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 committed Dec 10, 2024
1 parent ef91e52 commit b649f5f
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 @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
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 @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b649f5f

Please sign in to comment.