diff --git a/system-contracts/contracts/EvmInterpreterFunctions.template.yul b/system-contracts/contracts/EvmInterpreterFunctions.template.yul index 40eac584a..8874976a9 100644 --- a/system-contracts/contracts/EvmInterpreterFunctions.template.yul +++ b/system-contracts/contracts/EvmInterpreterFunctions.template.yul @@ -897,8 +897,15 @@ function performStaticCall(oldSp, evmGasLeft, oldStackHead) -> extraCost, sp, st } } - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } + stackHead := success } function capGas(evmGasLeft,oldGasToPass) -> gasToPass { @@ -1020,8 +1027,14 @@ function performCall(oldSp, evmGasLeft, isStatic, oldStackHead) -> extraCost, sp isStatic ) - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } stackHead := success } @@ -1083,8 +1096,14 @@ function delegateCall(oldSp, oldIsStatic, evmGasLeft, oldStackHead) -> sp, isSta _popEVMFrame() - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } stackHead := success } diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index 07287d7d8..1b0ae7fa3 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -968,8 +968,15 @@ object "EVMInterpreter" { } } - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } + stackHead := success } function capGas(evmGasLeft,oldGasToPass) -> gasToPass { @@ -1091,8 +1098,14 @@ object "EVMInterpreter" { isStatic ) - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } stackHead := success } @@ -1154,8 +1167,14 @@ object "EVMInterpreter" { _popEVMFrame() - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } stackHead := success } @@ -3897,8 +3916,15 @@ object "EVMInterpreter" { } } - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } + stackHead := success } function capGas(evmGasLeft,oldGasToPass) -> gasToPass { @@ -4020,8 +4046,14 @@ object "EVMInterpreter" { isStatic ) - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } stackHead := success } @@ -4083,8 +4115,14 @@ object "EVMInterpreter" { _popEVMFrame() - extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) - extraCost := add(extraCost, getGasForPrecompiles(addr, argsOffset, argsSize)) + let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize) + switch iszero(precompileCost) + case 1 { + extraCost := add(extraCost,sub(gasToPass,frameGasLeft)) + } + default { + extraCost := add(extraCost, precompileCost) + } stackHead := success }