From b649f5f5cc0cba54479688d31e98d585542391d0 Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Wed, 27 Nov 2024 17:25:48 +0100 Subject: [PATCH] fix(EVM): Do not charge additionally for EraVM decommit (#1086) --- system-contracts/contracts/EvmEmulator.yul | 46 ------------------- .../EvmEmulatorFunctions.template.yul | 23 ---------- 2 files changed, 69 deletions(-) diff --git a/system-contracts/contracts/EvmEmulator.yul b/system-contracts/contracts/EvmEmulator.yul index 303b7ffd5..e4d7e98b5 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -185,9 +185,6 @@ object "EvmEmulator" { function OVERHEAD() -> overhead { overhead := 2000 } - // From precompiles/CodeOracle - function DECOMMIT_COST_PER_WORD() -> cost { cost := 4 } - function UINT32_MAX() -> ret { ret := 4294967295 } // 2^32 - 1 //////////////////////////////////////////////////////////////// @@ -848,17 +845,6 @@ object "EvmEmulator" { // Call native ZkVm contract from EVM context function callZkVmNative(addr, evmGasToPass, value, argsOffset, argsSize, retOffset, retSize, isStatic) -> success, frameGasLeft { let zkEvmGasToPass := mul(evmGasToPass, GAS_DIVISOR()) // convert EVM gas -> ZkVM gas - let decommitZkVmGasCost := decommitmentCost(addr) - - // we are going to charge decommit cost even if address is already warm - // decommit cost is subtracted from the callee frame - switch gt(decommitZkVmGasCost, zkEvmGasToPass) - case 0 { - zkEvmGasToPass := sub(zkEvmGasToPass, decommitZkVmGasCost) - } - default { - zkEvmGasToPass := 0 - } if gt(zkEvmGasToPass, UINT32_MAX()) { // just in case zkEvmGasToPass := UINT32_MAX() @@ -886,15 +872,6 @@ object "EvmEmulator" { } } - function decommitmentCost(addr) -> cost { - // charge for contract decommitment - let byteSize := extcodesize(addr) - cost := mul( - div(add(byteSize, 31), 32), // rounding up - DECOMMIT_COST_PER_WORD() - ) - } - function capGasForCall(evmGasLeft, oldGasToPass) -> gasToPass { let maxGasToPass := sub(evmGasLeft, shr(6, evmGasLeft)) // evmGasLeft >> 6 == evmGasLeft/64 gasToPass := oldGasToPass @@ -3231,9 +3208,6 @@ object "EvmEmulator" { function OVERHEAD() -> overhead { overhead := 2000 } - // From precompiles/CodeOracle - function DECOMMIT_COST_PER_WORD() -> cost { cost := 4 } - function UINT32_MAX() -> ret { ret := 4294967295 } // 2^32 - 1 //////////////////////////////////////////////////////////////// @@ -3894,17 +3868,6 @@ object "EvmEmulator" { // Call native ZkVm contract from EVM context function callZkVmNative(addr, evmGasToPass, value, argsOffset, argsSize, retOffset, retSize, isStatic) -> success, frameGasLeft { let zkEvmGasToPass := mul(evmGasToPass, GAS_DIVISOR()) // convert EVM gas -> ZkVM gas - let decommitZkVmGasCost := decommitmentCost(addr) - - // we are going to charge decommit cost even if address is already warm - // decommit cost is subtracted from the callee frame - switch gt(decommitZkVmGasCost, zkEvmGasToPass) - case 0 { - zkEvmGasToPass := sub(zkEvmGasToPass, decommitZkVmGasCost) - } - default { - zkEvmGasToPass := 0 - } if gt(zkEvmGasToPass, UINT32_MAX()) { // just in case zkEvmGasToPass := UINT32_MAX() @@ -3932,15 +3895,6 @@ object "EvmEmulator" { } } - function decommitmentCost(addr) -> cost { - // charge for contract decommitment - let byteSize := extcodesize(addr) - cost := mul( - div(add(byteSize, 31), 32), // rounding up - DECOMMIT_COST_PER_WORD() - ) - } - function capGasForCall(evmGasLeft, oldGasToPass) -> gasToPass { let maxGasToPass := sub(evmGasLeft, shr(6, evmGasLeft)) // evmGasLeft >> 6 == evmGasLeft/64 gasToPass := oldGasToPass diff --git a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul index eb7e554af..96d0df147 100644 --- a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul @@ -123,9 +123,6 @@ function MSG_VALUE_SIMULATOR_STIPEND_GAS() -> gas_stipend { function OVERHEAD() -> overhead { overhead := 2000 } -// From precompiles/CodeOracle -function DECOMMIT_COST_PER_WORD() -> cost { cost := 4 } - function UINT32_MAX() -> ret { ret := 4294967295 } // 2^32 - 1 //////////////////////////////////////////////////////////////// @@ -786,17 +783,6 @@ function callPrecompile(addr, precompileCost, gasToPass, value, argsOffset, args // Call native ZkVm contract from EVM context function callZkVmNative(addr, evmGasToPass, value, argsOffset, argsSize, retOffset, retSize, isStatic) -> success, frameGasLeft { let zkEvmGasToPass := mul(evmGasToPass, GAS_DIVISOR()) // convert EVM gas -> ZkVM gas - let decommitZkVmGasCost := decommitmentCost(addr) - - // we are going to charge decommit cost even if address is already warm - // decommit cost is subtracted from the callee frame - switch gt(decommitZkVmGasCost, zkEvmGasToPass) - case 0 { - zkEvmGasToPass := sub(zkEvmGasToPass, decommitZkVmGasCost) - } - default { - zkEvmGasToPass := 0 - } if gt(zkEvmGasToPass, UINT32_MAX()) { // just in case zkEvmGasToPass := UINT32_MAX() @@ -824,15 +810,6 @@ function callZkVmNative(addr, evmGasToPass, value, argsOffset, argsSize, retOffs } } -function decommitmentCost(addr) -> cost { - // charge for contract decommitment - let byteSize := extcodesize(addr) - cost := mul( - div(add(byteSize, 31), 32), // rounding up - DECOMMIT_COST_PER_WORD() - ) -} - function capGasForCall(evmGasLeft, oldGasToPass) -> gasToPass { let maxGasToPass := sub(evmGasLeft, shr(6, evmGasLeft)) // evmGasLeft >> 6 == evmGasLeft/64 gasToPass := oldGasToPass