From ff96fe37282f1dadae18123ca7ba3d33c76de07f Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Thu, 28 Nov 2024 19:08:50 +0100 Subject: [PATCH] fix(EVM): Zero out frame gas left for underpaid precompiles (#1101) --- system-contracts/contracts/EvmEmulator.yul | 2 ++ system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul | 1 + 2 files changed, 3 insertions(+) diff --git a/system-contracts/contracts/EvmEmulator.yul b/system-contracts/contracts/EvmEmulator.yul index 23453d9d2..673db6725 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -851,6 +851,7 @@ object "EvmEmulator" { let zkVmGasToPass := gas() // pass all remaining gas, precompiles should not call any contracts if lt(gasToPass, precompileCost) { zkVmGasToPass := 0 // in EVM precompile should revert consuming all gas in that case + precompileCost := gasToPass // just in case } switch isStatic @@ -3909,6 +3910,7 @@ object "EvmEmulator" { let zkVmGasToPass := gas() // pass all remaining gas, precompiles should not call any contracts if lt(gasToPass, precompileCost) { zkVmGasToPass := 0 // in EVM precompile should revert consuming all gas in that case + precompileCost := gasToPass // just in case } switch isStatic diff --git a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul index 4bfa3b6ea..000552f43 100644 --- a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul @@ -789,6 +789,7 @@ function callPrecompile(addr, precompileCost, gasToPass, value, argsOffset, args let zkVmGasToPass := gas() // pass all remaining gas, precompiles should not call any contracts if lt(gasToPass, precompileCost) { zkVmGasToPass := 0 // in EVM precompile should revert consuming all gas in that case + precompileCost := gasToPass // just in case } switch isStatic