mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 17:23:08 +00:00
* Working linear search * Working linear search for storage keys * Macros * Gas for wextaccount * Add origin and to to the access list * Handle precompiles * Fixes * Other opcodes * Access list SLOAD * Minor * Add TODO for SSTORE * Comments * Clippy * Minor * PR feedback: cold_access * PR feedback: simplify insert_accessed_addresses_no_return macro * Fix sys_selfdestruct * Store length in global metadata and store arrays in kernel memory * Truncate address in all *CALL syscalls
57 lines
1.2 KiB
NASM
57 lines
1.2 KiB
NASM
global sys_balance:
|
|
// stack: kexit_info, address
|
|
SWAP1 %u256_to_addr
|
|
// stack: address, kexit_info
|
|
DUP1 %insert_accessed_addresses
|
|
// stack: cold_access, address, kexit_info
|
|
PUSH @GAS_COLDACCOUNTACCESS_MINUS_WARMACCESS
|
|
MUL
|
|
PUSH @GAS_WARMACCESS
|
|
ADD
|
|
%stack (gas, address, kexit_info) -> (gas, kexit_info, address)
|
|
%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
|