Skip to content

Commit

Permalink
Merge branch 'evm-equivalence-yul' into vv-small-interpreter-optimiza…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
0xVolosnikov committed Aug 21, 2024
2 parents 83d9aa7 + 18d1d3a commit 2c9b719
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 @@ -229,7 +228,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 @@ -780,7 +778,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 @@ -917,8 +914,6 @@ function performStaticCall(oldSp,evmGasLeft) -> extraCost, sp {
}
default {
_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 @@ -1107,13 +1102,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 @@ -1199,8 +1187,6 @@ function _performStaticCall(
}
default {
_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 @@ -480,11 +480,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 @@ -510,9 +505,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 @@ -300,7 +297,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 @@ -851,7 +847,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 @@ -988,8 +983,6 @@ object "EVMInterpreter" {
}
default {
_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 @@ -1178,13 +1171,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 @@ -1270,8 +1256,6 @@ object "EVMInterpreter" {
}
default {
_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 @@ -2033,11 +2017,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 @@ -2063,9 +2042,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 @@ -3135,7 +3111,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 @@ -3288,7 +3263,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 @@ -3839,7 +3813,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 @@ -3976,8 +3949,6 @@ object "EVMInterpreter" {
}
default {
_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 @@ -4166,13 +4137,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 @@ -4258,8 +4222,6 @@ object "EVMInterpreter" {
}
default {
_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 @@ -5021,11 +4983,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 @@ -5051,9 +5008,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 2c9b719

Please sign in to comment.