Skip to content

Commit

Permalink
Charge cold access cost in *CALL* before accessing state (#124)
Browse files Browse the repository at this point in the history
* Charge cold access cost in CALL before accessing state

* PR feedback

---------

Co-authored-by: BGluth <gluthb@gmail.com>
  • Loading branch information
wborgeaud and BGluth authored Mar 26, 2024
1 parent cab64b4 commit 81b5ef2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions evm_arithmetization/src/cpu/kernel/asm/core/call_gas.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ global call_charge_gas:
// stack: is_call_or_callcode, is_call_or_staticcall, cold_access, address, gas, kexit_info, value, retdest
SWAP2
// stack: cold_access, is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
%mul_const(@GAS_COLDACCOUNTACCESS_MINUS_WARMACCESS)
%add_const(@GAS_WARMACCESS)
%jumpi(charge_cold_access_gas)
// stack: is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
call_charge_gas_contd:
PUSH @GAS_WARMACCESS
// stack: cost, is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
DUP3
// stack: is_call_or_callcode, cost, is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
Expand Down Expand Up @@ -90,3 +92,15 @@ new_cost_nonzero:
// stack: cost, is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
%add_const(@GAS_NEWACCOUNT)
%jump(after_new_cost)

charge_cold_access_gas:
// stack: is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
SWAP4
// stack: kexit_info, is_call_or_callcode, address, gas, is_call_or_staticcall, value, retdest
PUSH @GAS_COLDACCOUNTACCESS_MINUS_WARMACCESS
// stack: cold_access_cost, kexit_info, is_call_or_callcode, address, gas, is_call_or_staticcall, value, retdest
%charge_gas
// stack: kexit_info, is_call_or_callcode, address, gas, is_call_or_staticcall, value, retdest
SWAP4
// stack: is_call_or_staticcall, is_call_or_callcode, address, gas, kexit_info, value, retdest
%jump(call_charge_gas_contd)

0 comments on commit 81b5ef2

Please sign in to comment.