Skip to content

Commit

Permalink
Properly charge cost per word and substract it instead of adding
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Jul 3, 2024
1 parent 2954c3a commit 1a88e64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
14 changes: 12 additions & 2 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 1a88e64

Please sign in to comment.