Skip to content

Commit 2c9b719

Browse files
committed
Merge branch 'evm-equivalence-yul' into vv-small-interpreter-optimizations
2 parents 83d9aa7 + 18d1d3a commit 2c9b719

File tree

4 files changed

+0
-70
lines changed

4 files changed

+0
-70
lines changed

system-contracts/contracts/EvmInterpreter.template.yul

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ object "EVMInterpreter" {
5757

5858
function validateCorrectBytecode(offset, len, gasToReturn) -> returnGas {
5959
if len {
60-
// let firstByte := shr(mload(offset), 248)
61-
// FIXME: Check this.
6260
let firstByte := shr(248, mload(offset))
6361
if eq(firstByte, 0xEF) {
6462
revert(0, 0)

system-contracts/contracts/EvmInterpreterFunctions.template.yul

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ function MAX_UINT() -> max_uint {
7676

7777
// It is the responsibility of the caller to ensure that ip >= BYTECODE_OFFSET + 32
7878
function readIP(ip,maxAcceptablePos) -> opcode {
79-
// TODO: Why not do this at the beginning once instead of every time?
8079
if gt(ip, maxAcceptablePos) {
8180
revert(0, 0)
8281
}
@@ -229,7 +228,6 @@ function _getCodeHash(account) -> hash {
229228

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

@@ -780,7 +778,6 @@ function _popEVMFrame() {
780778
}
781779

782780
// Each evm gas is 5 zkEVM one
783-
// FIXME: change this variable to reflect real ergs : gas ratio
784781
function GAS_DIVISOR() -> gas_div { gas_div := 5 }
785782
function EVM_GAS_STIPEND() -> gas_stipend { gas_stipend := shl(30, 1) } // 1 << 30
786783
function OVERHEAD() -> overhead { overhead := 2000 }
@@ -917,8 +914,6 @@ function performStaticCall(oldSp,evmGasLeft) -> extraCost, sp {
917914
}
918915
default {
919916
_pushEVMFrame(gasToPass, true)
920-
// TODO Check the following comment from zkSync .sol.
921-
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
922917
success := staticcall(gasToPass, addr, add(MEM_OFFSET_INNER(), argsOffset), argsSize, 0, 0)
923918

924919
frameGasLeft := _saveReturndataAfterEVMCall(add(MEM_OFFSET_INNER(), retOffset), retSize)
@@ -1107,13 +1102,6 @@ function delegateCall(oldSp, oldIsStatic, evmGasLeft) -> sp, isStatic, extraCost
11071102
}
11081103
gasToPass := capGas(evmGasLeft,gasToPass)
11091104

1110-
// TODO: Do this
1111-
// if warmAccount(addr) {
1112-
// extraCost = GAS_WARM_ACCESS;
1113-
// } else {
1114-
// extraCost = GAS_COLD_ACCOUNT_ACCESS;
1115-
// }
1116-
11171105
_pushEVMFrame(gasToPass, isStatic)
11181106
let success := delegatecall(
11191107
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
@@ -1199,8 +1187,6 @@ function _performStaticCall(
11991187
}
12001188
default {
12011189
_pushEVMFrame(_calleeGas, true)
1202-
// TODO Check the following comment from zkSync .sol.
1203-
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
12041190
success := staticcall(EVM_GAS_STIPEND(), _callee, _inputOffset, _inputLen, 0, 0)
12051191

12061192
_gasLeft := _saveReturndataAfterEVMCall(_outputOffset, _outputLen)

system-contracts/contracts/EvmInterpreterLoop.template.yul

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,6 @@ for { } true { } {
480480
evmGasLeft := chargeGas(evmGasLeft, 2500)
481481
}
482482

483-
// TODO: check, the .sol uses extcodesize directly, but it doesnt seem to work
484-
// if a contract is created it works, but if the address is a zkSync's contract
485-
// what happens?
486-
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)
487-
488483
switch _isEVM(addr)
489484
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
490485
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
@@ -510,9 +505,6 @@ for { } true { } {
510505
offset, sp := popStackItemWithoutCheck(sp)
511506
len, sp := popStackItemWithoutCheck(sp)
512507

513-
// TODO: check if these conditions are met
514-
// The addition offset + size overflows.
515-
// offset + size is larger than RETURNDATASIZE.
516508
checkOverflow(offset,len, evmGasLeft)
517509
if gt(add(offset, len), mload(LAST_RETURNDATA_SIZE_OFFSET())) {
518510
revertWithGas(evmGasLeft)

system-contracts/contracts/EvmInterpreterPreprocessed.yul

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ object "EVMInterpreter" {
5757

5858
function validateCorrectBytecode(offset, len, gasToReturn) -> returnGas {
5959
if len {
60-
// let firstByte := shr(mload(offset), 248)
61-
// FIXME: Check this.
6260
let firstByte := shr(248, mload(offset))
6361
if eq(firstByte, 0xEF) {
6462
revert(0, 0)
@@ -147,7 +145,6 @@ object "EVMInterpreter" {
147145

148146
// It is the responsibility of the caller to ensure that ip >= BYTECODE_OFFSET + 32
149147
function readIP(ip,maxAcceptablePos) -> opcode {
150-
// TODO: Why not do this at the beginning once instead of every time?
151148
if gt(ip, maxAcceptablePos) {
152149
revert(0, 0)
153150
}
@@ -300,7 +297,6 @@ object "EVMInterpreter" {
300297

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

@@ -851,7 +847,6 @@ object "EVMInterpreter" {
851847
}
852848

853849
// Each evm gas is 5 zkEVM one
854-
// FIXME: change this variable to reflect real ergs : gas ratio
855850
function GAS_DIVISOR() -> gas_div { gas_div := 5 }
856851
function EVM_GAS_STIPEND() -> gas_stipend { gas_stipend := shl(30, 1) } // 1 << 30
857852
function OVERHEAD() -> overhead { overhead := 2000 }
@@ -988,8 +983,6 @@ object "EVMInterpreter" {
988983
}
989984
default {
990985
_pushEVMFrame(gasToPass, true)
991-
// TODO Check the following comment from zkSync .sol.
992-
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
993986
success := staticcall(gasToPass, addr, add(MEM_OFFSET_INNER(), argsOffset), argsSize, 0, 0)
994987

995988
frameGasLeft := _saveReturndataAfterEVMCall(add(MEM_OFFSET_INNER(), retOffset), retSize)
@@ -1178,13 +1171,6 @@ object "EVMInterpreter" {
11781171
}
11791172
gasToPass := capGas(evmGasLeft,gasToPass)
11801173

1181-
// TODO: Do this
1182-
// if warmAccount(addr) {
1183-
// extraCost = GAS_WARM_ACCESS;
1184-
// } else {
1185-
// extraCost = GAS_COLD_ACCOUNT_ACCESS;
1186-
// }
1187-
11881174
_pushEVMFrame(gasToPass, isStatic)
11891175
let success := delegatecall(
11901176
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
@@ -1270,8 +1256,6 @@ object "EVMInterpreter" {
12701256
}
12711257
default {
12721258
_pushEVMFrame(_calleeGas, true)
1273-
// TODO Check the following comment from zkSync .sol.
1274-
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
12751259
success := staticcall(EVM_GAS_STIPEND(), _callee, _inputOffset, _inputLen, 0, 0)
12761260

12771261
_gasLeft := _saveReturndataAfterEVMCall(_outputOffset, _outputLen)
@@ -2033,11 +2017,6 @@ object "EVMInterpreter" {
20332017
evmGasLeft := chargeGas(evmGasLeft, 2500)
20342018
}
20352019

2036-
// TODO: check, the .sol uses extcodesize directly, but it doesnt seem to work
2037-
// if a contract is created it works, but if the address is a zkSync's contract
2038-
// what happens?
2039-
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)
2040-
20412020
switch _isEVM(addr)
20422021
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
20432022
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
@@ -2063,9 +2042,6 @@ object "EVMInterpreter" {
20632042
offset, sp := popStackItemWithoutCheck(sp)
20642043
len, sp := popStackItemWithoutCheck(sp)
20652044

2066-
// TODO: check if these conditions are met
2067-
// The addition offset + size overflows.
2068-
// offset + size is larger than RETURNDATASIZE.
20692045
checkOverflow(offset,len, evmGasLeft)
20702046
if gt(add(offset, len), mload(LAST_RETURNDATA_SIZE_OFFSET())) {
20712047
revertWithGas(evmGasLeft)
@@ -3135,7 +3111,6 @@ object "EVMInterpreter" {
31353111

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

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

@@ -3839,7 +3813,6 @@ object "EVMInterpreter" {
38393813
}
38403814

38413815
// Each evm gas is 5 zkEVM one
3842-
// FIXME: change this variable to reflect real ergs : gas ratio
38433816
function GAS_DIVISOR() -> gas_div { gas_div := 5 }
38443817
function EVM_GAS_STIPEND() -> gas_stipend { gas_stipend := shl(30, 1) } // 1 << 30
38453818
function OVERHEAD() -> overhead { overhead := 2000 }
@@ -3976,8 +3949,6 @@ object "EVMInterpreter" {
39763949
}
39773950
default {
39783951
_pushEVMFrame(gasToPass, true)
3979-
// TODO Check the following comment from zkSync .sol.
3980-
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
39813952
success := staticcall(gasToPass, addr, add(MEM_OFFSET_INNER(), argsOffset), argsSize, 0, 0)
39823953

39833954
frameGasLeft := _saveReturndataAfterEVMCall(add(MEM_OFFSET_INNER(), retOffset), retSize)
@@ -4166,13 +4137,6 @@ object "EVMInterpreter" {
41664137
}
41674138
gasToPass := capGas(evmGasLeft,gasToPass)
41684139

4169-
// TODO: Do this
4170-
// if warmAccount(addr) {
4171-
// extraCost = GAS_WARM_ACCESS;
4172-
// } else {
4173-
// extraCost = GAS_COLD_ACCOUNT_ACCESS;
4174-
// }
4175-
41764140
_pushEVMFrame(gasToPass, isStatic)
41774141
let success := delegatecall(
41784142
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
@@ -4258,8 +4222,6 @@ object "EVMInterpreter" {
42584222
}
42594223
default {
42604224
_pushEVMFrame(_calleeGas, true)
4261-
// TODO Check the following comment from zkSync .sol.
4262-
// We can not just pass all gas here to prevert overflow of zkEVM gas counter
42634225
success := staticcall(EVM_GAS_STIPEND(), _callee, _inputOffset, _inputLen, 0, 0)
42644226

42654227
_gasLeft := _saveReturndataAfterEVMCall(_outputOffset, _outputLen)
@@ -5021,11 +4983,6 @@ object "EVMInterpreter" {
50214983
evmGasLeft := chargeGas(evmGasLeft, 2500)
50224984
}
50234985

5024-
// TODO: check, the .sol uses extcodesize directly, but it doesnt seem to work
5025-
// if a contract is created it works, but if the address is a zkSync's contract
5026-
// what happens?
5027-
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)
5028-
50294986
switch _isEVM(addr)
50304987
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
50314988
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
@@ -5051,9 +5008,6 @@ object "EVMInterpreter" {
50515008
offset, sp := popStackItemWithoutCheck(sp)
50525009
len, sp := popStackItemWithoutCheck(sp)
50535010

5054-
// TODO: check if these conditions are met
5055-
// The addition offset + size overflows.
5056-
// offset + size is larger than RETURNDATASIZE.
50575011
checkOverflow(offset,len, evmGasLeft)
50585012
if gt(add(offset, len), mload(LAST_RETURNDATA_SIZE_OFFSET())) {
50595013
revertWithGas(evmGasLeft)

0 commit comments

Comments
 (0)