diff --git a/state/runtime/evm/instructions.go b/state/runtime/evm/instructions.go index 9c8f093d84..6d403c32ee 100644 --- a/state/runtime/evm/instructions.go +++ b/state/runtime/evm/instructions.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/state/runtime/evm/state.go b/state/runtime/evm/state.go index cad372691d..3ddc347c04 100644 --- a/state/runtime/evm/state.go +++ b/state/runtime/evm/state.go @@ -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) @@ -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 }