Skip to content

Commit

Permalink
Merge pull request #723 from lambdaclass/remove-todo
Browse files Browse the repository at this point in the history
[EVM-Equivalence-YUL] Remove TODOs
  • Loading branch information
jrchatruc committed Aug 20, 2024
2 parents 74767c1 + 77eb854 commit 18d1d3a
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 70 deletions.
2 changes: 0 additions & 2 deletions system-contracts/contracts/EvmInterpreter.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ object "EVMInterpreter" {

function validateCorrectBytecode(offset, len, gasToReturn) -> returnGas {
if len {
// let firstByte := shr(mload(offset), 248)
// FIXME: Check this.
let firstByte := shr(248, mload(offset))
if eq(firstByte, 0xEF) {
revert(0, 0)
Expand Down
14 changes: 0 additions & 14 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function MAX_UINT() -> max_uint {

// It is the responsibility of the caller to ensure that ip >= BYTECODE_OFFSET + 32
function readIP(ip,maxAcceptablePos) -> opcode {
// TODO: Why not do this at the beginning once instead of every time?
if gt(ip, maxAcceptablePos) {
revert(0, 0)
}
Expand Down Expand Up @@ -223,7 +222,6 @@ function _getCodeHash(account) -> hash {

function getIsStaticFromCallFlags() -> isStatic {
isStatic := verbatim_0i_1o("get_global::call_flags")
// TODO: make it a constnat
isStatic := iszero(iszero(and(isStatic, 0x04)))
}

Expand Down Expand Up @@ -762,7 +760,6 @@ function _popEVMFrame() {
}

// Each evm gas is 5 zkEVM one
// FIXME: change this variable to reflect real ergs : gas ratio
function GAS_DIVISOR() -> gas_div { gas_div := 5 }
function EVM_GAS_STIPEND() -> gas_stipend { gas_stipend := shl(30, 1) } // 1 << 30
function OVERHEAD() -> overhead { overhead := 2000 }
Expand Down Expand Up @@ -884,8 +881,6 @@ function performStaticCall(oldSp,evmGasLeft) -> extraCost, sp {
let success
if _isEVM(addr) {
_pushEVMFrame(gasToPass, true)
// TODO Check the following comment from zkSync .sol.
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
success := staticcall(gasToPass, addr, add(MEM_OFFSET_INNER(), argsOffset), argsSize, 0, 0)

frameGasLeft := _saveReturndataAfterEVMCall(add(MEM_OFFSET_INNER(), retOffset), retSize)
Expand Down Expand Up @@ -1086,13 +1081,6 @@ function delegateCall(oldSp, oldIsStatic, evmGasLeft) -> sp, isStatic, extraCost
}
gasToPass := capGas(evmGasLeft,gasToPass)

// TODO: Do this
// if warmAccount(addr) {
// extraCost = GAS_WARM_ACCESS;
// } else {
// extraCost = GAS_COLD_ACCOUNT_ACCESS;
// }

_pushEVMFrame(gasToPass, isStatic)
let success := delegatecall(
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
Expand Down Expand Up @@ -1162,8 +1150,6 @@ function _performStaticCall(
) -> success, _gasLeft {
if _calleeIsEVM {
_pushEVMFrame(_calleeGas, true)
// TODO Check the following comment from zkSync .sol.
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
success := staticcall(EVM_GAS_STIPEND(), _callee, _inputOffset, _inputLen, 0, 0)

_gasLeft := _saveReturndataAfterEVMCall(_outputOffset, _outputLen)
Expand Down
8 changes: 0 additions & 8 deletions system-contracts/contracts/EvmInterpreterLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,6 @@ for { } true { } {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

// TODO: check, the .sol uses extcodesize directly, but it doesnt seem to work
// if a contract is created it works, but if the address is a zkSync's contract
// what happens?
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)

switch _isEVM(addr)
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
Expand All @@ -509,9 +504,6 @@ for { } true { } {
offset, sp := popStackItemWithoutCheck(sp)
len, sp := popStackItemWithoutCheck(sp)

// TODO: check if these conditions are met
// The addition offset + size overflows.
// offset + size is larger than RETURNDATASIZE.
checkOverflow(offset,len, evmGasLeft)
if gt(add(offset, len), mload(LAST_RETURNDATA_SIZE_OFFSET())) {
revertWithGas(evmGasLeft)
Expand Down
46 changes: 0 additions & 46 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ object "EVMInterpreter" {

function validateCorrectBytecode(offset, len, gasToReturn) -> returnGas {
if len {
// let firstByte := shr(mload(offset), 248)
// FIXME: Check this.
let firstByte := shr(248, mload(offset))
if eq(firstByte, 0xEF) {
revert(0, 0)
Expand Down Expand Up @@ -147,7 +145,6 @@ object "EVMInterpreter" {

// It is the responsibility of the caller to ensure that ip >= BYTECODE_OFFSET + 32
function readIP(ip,maxAcceptablePos) -> opcode {
// TODO: Why not do this at the beginning once instead of every time?
if gt(ip, maxAcceptablePos) {
revert(0, 0)
}
Expand Down Expand Up @@ -294,7 +291,6 @@ object "EVMInterpreter" {

function getIsStaticFromCallFlags() -> isStatic {
isStatic := verbatim_0i_1o("get_global::call_flags")
// TODO: make it a constnat
isStatic := iszero(iszero(and(isStatic, 0x04)))
}

Expand Down Expand Up @@ -833,7 +829,6 @@ object "EVMInterpreter" {
}

// Each evm gas is 5 zkEVM one
// FIXME: change this variable to reflect real ergs : gas ratio
function GAS_DIVISOR() -> gas_div { gas_div := 5 }
function EVM_GAS_STIPEND() -> gas_stipend { gas_stipend := shl(30, 1) } // 1 << 30
function OVERHEAD() -> overhead { overhead := 2000 }
Expand Down Expand Up @@ -955,8 +950,6 @@ object "EVMInterpreter" {
let success
if _isEVM(addr) {
_pushEVMFrame(gasToPass, true)
// TODO Check the following comment from zkSync .sol.
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
success := staticcall(gasToPass, addr, add(MEM_OFFSET_INNER(), argsOffset), argsSize, 0, 0)

frameGasLeft := _saveReturndataAfterEVMCall(add(MEM_OFFSET_INNER(), retOffset), retSize)
Expand Down Expand Up @@ -1157,13 +1150,6 @@ object "EVMInterpreter" {
}
gasToPass := capGas(evmGasLeft,gasToPass)

// TODO: Do this
// if warmAccount(addr) {
// extraCost = GAS_WARM_ACCESS;
// } else {
// extraCost = GAS_COLD_ACCOUNT_ACCESS;
// }

_pushEVMFrame(gasToPass, isStatic)
let success := delegatecall(
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
Expand Down Expand Up @@ -1233,8 +1219,6 @@ object "EVMInterpreter" {
) -> success, _gasLeft {
if _calleeIsEVM {
_pushEVMFrame(_calleeGas, true)
// TODO Check the following comment from zkSync .sol.
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
success := staticcall(EVM_GAS_STIPEND(), _callee, _inputOffset, _inputLen, 0, 0)

_gasLeft := _saveReturndataAfterEVMCall(_outputOffset, _outputLen)
Expand Down Expand Up @@ -2012,11 +1996,6 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

// TODO: check, the .sol uses extcodesize directly, but it doesnt seem to work
// if a contract is created it works, but if the address is a zkSync's contract
// what happens?
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)

switch _isEVM(addr)
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
Expand All @@ -2042,9 +2021,6 @@ object "EVMInterpreter" {
offset, sp := popStackItemWithoutCheck(sp)
len, sp := popStackItemWithoutCheck(sp)

// TODO: check if these conditions are met
// The addition offset + size overflows.
// offset + size is larger than RETURNDATASIZE.
checkOverflow(offset,len, evmGasLeft)
if gt(add(offset, len), mload(LAST_RETURNDATA_SIZE_OFFSET())) {
revertWithGas(evmGasLeft)
Expand Down Expand Up @@ -3116,7 +3092,6 @@ object "EVMInterpreter" {

// It is the responsibility of the caller to ensure that ip >= BYTECODE_OFFSET + 32
function readIP(ip,maxAcceptablePos) -> opcode {
// TODO: Why not do this at the beginning once instead of every time?
if gt(ip, maxAcceptablePos) {
revert(0, 0)
}
Expand Down Expand Up @@ -3263,7 +3238,6 @@ object "EVMInterpreter" {

function getIsStaticFromCallFlags() -> isStatic {
isStatic := verbatim_0i_1o("get_global::call_flags")
// TODO: make it a constnat
isStatic := iszero(iszero(and(isStatic, 0x04)))
}

Expand Down Expand Up @@ -3802,7 +3776,6 @@ object "EVMInterpreter" {
}

// Each evm gas is 5 zkEVM one
// FIXME: change this variable to reflect real ergs : gas ratio
function GAS_DIVISOR() -> gas_div { gas_div := 5 }
function EVM_GAS_STIPEND() -> gas_stipend { gas_stipend := shl(30, 1) } // 1 << 30
function OVERHEAD() -> overhead { overhead := 2000 }
Expand Down Expand Up @@ -3924,8 +3897,6 @@ object "EVMInterpreter" {
let success
if _isEVM(addr) {
_pushEVMFrame(gasToPass, true)
// TODO Check the following comment from zkSync .sol.
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
success := staticcall(gasToPass, addr, add(MEM_OFFSET_INNER(), argsOffset), argsSize, 0, 0)

frameGasLeft := _saveReturndataAfterEVMCall(add(MEM_OFFSET_INNER(), retOffset), retSize)
Expand Down Expand Up @@ -4126,13 +4097,6 @@ object "EVMInterpreter" {
}
gasToPass := capGas(evmGasLeft,gasToPass)

// TODO: Do this
// if warmAccount(addr) {
// extraCost = GAS_WARM_ACCESS;
// } else {
// extraCost = GAS_COLD_ACCOUNT_ACCESS;
// }

_pushEVMFrame(gasToPass, isStatic)
let success := delegatecall(
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
Expand Down Expand Up @@ -4202,8 +4166,6 @@ object "EVMInterpreter" {
) -> success, _gasLeft {
if _calleeIsEVM {
_pushEVMFrame(_calleeGas, true)
// TODO Check the following comment from zkSync .sol.
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
success := staticcall(EVM_GAS_STIPEND(), _callee, _inputOffset, _inputLen, 0, 0)

_gasLeft := _saveReturndataAfterEVMCall(_outputOffset, _outputLen)
Expand Down Expand Up @@ -4981,11 +4943,6 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

// TODO: check, the .sol uses extcodesize directly, but it doesnt seem to work
// if a contract is created it works, but if the address is a zkSync's contract
// what happens?
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)

switch _isEVM(addr)
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
Expand All @@ -5011,9 +4968,6 @@ object "EVMInterpreter" {
offset, sp := popStackItemWithoutCheck(sp)
len, sp := popStackItemWithoutCheck(sp)

// TODO: check if these conditions are met
// The addition offset + size overflows.
// offset + size is larger than RETURNDATASIZE.
checkOverflow(offset,len, evmGasLeft)
if gt(add(offset, len), mload(LAST_RETURNDATA_SIZE_OFFSET())) {
revertWithGas(evmGasLeft)
Expand Down

0 comments on commit 18d1d3a

Please sign in to comment.