plonky2/evm/src/cpu/kernel/asm/balance.asm
Robin Salen 990eb34d96
Remove some CPU cycles (#1469)
* Amortize mload_packing

* Reduce stack overhead

* Amortize mstore_unpacking

* Speed-up stack operation in hash.asm

* Misc

* Small tweaks

* Misc small optims

* Fix comments

* Fix main access to withdrawals

* Fix stack description

* minor: rename label

* Comments

---------

Co-authored-by: Linda Guiga <lindaguiga3@gmail.com>
2024-01-16 17:00:55 +00:00

57 lines
1.2 KiB
NASM

global sys_balance:
// stack: kexit_info, address
SWAP1 %u256_to_addr
// stack: address, kexit_info
SWAP1
DUP2 %insert_accessed_addresses
// stack: cold_access, kexit_info, address
PUSH @GAS_COLDACCOUNTACCESS_MINUS_WARMACCESS
MUL
PUSH @GAS_WARMACCESS
ADD
%charge_gas
// stack: kexit_info, address
SWAP1
// stack: address, kexit_info
%balance
// stack: balance, kexit_info
SWAP1
EXIT_KERNEL
%macro balance
%stack (address) -> (address, %%after)
%jump(balance)
%%after:
%endmacro
global balance:
// stack: address, retdest
%mpt_read_state_trie
// stack: account_ptr, retdest
DUP1 ISZERO %jumpi(retzero) // If the account pointer is null, return 0.
%add_const(1)
// stack: balance_ptr, retdest
%mload_trie_data
// stack: balance, retdest
SWAP1 JUMP
retzero:
%stack (account_ptr, retdest) -> (retdest, 0)
JUMP
global sys_selfbalance:
// stack: kexit_info
%charge_gas_const(@GAS_LOW)
%selfbalance
// stack: balance, kexit_info
SWAP1
EXIT_KERNEL
%macro selfbalance
PUSH %%after
%address
%jump(balance)
%%after:
%endmacro