Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EVM): Do not charge additionally for EraVM decommit #1086

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

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