Skip to content

Commit

Permalink
Go back to returning 0 evm gas when there's not enough zkevm gas
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Jul 10, 2024
1 parent c457c7b commit 0b58290
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -823,12 +823,13 @@ function getEVMGas() -> evmGas {
let _gas := gas()
let requiredGas := add(EVM_GAS_STIPEND(), OVERHEAD())

if lt(sub(_gas,shl(30,1)), requiredGas) {
// This cheks if enough zkevm gas was provided, we are substracting 2^30 since that's the stipend,
// and we need to make sure that the gas provided over that is enough for security reasons
revert(0, 0)
switch lt(_gas, requiredGas)
case 1 {
evmGas := 0
}
default {
evmGas := div(sub(_gas, requiredGas), GAS_DIVISOR())
}
evmGas := div(sub(_gas, requiredGas), GAS_DIVISOR())
}

function _getZkEVMGas(_evmGas) -> zkevmGas {
Expand Down
22 changes: 12 additions & 10 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,13 @@ object "EVMInterpreter" {
let _gas := gas()
let requiredGas := add(EVM_GAS_STIPEND(), OVERHEAD())

if lt(sub(_gas,shl(30,1)), requiredGas) {
// This cheks if enough zkevm gas was provided, we are substracting 2^30 since that's the stipend,
// and we need to make sure that the gas provided over that is enough for security reasons
revert(0, 0)
switch lt(_gas, requiredGas)
case 1 {
evmGas := 0
}
default {
evmGas := div(sub(_gas, requiredGas), GAS_DIVISOR())
}
evmGas := div(sub(_gas, requiredGas), GAS_DIVISOR())
}

function _getZkEVMGas(_evmGas) -> zkevmGas {
Expand Down Expand Up @@ -3728,12 +3729,13 @@ object "EVMInterpreter" {
let _gas := gas()
let requiredGas := add(EVM_GAS_STIPEND(), OVERHEAD())

if lt(sub(_gas,shl(30,1)), requiredGas) {
// This cheks if enough zkevm gas was provided, we are substracting 2^30 since that's the stipend,
// and we need to make sure that the gas provided over that is enough for security reasons
revert(0, 0)
switch lt(_gas, requiredGas)
case 1 {
evmGas := 0
}
default {
evmGas := div(sub(_gas, requiredGas), GAS_DIVISOR())
}
evmGas := div(sub(_gas, requiredGas), GAS_DIVISOR())
}

function _getZkEVMGas(_evmGas) -> zkevmGas {
Expand Down

0 comments on commit 0b58290

Please sign in to comment.