From 746914c263db165327ff658332167d8b7230b1f3 Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Mon, 18 Nov 2024 13:12:25 +0100 Subject: [PATCH] Do not charge for decommit --- 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 f9a9c0d75b..ea5f99e20a 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -189,9 +189,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 //////////////////////////////////////////////////////////////// @@ -852,17 +849,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() @@ -890,15 +876,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 @@ -3237,9 +3214,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 //////////////////////////////////////////////////////////////// @@ -3900,17 +3874,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() @@ -3938,15 +3901,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 58736a58d4..5370e4dbdc 100644 --- a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul @@ -127,9 +127,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 //////////////////////////////////////////////////////////////// @@ -790,17 +787,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() @@ -828,15 +814,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