Skip to content

Commit

Permalink
Merge pull request #705 from matter-labs/vv-evm-interp-mem-overflow-c…
Browse files Browse the repository at this point in the history
…heck

[EVM-Equivalence-YUL] Check offset overflow earlier in memory opcodes
  • Loading branch information
jrchatruc authored Aug 15, 2024
2 parents 8376204 + 1b2b0f9 commit 462f011
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions system-contracts/contracts/EvmInterpreterLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,11 @@ for { } true { } {

offset, sp := popStackItem(sp, evmGasLeft)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 32))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue, evmGasLeft)
ip := add(ip, 1)
Expand All @@ -637,11 +637,11 @@ for { } true { } {
offset, sp := popStackItemWithoutCheck(sp)
value, sp := popStackItemWithoutCheck(sp)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 32))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
mstore(add(MEM_OFFSET_INNER(), offset), value)
ip := add(ip, 1)
}
Expand All @@ -654,11 +654,11 @@ for { } true { } {
offset, sp := popStackItemWithoutCheck(sp)
value, sp := popStackItemWithoutCheck(sp)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 1))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
mstore8(add(MEM_OFFSET_INNER(), offset), value)
ip := add(ip, 1)
}
Expand Down
12 changes: 6 additions & 6 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -2167,11 +2167,11 @@ object "EVMInterpreter" {

offset, sp := popStackItem(sp, evmGasLeft)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 32))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue, evmGasLeft)
ip := add(ip, 1)
Expand All @@ -2185,11 +2185,11 @@ object "EVMInterpreter" {
offset, sp := popStackItemWithoutCheck(sp)
value, sp := popStackItemWithoutCheck(sp)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 32))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
mstore(add(MEM_OFFSET_INNER(), offset), value)
ip := add(ip, 1)
}
Expand All @@ -2202,11 +2202,11 @@ object "EVMInterpreter" {
offset, sp := popStackItemWithoutCheck(sp)
value, sp := popStackItemWithoutCheck(sp)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 1))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
mstore8(add(MEM_OFFSET_INNER(), offset), value)
ip := add(ip, 1)
}
Expand Down Expand Up @@ -5163,11 +5163,11 @@ object "EVMInterpreter" {

offset, sp := popStackItem(sp, evmGasLeft)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 32))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue, evmGasLeft)
ip := add(ip, 1)
Expand All @@ -5181,11 +5181,11 @@ object "EVMInterpreter" {
offset, sp := popStackItemWithoutCheck(sp)
value, sp := popStackItemWithoutCheck(sp)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 32))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
mstore(add(MEM_OFFSET_INNER(), offset), value)
ip := add(ip, 1)
}
Expand All @@ -5198,11 +5198,11 @@ object "EVMInterpreter" {
offset, sp := popStackItemWithoutCheck(sp)
value, sp := popStackItemWithoutCheck(sp)

checkOverflow(offset, MEM_OFFSET_INNER(), evmGasLeft)
checkMemOverflow(add(offset, MEM_OFFSET_INNER()), evmGasLeft)
let expansionGas := expandMemory(add(offset, 1))
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

checkOverflow(offset,MEM_OFFSET_INNER(), evmGasLeft)
mstore8(add(MEM_OFFSET_INNER(), offset), value)
ip := add(ip, 1)
}
Expand Down

0 comments on commit 462f011

Please sign in to comment.