use.kernel::account use.kernel::constants # ERRORS # ================================================================================================= # Number of assets in a note exceed 255 const.ERR_NOTE_NUM_OF_ASSETS_EXCEED_LIMIT=0x0002002F # The current account is not native const.ERR_ACCOUNT_IS_NOT_NATIVE=0x00020030 # MEMORY ADDRESS CONSTANTS # ================================================================================================= # BOOK KEEPING # ------------------------------------------------------------------------------------------------- # The memory address at which the transaction vault root is stored const.TX_VAULT_ROOT_PTR=0 # The memory address at which a pointer to the input note being executed is stored. const.CURRENT_INPUT_NOTE_PTR=1 # The memory address at which the number of output notes is stored. const.NUM_OUTPUT_NOTES_PTR=2 # The memory address at which the input vault root is stored const.INPUT_VAULT_ROOT_PTR=3 # The memory address at which the output vault root is stored const.OUTPUT_VAULT_ROOT_PTR=4 # The memory address at which the pointer to the data of the currently accessing account is stored const.CURRENT_ACCOUNT_DATA_PTR=5 # The memory address at which the native account's new code commitment is stored. const.NEW_CODE_ROOT_PTR=6 # The memory address at which the absolute expiration block number is stored. const.TX_EXPIRATION_BLOCK_NUM_PTR=7 # GLOBAL INPUTS # ------------------------------------------------------------------------------------------------- # The memory address at which the global inputs section begins const.GLOBAL_INPUTS_SECTION_OFFSET=100 # The memory address at which the latest known block hash is stored const.BLK_HASH_PTR=100 # The memory address at which the account id is stored const.ACCT_ID_PTR=101 # The memory address at which the initial account hash is stored const.INIT_ACCT_HASH_PTR=102 # The memory address at which the input notes commitment is stored const.INPUT_NOTES_COMMITMENT_PTR=103 # The memory address at which the initial nonce is stored const.INIT_NONCE_PTR=104 # The memory address at which the transaction script mast root is stored const.TX_SCRIPT_ROOT_PTR=105 # GLOBAL BLOCK DATA # ------------------------------------------------------------------------------------------------- # The memory address at which the block data section begins const.BLOCK_DATA_SECTION_OFFSET=200 # The memory address at which the previous block hash is stored const.PREV_BLOCK_HASH_PTR=200 # The memory address at which the chain root is stored const.CHAIN_ROOT_PTR=201 # The memory address at which the account root is stored const.ACCT_DB_ROOT_PTR=202 # The memory address at which the nullifier root is stored const.NULLIFIER_ROOT_PTR=203 # The memory address at which the tx hash is stored const.TX_HASH_PTR=204 # The memory address at which the kernel root is stored const.KERNEL_ROOT_PTR=205 # The memory address at which the proof hash is stored const.PROOF_HASH_PTR=206 # The memory address at which the block metadata is stored [block_number, version, timestamp, 0] const.BLOCK_METADATA_PTR=207 # The memory address at which the note root is stored const.NOTE_ROOT_PTR=208 # CHAIN MMR # ------------------------------------------------------------------------------------------------- # The memory address at which the chain data section begins const.CHAIN_MMR_PTR=300 # The memory address at which the total number of leaves in the chain MMR is stored const.CHAIN_MMR_NUM_LEAVES_PTR=300 # The memory address at which the chain mmr peaks are stored const.CHAIN_MMR_PEAKS_PTR=301 # KERNEL DATA # ------------------------------------------------------------------------------------------------- # The memory address at which the number of the procedures of the selected kernel is stored. const.NUM_KERNEL_PROCEDURES_PTR=400 # The memory address at which the hashes of kernel procedures begin. # TODO: choose the proper memory location for the kernel procedures. const.KERNEL_PROCEDURES_PTR=401 # ACCOUNT DATA # ------------------------------------------------------------------------------------------------- # The largest memory address which can be used to load the foreign account data. # It is computed as `2048 * 64` -- this is the memory address where the data block of the 64th # account starts. const.MAX_FOREIGN_ACCOUNT_PTR=131072 # The memory address at which the native account data is stored. const.NATIVE_ACCOUNT_DATA_PTR=2048 # The length of the memory interval that the account data occupies. const.ACCOUNT_DATA_LENGTH=2048 # The offsets at which the account data is stored relative to the start of the account data segment. const.ACCT_ID_AND_NONCE_OFFSET=0 const.ACCT_VAULT_ROOT_OFFSET=1 const.ACCT_STORAGE_COMMITMENT_OFFSET=2 const.ACCT_CODE_COMMITMENT_OFFSET=3 const.ACCT_CORE_DATA_SECTION_END_OFFSET=4 const.NUM_ACCT_PROCEDURES_OFFSET=7 const.ACCT_PROCEDURES_SECTION_OFFSET=8 const.NUM_ACCT_STORAGE_SLOTS_OFFSET=521 const.ACCT_STORAGE_SLOTS_SECTION_OFFSET=522 # INPUT NOTES DATA # ------------------------------------------------------------------------------------------------- # The memory address at which the input note section begins. const.INPUT_NOTE_SECTION_OFFSET=1048576 # The memory address at which the input note data section begins. const.INPUT_NOTE_DATA_SECTION_OFFSET=1064960 # The memory address at which the number of input notes is stored. const.NUM_INPUT_NOTES_PTR=1048576 # The offsets at which data of a input note is stored relative to the start of its data segment const.INPUT_NOTE_ID_OFFSET=0 const.INPUT_NOTE_CORE_DATA_OFFSET=1 const.INPUT_NOTE_SERIAL_NUM_OFFSET=1 const.INPUT_NOTE_SCRIPT_ROOT_OFFSET=2 const.INPUT_NOTE_INPUTS_HASH_OFFSET=3 const.INPUT_NOTE_ASSETS_HASH_OFFSET=4 const.INPUT_NOTE_METADATA_OFFSET=5 const.INPUT_NOTE_ARGS_OFFSET=6 const.INPUT_NOTE_NUM_ASSETS_OFFSET=7 const.INPUT_NOTE_ASSETS_OFFSET=8 # OUTPUT NOTES # ------------------------------------------------------------------------------------------------- # The memory address at which the output notes section begins. const.OUTPUT_NOTE_SECTION_OFFSET=4194304 # The offsets at which data of a output note is stored relative to the start of its data segment. const.OUTPUT_NOTE_ID_OFFSET=0 const.OUTPUT_NOTE_METADATA_OFFSET=1 const.OUTPUT_NOTE_RECIPIENT_OFFSET=2 const.OUTPUT_NOTE_ASSETS_HASH_OFFSET=3 const.OUTPUT_NOTE_NUM_ASSETS_OFFSET=4 const.OUTPUT_NOTE_ASSETS_OFFSET=5 # MEMORY PROCEDURES # ================================================================================================= # BOOK KEEPING # ------------------------------------------------------------------------------------------------- #! Returns the number of output notes. #! #! Stack: [] #! Output: [num_output_notes] export.get_num_output_notes push.NUM_OUTPUT_NOTES_PTR mem_load end #! Sets the number of output notes. #! #! Stack: [num_output_notes] #! Output: [] export.set_num_output_notes push.NUM_OUTPUT_NOTES_PTR mem_store end #! Returns a pointer to the input note being executed. #! #! Stack: [] #! Output: [note_ptr] #! #! Where: #! - note_ptr, the memory address of the data segment for the current input note. export.get_current_input_note_ptr push.CURRENT_INPUT_NOTE_PTR mem_load end #! Sets the current input note pointer to the input note being executed. #! #! Stack: [note_ptr] #! Output: [] #! #! Where: #! - note_ptr, the new memory address of the data segment for the input note. export.set_current_input_note_ptr push.CURRENT_INPUT_NOTE_PTR mem_store end #! Returns a pointer to the memory address at which the input vault root is stored #! #! Stack: [] #! Output: [input_vault_root_ptr] #! #! Where: #! - input_vault_root_ptr is a pointer to the memory address at which the input vault root is stored export.get_input_vault_root_ptr push.INPUT_VAULT_ROOT_PTR end #! Returns the input vault root. #! #! Stack: [] #! Output: [INPUT_VAULT_ROOT] #! #! Where: #! - INPUT_VAULT_ROOT is the input vault root. export.get_input_vault_root padw push.INPUT_VAULT_ROOT_PTR mem_loadw end #! Sets the input vault root. #! #! Stack: [INPUT_VAULT_ROOT] #! Output: [INPUT_VAULT_ROOT] #! #! Where: #! - INPUT_VAULT_ROOT is the input vault root. export.set_input_vault_root push.INPUT_VAULT_ROOT_PTR mem_storew end #! Returns a pointer to the memory address at which the output vault root is stored. #! #! Stack: [] #! Output: [output_vault_root_ptr] #! #! Where: #! - output_vault_root_ptr is a pointer to the memory address at which the output vault root is stored. export.get_output_vault_root_ptr push.OUTPUT_VAULT_ROOT_PTR end #! Returns the output vault root. #! #! Stack: [] #! Output: [OUTPUT_VAULT_ROOT] #! #! Where: #! - OUTPUT_VAULT_ROOT is the output vault root. export.get_output_vault_root padw push.OUTPUT_VAULT_ROOT_PTR mem_loadw end #! Sets the output vault root. #! #! Stack: [OUTPUT_VAULT_ROOT] #! Output: [OUTPUT_VAULT_ROOT] #! #! Where: #! - OUTPUT_VAULT_ROOT is the output vault root. export.set_output_vault_root push.OUTPUT_VAULT_ROOT_PTR mem_storew end # GLOBAL INPUTS # ------------------------------------------------------------------------------------------------- #! Saves the hash of the reference block to memory. #! #! Stack: [BLOCK_HASH] #! Output: [BLOCK_HASH] #! #! Where: #! - BLOCK_HASH, reference block for the transaction execution. export.set_block_hash push.BLK_HASH_PTR mem_storew end #! Returns the block hash of the reference block. #! #! Stack: [] #! Output: [BLOCK_HASH] #! #! Where: #! - BLOCK_HASH, reference block for the transaction execution. export.get_block_hash padw push.BLK_HASH_PTR mem_loadw end #! Sets the account id. #! #! Stack: [acct_id] #! Output: [] #! #! Where: #! - acct_id is the account id. export.set_global_acct_id push.ACCT_ID_PTR mem_store end #! Returns the global account id. #! #! Stack: [] #! Output: [acct_id] #! #! - acct_id is the account id. export.get_global_acct_id push.ACCT_ID_PTR mem_load end #! Sets the initial account hash. #! #! Stack: [INIT_ACCT_HASH] #! Output: [INIT_ACCT_HASH] #! #! Where: #! - INIT_ACCT_HASH is the initial account hash. export.set_init_acct_hash push.INIT_ACCT_HASH_PTR mem_storew end #! Returns the initial account hash. #! #! Stack: [] #! Output: [INIT_ACCT_HASH] #! #! Where: #! - INIT_ACCT_HASH is the initial account hash. export.get_init_acct_hash padw push.INIT_ACCT_HASH_PTR mem_loadw end #! Returns the input notes commitment. #! #! See `transaction::api::get_input_notes_commitment` for details. #! #! Stack: [] #! Outputs: [INPUT_NOTES_COMMITMENT] #! #! Where: #! - INPUT_NOTES_COMMITMENT is the input notes commitment. export.get_input_notes_commitment padw push.INPUT_NOTES_COMMITMENT_PTR mem_loadw end #! Sets the input notes' commitment. #! #! Stack: [INPUT_NOTES_COMMITMENT] #! Output: [INPUT_NOTES_COMMITMENT] #! #! Where: #! - INPUT_NOTES_COMMITMENT is the notes' commitment. export.set_nullifier_commitment push.INPUT_NOTES_COMMITMENT_PTR mem_storew end #! Returns the initial account nonce. #! #! Stack: [] #! Output: [init_nonce] #! #! Where: #! - init_nonce is the initial account nonce. export.get_init_nonce push.INIT_NONCE_PTR mem_load end #! Sets the initial account nonce. #! #! Stack: [init_nonce] #! Output: [] #! #! - init_nonce is the initial account nonce. export.set_init_nonce push.INIT_NONCE_PTR mem_store end #! Returns a memory address of the transaction script root. #! #! Stack: [] #! Output: [tx_script_root_ptr] #! #! Where: #! - tx_script_root_ptr is the pointer to the memory where transaction script root is stored. export.get_tx_script_root_ptr push.TX_SCRIPT_ROOT_PTR end #! Sets the transaction script root. #! #! Stack: [TX_SCRIPT_ROOT] #! Output: [TX_SCRIPT_ROOT] #! #! Where: #! - TX_SCRIPT_ROOT is the transaction script root. export.set_tx_script_root push.TX_SCRIPT_ROOT_PTR mem_storew end # BLOCK DATA # ------------------------------------------------------------------------------------------------- #! Returns a pointer to the block data section. #! #! Stack: [] #! Output: [ptr] #! #! Where: #! - ptr is a pointer to the block data section. export.get_block_data_ptr push.BLOCK_DATA_SECTION_OFFSET end #! Returns the previous block hash of the last known block. #! #! Stack: [] #! Output: [PREV_BLOCK_HASH] #! #! Where: #! - PREV_BLOCK_HASH is the previous block hash of the last known block. export.get_prv_blk_hash padw push.PREV_BLOCK_HASH_PTR mem_loadw end #! Returns the block number of the last known block. #! #! Stack: [] #! Output: [blk_num] #! #! Where: #! - blk_num is the block number of the last known block. export.get_blk_num push.BLOCK_METADATA_PTR mem_load end #! Returns the protocol version of the last known block. #! #! Stack: [] #! Output: [version] #! #! Where: #! - version is the protocol version of the last known block. export.get_blk_version padw push.BLOCK_METADATA_PTR mem_loadw drop drop swap drop end #! Returns the block timestamp of the last known block. #! #! Stack: [] #! Output: [timestamp] #! #! Where: #! - timestamp is the block timestamp of the last known block. export.get_blk_timestamp padw push.BLOCK_METADATA_PTR mem_loadw drop movdn.2 drop drop end #! Returns the chain root of the last known block. #! #! Stack: [] #! Output: [CHAIN_ROOT] #! #! Where: #! - CHAIN_ROOT is the chain root of the last known block. export.get_chain_root padw push.CHAIN_ROOT_PTR mem_loadw end #! Returns the account db root of the last known block. #! #! Stack: [] #! Output: [ACCT_DB_ROOT] #! #! Where: #! - ACCT_DB_ROOT is the account database root of the last known block. export.get_acct_db_root padw push.ACCT_DB_ROOT_PTR mem_loadw end #! Returns the nullifier db root of the last known block. #! #! Stack: [] #! Output: [NULLIFIER_ROOT] #! #! Where: #! - NULLIFIER_ROOT is the nullifier root of the last known block. export.get_nullifier_db_root padw push.NULLIFIER_ROOT_PTR mem_loadw end #! Returns the tx hash of the last known block. #! #! Stack: [] #! Output: [TX_HASH] #! #! Where: #! - TX_HASH is the tx hash of the last known block. export.get_tx_hash padw push.TX_HASH_PTR mem_loadw end #! Returns the kernel root used in the last known block. #! #! Stack: [] #! Output: [KERNEL_ROOT] #! #! Where: #! - KERNEL_ROOT is an accumulative hash from all kernel hashes. export.get_kernel_root padw push.KERNEL_ROOT_PTR mem_loadw end #! Returns the proof hash of the last known block. #! #! Stack: [] #! Output: [PROOF_HASH] #! #! Where: #! - PROOF_HASH is the proof hash of the last known block. export.get_proof_hash padw push.PROOF_HASH_PTR mem_loadw end #! Returns the note root of the last known block. #! #! Stack: [] #! Output: [NOTE_ROOT] #! #! Where: #! - NOTE_ROOT is the note root of the last known block. export.get_note_root padw push.NOTE_ROOT_PTR mem_loadw end #! Sets the note root of the last known block. #! #! Stack: [NOTE_ROOT] #! Output: [NOTE_ROOT] #! #! Where: #! - NOTE_ROOT is the note root of the last known block. export.set_note_root push.NOTE_ROOT_PTR mem_storew end # CHAIN DATA # ------------------------------------------------------------------------------------------------- #! Returns a pointer to the chain MMR section. #! #! Stack: [] #! Output: [ptr] #! #! Where: #! - ptr is a pointer to the chain MMR section. export.get_chain_mmr_ptr push.CHAIN_MMR_PTR end #! Sets the number of leaves in the chain MMR. #! #! Stack: [num_leaves] #! Output: [] #! #! Where: #! - num_leaves is the number of leaves in the chain MMR. export.set_chain_mmr_num_leaves push.CHAIN_MMR_NUM_LEAVES_PTR mem_store end #! Returns a pointer to start of the chain MMR peaks section. #! #! Stack: [] #! Output: [ptr] #! #! Where: #! - ptr is a pointer to the start of the chain MMR peaks section. export.get_chain_mmr_peaks_ptr push.CHAIN_MMR_PEAKS_PTR end # ACCOUNT DATA # ------------------------------------------------------------------------------------------------- #! Returns the memory pointer at which the native account data is stored. #! #! Stack: [] #! Output: [ptr] #! #! Where: #! - ptr is the memory address at which the native account data is stored. export.get_native_account_data_ptr push.NATIVE_ACCOUNT_DATA_PTR end #! Returns the length of the memory interval that the account data occupies. #! #! Stack: [] #! Output: [acct_data_length] export.get_account_data_length push.ACCOUNT_DATA_LENGTH end #! Returns the largest memory address which can be used to load the foreign account data. #! #! Stack: [] #! Output: [max_foreign_acct_ptr] export.get_max_foreign_account_ptr push.MAX_FOREIGN_ACCOUNT_PTR end #! Sets the memory pointer of the current account data to the native account (2048). #! #! Stack: [] #! Output: [] export.set_current_account_data_ptr_to_native_account push.NATIVE_ACCOUNT_DATA_PTR push.CURRENT_ACCOUNT_DATA_PTR mem_store end #! Returns the memory pointer of the current account data. #! #! Stack: [] #! Output: [ptr] #! #! Where: #! - ptr is the memory address at which the account data begins. export.get_current_account_data_ptr push.CURRENT_ACCOUNT_DATA_PTR mem_load end #! Sets the memory pointer of the current account data to the provided value. #! #! Stack: [curr_account_data_ptr] #! Output: [] #! #! Where: #! - curr_account_data_ptr is the memory pointer to the currently accessing account data. export.set_current_account_data_ptr push.CURRENT_ACCOUNT_DATA_PTR mem_store end #! Asserts that current account data pointer matches the data pointer of the native account (2048). #! It is used to prevent usage of the account procedures which can mutate the account state with the #! foreign accounts. #! #! Stack: [] #! Output: [] #! #! Panics: #! - if the current account data pointer is not equal to native account data pointer (2048). export.assert_native_account push.CURRENT_ACCOUNT_DATA_PTR mem_load push.NATIVE_ACCOUNT_DATA_PTR assert_eq.err=ERR_ACCOUNT_IS_NOT_NATIVE end #! Returns a pointer to the end of the core account data section. #! #! Stack: [] #! Output: [ptr] #! #! Where: #! - ptr is the memory address at which the core account data ends. export.get_core_acct_data_end_ptr exec.get_current_account_data_ptr push.ACCT_CORE_DATA_SECTION_END_OFFSET add end ### ACCOUNT ID AND NONCE ################################################# #! Returns the id of the current account. #! #! Stack: [] #! Output: [curr_acct_id] #! #! Where: #! - curr_acct_id is the account id of the currently accessing account. export.get_account_id exec.get_current_account_data_ptr push.ACCT_ID_AND_NONCE_OFFSET add mem_load end #! Sets the account id and nonce. #! #! Stack: [account_nonce, 0, 0, account_id] #! Output: [account_nonce, 0, 0, account_id] #! #! Where: #! - account_id is the id of the currently accessing account. #! - account_nonce is the nonce of the currently accessing account. export.set_acct_id_and_nonce exec.get_current_account_data_ptr push.ACCT_ID_AND_NONCE_OFFSET add mem_storew end #! Returns the id of the native account. #! #! Stack: [] #! Output: [native_acct_id] #! #! Where: #! - native_acct_id is the id of the native account. export.get_native_account_id push.NATIVE_ACCOUNT_DATA_PTR push.ACCT_ID_AND_NONCE_OFFSET add mem_load end #! Returns the account nonce. #! #! Stack: [] #! Output: [acct_nonce] #! #! Where: #! - acct_nonce is the account nonce. export.get_acct_nonce padw exec.get_current_account_data_ptr push.ACCT_ID_AND_NONCE_OFFSET add mem_loadw movdn.3 drop drop drop end #! Sets the account nonce. #! #! Stack: [acct_nonce] #! Output: [] #! #! Where: #! - acct_nonce is the account nonce. export.set_acct_nonce exec.get_current_account_data_ptr push.ACCT_ID_AND_NONCE_OFFSET add padw dup.4 mem_loadw # => [old_nonce, 0, 0, old_id, acct_id_and_nonce_ptr, new_nonce] drop movup.4 movup.4 mem_storew dropw end ### ACCOUNT VAULT ################################################# #! Returns the memory pointer to the account vault root. #! #! Stack: [] #! Output: [acct_vault_root_ptr] #! #! Where: #! - acct_vault_root_ptr is the memory pointer to the account asset vault root. export.get_acct_vault_root_ptr exec.get_current_account_data_ptr push.ACCT_VAULT_ROOT_OFFSET add end #! Returns the account vault root. #! #! Stack: [] #! Output: [ACCT_VAULT_ROOT] #! #! Where: #! - ACCT_VAULT_ROOT is the account asset vault root. export.get_acct_vault_root padw exec.get_current_account_data_ptr push.ACCT_VAULT_ROOT_OFFSET add mem_loadw end #! Sets the account vault root. #! #! Stack: [ACCT_VAULT_ROOT] #! Output: [ACCT_VAULT_ROOT] #! #! Where: #! - ACCT_VAULT_ROOT is the account vault root to be set. export.set_acct_vault_root exec.get_current_account_data_ptr push.ACCT_VAULT_ROOT_OFFSET add mem_storew end ### ACCOUNT CODE ################################################# #! Returns the code commitment of the account. #! #! Stack: [] #! Output: [CODE_COMMITMENT] #! #! Where: #! - CODE_COMMITMENT is the code commitment of the account. export.get_acct_code_commitment padw exec.get_current_account_data_ptr push.ACCT_CODE_COMMITMENT_OFFSET add mem_loadw end #! Sets the code commitment of the account. #! #! Stack: [CODE_COMMITMENT] #! Output: [CODE_COMMITMENT] #! #! Where: #! - CODE_COMMITMENT is the code commitment to be set. export.set_acct_code_commitment exec.get_current_account_data_ptr push.ACCT_CODE_COMMITMENT_OFFSET add mem_storew end #! Returns the new account code commitment. #! #! Stack: [] #! Output: [CODE_COMMITMENT] #! #! Where: #! - CODE_COMMITMENT is the new account code commitment. export.get_new_acct_code_commitment padw push.NEW_CODE_ROOT_PTR mem_loadw end #! Stores the new account code commitment in memory. #! #! Stack: [CODE_COMMITMENT] #! Output: [CODE_COMMITMENT] #! #! Where: #! - CODE_COMMITMENT is the new account code commitment. export.set_new_acct_code_commitment push.NEW_CODE_ROOT_PTR mem_storew end #! Sets the transaction expiration block number. #! #! Inputs: [tx_expiration_block_num, ...] #! Output: [...] export.set_expiration_block_num push.TX_EXPIRATION_BLOCK_NUM_PTR mem_store end #! Gets the transaction expiration block number. #! #! Inputs: [] #! Output: [tx_expiration_block_num] export.get_expiration_block_num push.TX_EXPIRATION_BLOCK_NUM_PTR mem_load end #! Returns the number of procedures contained in the account code. #! #! Stack: [] #! Output: [num_procedures] #! #! Where: #! - num_procedures is the number of procedures contained in the account code. export.get_num_account_procedures exec.get_current_account_data_ptr push.NUM_ACCT_PROCEDURES_OFFSET add mem_load end #! Sets the number of procedures contained in the account code. #! #! Stack: [num_procedures] #! Output: [] #! #! Where: #! - num_procedures is the number of procedures contained in the account code. export.set_num_account_procedures exec.get_current_account_data_ptr push.NUM_ACCT_PROCEDURES_OFFSET add mem_store end #! Returns the memory pointer to the account procedures section. #! #! Stack: [] #! Output: [account_procedures_section_ptr] #! #! Where: #! - account_procedures_section_ptr is the memory pointer to the account procedures section. export.get_acct_procedures_section_ptr exec.get_current_account_data_ptr push.ACCT_PROCEDURES_SECTION_OFFSET add end ### ACCOUNT STORAGE ################################################# #! Returns the account storage commitment. #! #! Stack: [] #! Output: [STORAGE_COMMITMENT] #! #! Where: #! - STORAGE_COMMITMENT is the account storage commitment. export.get_acct_storage_commitment padw exec.get_current_account_data_ptr push.ACCT_STORAGE_COMMITMENT_OFFSET add mem_loadw end #! Sets the account storage commitment. #! #! Stack: [STORAGE_COMMITMENT] #! Output: [STORAGE_COMMITMENT] #! #! Where: #! - STORAGE_COMMITMENT is the account storage commitment. export.set_acct_storage_commitment exec.get_current_account_data_ptr push.ACCT_STORAGE_COMMITMENT_OFFSET add mem_storew end #! Returns the number of storage slots contained in the account storage. #! #! Stack: [] #! Output: [num_storage_slots] #! #! Where: #! - num_storage_slots is the number of storage slots contained in the account storage. export.get_num_storage_slots exec.get_current_account_data_ptr push.NUM_ACCT_STORAGE_SLOTS_OFFSET add mem_load end #! Sets the number of storage slots contained in the account storage. #! #! Stack: [num_storage_slots] #! Output: [] #! #! Where: #! - num_storage_slots is the number of storage slots contained in the account storage. export.set_num_storage_slots exec.get_current_account_data_ptr push.NUM_ACCT_STORAGE_SLOTS_OFFSET add mem_store end #! Returns the memory pointer to the account storage slots section. #! #! Stack: [] #! Output: [storage_slots_section_ptr] #! #! Where: #! - storage_slots_section_ptr is the memory pointer to the account storage slots section. export.get_acct_storage_slots_section_ptr exec.get_current_account_data_ptr push.ACCT_STORAGE_SLOTS_SECTION_OFFSET add end # INPUT NOTES # ------------------------------------------------------------------------------------------------- #! Gets the total number of input notes in the transaction. #! #! Stack: [] #! Output: [num_input_notes] #! #! Where: #! - num_input_notes is the total number of input notes in the transaction. export.get_num_input_notes push.NUM_INPUT_NOTES_PTR mem_load end #! Sets the total number of input notes in the transaction. #! #! Stack: [num_input_notes] #! Output: [] #! #! Where: #! - num_input_notes is the total number of input notes in the transaction. export.set_num_input_notes push.NUM_INPUT_NOTES_PTR mem_store end #! Computes a pointer to the memory address at which the data associated with a input note with #! index `idx` is stored. #! #! Stack: [idx] #! Output: [note_ptr] #! #! Where: #! - idx, the index of the input note. #! - note_ptr, the memory address of the data segment for the input note with `idx`. export.get_input_note_ptr exec.constants::get_note_mem_size mul push.INPUT_NOTE_DATA_SECTION_OFFSET add end #! Set the note id of the input note. #! #! Stack: [note_ptr, NOTE_ID] #! Output: [NOTE_ID] #! #! Where: #! - note_ptr, the input note's the memory address. #! - NOTE_ID, the note's id. export.set_input_note_id mem_storew end #! Computes a pointer to the memory address at which the nullifier associated a note with `idx` #! is stored. #! #! Stack: [idx] #! Output: [nullifier_ptr] #! #! Where: #! - idx, the index of the input note. #! - nullifier_ptr, the memory address of the nullifier for note idx. export.get_input_note_nullifier_ptr push.INPUT_NOTE_SECTION_OFFSET.1 add add end #! Returns the nullifier of a input note with `idx`. #! #! Stack: [idx] #! Output: [nullifier] #! #! Where: #! - idx, the index of the input note. #! - nullifier, the nullifier of the input note. export.get_input_note_nullifier padw movup.4 push.INPUT_NOTE_SECTION_OFFSET.1 add add mem_loadw end #! Returns a pointer to the start of the input note core data segment for the note located at #! the specified memory address. #! #! Stack: [note_ptr] #! Output: [note_data_ptr] #! #! Where: #! - note_ptr, the memory address at which the input note data begins. #! - note_data_ptr, the memory address at which the input note core data begins. export.get_input_note_core_ptr push.INPUT_NOTE_CORE_DATA_OFFSET add end #! Returns the script root of a input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [SCRIPT_HASH] #! #! Where: #! - note_ptr, the memory address at which the input note data begins. #! - SCRIPT_HASH, the script root of the input note. export.get_input_note_script_root padw movup.4 push.INPUT_NOTE_SCRIPT_ROOT_OFFSET add mem_loadw end #! Returns the memory address of the script root of a input note. #! #! Stack: [note_ptr] #! Output: [script_root_ptr] #! #! Where: #! - note_ptr, the memory address at which the input note data begins. #! - script_root_ptr, the memory address where script root of the input note is stored. export.get_input_note_script_root_ptr push.INPUT_NOTE_SCRIPT_ROOT_OFFSET add end #! Returns the inputs hash of a input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [INPUTS_HASH] #! #! Where: #! - note_ptr, the memory address at which the input note data begins. #! - INPUTS_HASH, the inputs hash of the input note. export.get_input_note_inputs_hash padw movup.4 push.INPUT_NOTE_INPUTS_HASH_OFFSET add mem_loadw end #! Returns the metadata of a input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [METADATA] #! #! Where: #! - note_ptr, the memory address at which the input note data begins. #! - METADATA, the metadata of the input note. export.get_input_note_metadata padw movup.4 push.INPUT_NOTE_METADATA_OFFSET add mem_loadw end #! Sets the metadata for a input note located at the specified memory address. #! #! Stack: [note_ptr, NOTE_METADATA] #! Output: [NOTE_METADATA] #! #! Where: #! - note_ptr, the memory address at which the input note data begins. #! - NOTE_METADATA, the metadata of the input note. export.set_input_note_metadata push.INPUT_NOTE_METADATA_OFFSET add mem_storew end #! Returns the note's args. #! #! Stack: [note_ptr] #! Output: [NOTE_ARGS] #! #! Where: #! - note_ptr, the start memory address of the note. #! - NOTE_ARGS, the note's args. export.get_input_note_args padw movup.4 push.INPUT_NOTE_ARGS_OFFSET add mem_loadw end #! Sets the note args for a input note located at the specified memory address. #! #! Stack: [note_ptr, NOTE_ARGS] #! Output: [NOTE_ARGS] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - NOTE_ARGS are optional note args of the input note. export.set_input_note_args push.INPUT_NOTE_ARGS_OFFSET add mem_storew end #! Returns the number of assets in the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [num_assets] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - num_assets is the number of assets in the input note. export.get_input_note_num_assets push.INPUT_NOTE_NUM_ASSETS_OFFSET add mem_load end #! Sets the number of assets for a input note located at the specified memory address. #! #! Stack: [note_ptr, num_assets] #! Output: [] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - num_assets is the number of assets in the input note. export.set_input_note_num_assets push.INPUT_NOTE_NUM_ASSETS_OFFSET add mem_store end #! Returns a pointer to the start of the assets segment for the input note located at #! the specified memory address. #! #! Stack: [note_ptr] #! Output: [assets_ptr] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - assets_ptr is the memory address at which the assets segment for the input note begins. export.get_input_note_assets_ptr push.INPUT_NOTE_ASSETS_OFFSET add end #! Returns the assets hash for the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [ASSET_HASH] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - ASSET_HASH, sequential hash of the padded assets of a input note. export.get_input_note_assets_hash padw movup.4 push.INPUT_NOTE_ASSETS_HASH_OFFSET add mem_loadw end #! Returns the serial number for the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [SERIAL_NUMBER] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - SERIAL_NUMBER, the input note's serial number. export.get_input_note_serial_num padw movup.4 push.INPUT_NOTE_SERIAL_NUM_OFFSET add mem_loadw end #! Returns the sender for the input note located at the specified memory address. #! #! Stack: [note_ptr] #! Output: [sender] #! #! Where: #! - note_ptr is the memory address at which the input note data begins. #! - sender is the sender for the input note. export.get_input_note_sender padw movup.4 push.INPUT_NOTE_METADATA_OFFSET add mem_loadw # => [aux, encoded_type_and_ex_hint, sender, tag] drop drop swap drop # => [sender] end # OUTPUT NOTES # ------------------------------------------------------------------------------------------------- #! Returns the offset of the output note data segment. #! #! Stack: [] #! Output: [offset] #! #! Where: #! - offset is the offset of the output note data segment. export.get_output_note_data_offset push.OUTPUT_NOTE_SECTION_OFFSET end #! Computes a pointer to the memory address at which the data associated with a output note with #! index `i` is stored. #! #! Stack: [i] #! Output: [ptr] #! #! Where: #! - i is the index of the output note. #! - ptr is the memory address of the data segment for output note i. export.get_output_note_ptr exec.constants::get_note_mem_size mul push.OUTPUT_NOTE_SECTION_OFFSET add end #! Returns the output note recipient #! #! Stack: [output_note_data_ptr] #! Output: [R] #! #! Where: #! - output_note_data_ptr is the memory address at which the output note data begins. #! - R is the recipient of the output note. export.get_output_note_recipient padw movup.4 push.OUTPUT_NOTE_RECIPIENT_OFFSET add mem_loadw end #! Sets the output note's recipient #! #! Stack: [note_ptr, RECIPIENT] #! Output: [RECIPIENT] #! #! Where: #! - recipient is the recipient of the note #! - note_ptr is the memory address at which the output note data begins. export.set_output_note_recipient push.OUTPUT_NOTE_RECIPIENT_OFFSET add mem_storew end #! Sets the output note's metadata #! #! Stack: [note_ptr, METADATA] #! Output: [METADATA] #! #! Where: #! - METADATA is the note metadata #! - note_ptr is the memory address at which the output note data begins. export.set_output_note_metadata push.OUTPUT_NOTE_METADATA_OFFSET add mem_storew end #! Returns the number of assets in the output note #! #! Stack: [note_ptr] #! Output: [num_assets] #! #! Where: #! - note_ptr is a pointer to the memory address at which the output note is stored. #! - num_assets is the number of assets in the output note. export.get_output_note_num_assets push.OUTPUT_NOTE_NUM_ASSETS_OFFSET add mem_load end #! Sets the number of assets in the output note #! #! Stack: [note_ptr, num_assets] #! Output: [] #! #! Where: #! - note_ptr is the memory address at which the output note data begins. #! - num_assets is the number of assets in the output note. #! #! Panics: if the number of assets exceeds the maximum allowed number of assets per note. export.set_output_note_num_assets push.OUTPUT_NOTE_NUM_ASSETS_OFFSET add # => [note_ptr + offset, num_assets] # check note number of assets limit dup.1 exec.constants::get_max_assets_per_note lt assert.err=ERR_NOTE_NUM_OF_ASSETS_EXCEED_LIMIT mem_store end #! Returns a pointer to the output note asset data #! #! Stack: [output_note_data_ptr] #! Output: [asset_data_ptr] #! #! Where: #! - output_note_data_ptr is the memory address at which the output note data begins. #! - asset_data_ptr is the memory address at which the output note asset data begins. export.get_output_note_asset_data_ptr push.OUTPUT_NOTE_ASSETS_OFFSET add end #! Sets the output note assets hash. #! #! Stack: [output_note_data_ptr, ASSET_HASH] #! Output: [ASSET_HASH] #! #! Where: #! - output_note_data_ptr is the memory address at which the output note data begins. #! - ASSET_HASH, sequential hash of the padded assets of an output note. export.set_output_note_assets_hash push.OUTPUT_NOTE_ASSETS_HASH_OFFSET add mem_storew end # KERNEL DATA # ------------------------------------------------------------------------------------------------- #! Sets the number of of the procedures of the selected kernel. #! #! Stack: [num_kernel_procedures] #! Output: [] #! #! Where: #! - num_kernel_procedures is the number of the procedures of the selected kernel. export.set_num_kernel_procedures push.NUM_KERNEL_PROCEDURES_PTR mem_store end #! Returns the number of the procedures of the selected kernel. #! #! Stack: [] #! Output: [num_kernel_procedures] #! #! Where: #! - num_kernel_procedures is the number of the procedures of the selected kernel. export.get_num_kernel_procedures push.NUM_KERNEL_PROCEDURES_PTR mem_load end #! Returns a pointer to the memory where hashes of the kernel procedures are stored. #! #! Stack: [] #! Output: [kernel_procedures_ptr] #! #! Where: #! - kernel_procedures_ptr is the memory address where the hashes of the kernel procedures are stored. export.get_kernel_procedures_ptr push.KERNEL_PROCEDURES_PTR end