From 0b58290ec081a32db65e6c8e19c3b8551a81fa76 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Wed, 10 Jul 2024 09:31:18 -0300 Subject: [PATCH] Go back to returning 0 evm gas when there's not enough zkevm gas --- .../EvmInterpreterFunctions.template.yul | 11 +++++----- .../contracts/EvmInterpreterPreprocessed.yul | 22 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/system-contracts/contracts/EvmInterpreterFunctions.template.yul b/system-contracts/contracts/EvmInterpreterFunctions.template.yul index 89f3837c7..9e70a22d9 100644 --- a/system-contracts/contracts/EvmInterpreterFunctions.template.yul +++ b/system-contracts/contracts/EvmInterpreterFunctions.template.yul @@ -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 { diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index b4ae22738..962c991d9 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -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 { @@ -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 {