Skip to content

Commit

Permalink
Rename checmMemory to allocateMemory in evm package
Browse files Browse the repository at this point in the history
  • Loading branch information
Kourin1996 committed Oct 11, 2022
1 parent 94999c4 commit 87d7d41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions state/runtime/evm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func opMStore(c *state) {
offset := c.pop()
val := c.pop()

if !c.checkMemory(offset, wordSize) {
if !c.allocateMemory(offset, wordSize) {
return
}

Expand Down Expand Up @@ -452,7 +452,7 @@ func opMStore8(c *state) {
offset := c.pop()
val := c.pop()

if !c.checkMemory(offset, one) {
if !c.allocateMemory(offset, one) {
return
}

Expand Down Expand Up @@ -757,7 +757,7 @@ func opExtCodeCopy(c *state) {
codeOffset := c.pop()
length := c.pop()

if !c.checkMemory(memOffset, length) {
if !c.allocateMemory(memOffset, length) {
return
}

Expand Down Expand Up @@ -788,7 +788,7 @@ func opCallDataCopy(c *state) {
dataOffset := c.pop()
length := c.pop()

if !c.checkMemory(memOffset, length) {
if !c.allocateMemory(memOffset, length) {
return
}

Expand All @@ -813,7 +813,7 @@ func opReturnDataCopy(c *state) {
dataOffset := c.pop()
length := c.pop()

if !c.checkMemory(memOffset, length) {
if !c.allocateMemory(memOffset, length) {
return
}

Expand Down Expand Up @@ -850,7 +850,7 @@ func opCodeCopy(c *state) {
dataOffset := c.pop()
length := c.pop()

if !c.checkMemory(memOffset, length) {
if !c.allocateMemory(memOffset, length) {
return
}

Expand Down Expand Up @@ -1207,7 +1207,7 @@ func (c *state) buildCallContract(op OpCode) (*runtime.Contract, uint64, uint64,
return nil, 0, 0, nil
}
// Check if the memory return offsets are out of bounds
if !c.checkMemory(retOffset, retSize) {
if !c.allocateMemory(retOffset, retSize) {
return nil, 0, 0, nil
}

Expand Down
7 changes: 5 additions & 2 deletions state/runtime/evm/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ func (c *state) Len() int {
return len(c.memory)
}

func (c *state) checkMemory(offset, size *big.Int) bool {
// allocateMemory allocates memory to enable accessing in the range of [offset, offset+size]
// throws error if the given offset and size are negative
// consumes gas if memory needs to be expanded
func (c *state) allocateMemory(offset, size *big.Int) bool {
if !offset.IsUint64() || !size.IsUint64() {
c.exit(errGasUintOverflow)

Expand Down Expand Up @@ -325,7 +328,7 @@ func (c *state) get2(dst []byte, offset, length *big.Int) ([]byte, bool) {
return nil, true
}

if !c.checkMemory(offset, length) {
if !c.allocateMemory(offset, length) {
return nil, false
}

Expand Down

0 comments on commit 87d7d41

Please sign in to comment.