diff --git a/system-contracts/contracts/EvmInterpreterFunctions.template.yul b/system-contracts/contracts/EvmInterpreterFunctions.template.yul index d054a8180..239d1171f 100644 --- a/system-contracts/contracts/EvmInterpreterFunctions.template.yul +++ b/system-contracts/contracts/EvmInterpreterFunctions.template.yul @@ -777,7 +777,12 @@ function getEVMGas() -> evmGas { function _getZkEVMGas(_evmGas, addr) -> zkevmGas { zkevmGas := mul(_evmGas, GAS_DIVISOR()) let byteSize := extcodesize(addr) - zkevmGas := add(zkevmGas, mul(byteSize, DECOMMIT_COST_PER_WORD())) + let should_ceil := mod(byteSize, 32) + if gt(should_ceil, 0) { + byteSize := add(byteSize, sub(32, should_ceil)) + } + let decommitGasCost := mul(div(byteSize,32), DECOMMIT_COST_PER_WORD()) + zkevmGas := sub(zkevmGas, decommitGasCost) if gt(zkevmGas, UINT32_MAX()) { zkevmGas := UINT32_MAX() } diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index 4f997b4bf..dddc81c28 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -851,7 +851,12 @@ object "EVMInterpreter" { function _getZkEVMGas(_evmGas, addr) -> zkevmGas { zkevmGas := mul(_evmGas, GAS_DIVISOR()) let byteSize := extcodesize(addr) - zkevmGas := add(zkevmGas, mul(byteSize, DECOMMIT_COST_PER_WORD())) + let should_ceil := mod(byteSize, 32) + if gt(should_ceil, 0) { + byteSize := add(byteSize, sub(32, should_ceil)) + } + let decommitGasCost := mul(div(byteSize,32), DECOMMIT_COST_PER_WORD()) + zkevmGas := sub(zkevmGas, decommitGasCost) if gt(zkevmGas, UINT32_MAX()) { zkevmGas := UINT32_MAX() } @@ -3474,7 +3479,12 @@ object "EVMInterpreter" { function _getZkEVMGas(_evmGas, addr) -> zkevmGas { zkevmGas := mul(_evmGas, GAS_DIVISOR()) let byteSize := extcodesize(addr) - zkevmGas := add(zkevmGas, mul(byteSize, DECOMMIT_COST_PER_WORD())) + let should_ceil := mod(byteSize, 32) + if gt(should_ceil, 0) { + byteSize := add(byteSize, sub(32, should_ceil)) + } + let decommitGasCost := mul(div(byteSize,32), DECOMMIT_COST_PER_WORD()) + zkevmGas := sub(zkevmGas, decommitGasCost) if gt(zkevmGas, UINT32_MAX()) { zkevmGas := UINT32_MAX() }