Skip to content

Commit

Permalink
Merge pull request matter-labs#342 from lambdaclass/yul-stack-memory
Browse files Browse the repository at this point in the history
[EVM-Equivalent-Yul] Add mload, mstore and mstore8 opcodes
  • Loading branch information
jrchatruc authored Apr 12, 2024
2 parents 9e8c33e + 2cd9dc2 commit a931717
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions system-contracts/contracts/EvmInterpreter.yul
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,46 @@ object "EVMInterpreter" {

evmGasLeft := chargeGas(evmGasLeft, 3)
}
case 0x50 { // OP_POP
let _y

_y, sp := popStackItem(sp)

evmGasLeft := chargeGas(evmGasLeft, 2)
}
case 0x51 { // OP_MLOAD
let offset

offset, sp := popStackItem(sp)

let expansionGas := expandMemory(add(offset, 32))

let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue)
evmGasLeft := chargeGas(evmGasLeft, add(3, expansionGas))
}
case 0x52 { // OP_MSTORE
let offset, value

offset, sp := popStackItem(sp)
value, sp := popStackItem(sp)

let expansionGas := expandMemory(add(offset, 32))

mstore(add(MEM_OFFSET_INNER(), offset), value)
evmGasLeft := chargeGas(evmGasLeft, add(3, expansionGas))
}
case 0x53 { // OP_MSTORE8
let offset, value

offset, sp := popStackItem(sp)
value, sp := popStackItem(sp)

let expansionGas := expandMemory(add(offset, 1))

mstore8(add(MEM_OFFSET_INNER(), offset), value)
evmGasLeft := chargeGas(evmGasLeft, add(3, expansionGas))
}
// NOTE: We don't currently do full jumpdest validation
// (i.e. validating a jumpdest isn't in PUSH data)
case 0x56 { // OP_JUMP
Expand Down

0 comments on commit a931717

Please sign in to comment.