Skip to content

Commit

Permalink
fix(EVM): Do not charge additionally for EraVM decommit (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov authored Nov 27, 2024
1 parent 8f92eb0 commit 7547d09
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 69 deletions.
46 changes: 0 additions & 46 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -853,17 +850,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()
Expand Down Expand Up @@ -891,15 +877,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
Expand Down Expand Up @@ -3236,9 +3213,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

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3904,17 +3878,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()
Expand Down Expand Up @@ -3942,15 +3905,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
Expand Down
23 changes: 0 additions & 23 deletions system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -791,17 +788,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()
Expand Down Expand Up @@ -829,15 +815,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
Expand Down

0 comments on commit 7547d09

Please sign in to comment.