use.miden::kernels::tx::constants # ERRORS # ================================================================================================= const.ERR_NOTE_TOO_MANY_ASSETS=0x0002002A # 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 consumed note being executed is stored. const.CURRENT_CONSUMED_NOTE_PTR=1 # The memory address at which the number of created notes is stored. const.NUM_CREATED_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 # 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 store 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 proof hash is stored const.PROOF_HASH_PTR=205 # The memory address at which the block metadata is stored [block_number, version, timestamp, 0] const.BLOCK_METADATA_PTR=206 # The memory address at which the note root is stored const.NOTE_ROOT_PTR=207 # 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 # ACCOUNT DATA # ------------------------------------------------------------------------------------------------- # The memory address at which the account data section begins const.ACCT_DATA_SECTION_OFFSET=400 # The memory address at which the account id and nonce is stored. # The account id is stored in the first element. # The account nonce is stored in the fourth element. const.ACCT_ID_AND_NONCE_PTR=400 # The memory address at which the account vault root is stored const.ACCT_VAULT_ROOT_PTR=401 # The memory address at which the account storage root is stored const.ACCT_STORAGE_ROOT_PTR=402 # The memory address at which the account code root is stored const.ACCT_CODE_ROOT_PTR=403 # The memory address at which the new account code root is stored const.ACCT_NEW_CODE_ROOT_PTR=404 # The memory offset at which the account data section ends (exclusive) const.ACCT_CORE_DATA_SECTION_END_OFFSET=404 # The memory address at which the account storage slot type data beings const.ACCT_STORAGE_SLOT_TYPE_DATA_OFFSET=405 # CONSUMED NOTES DATA # ------------------------------------------------------------------------------------------------- # The memory address at which the consumed note section begins. const.CONSUMED_NOTE_SECTION_OFFSET=1048576 # The memory address at which the consumed note data section begins. const.CONSUMED_NOTE_DATA_SECTION_OFFSET=1064960 # The memory address at which the number of consumed notes is stored. const.CONSUMED_NOTE_NUM_PTR=1048576 # The offsets at which data of a consumed note is stored relative to the start of its data segment const.CONSUMED_NOTE_HASH_OFFSET=0 const.CONSUMED_NOTE_CORE_DATA_OFFSET=1 const.CONSUMED_NOTE_SERIAL_NUM_OFFSET=1 const.CONSUMED_NOTE_SCRIPT_ROOT_OFFSET=2 const.CONSUMED_NOTE_INPUTS_HASH_OFFSET=3 const.CONSUMED_NOTE_ASSETS_HASH_OFFSET=4 const.CONSUMED_NOTE_METADATA_OFFSET=5 const.CONSUMED_NOTE_ARGS_OFFSET=6 const.CONSUMED_NOTE_NUM_ASSETS_OFFSET=7 const.CONSUMED_NOTE_ASSETS_OFFSET=8 # CREATED NOTES # ------------------------------------------------------------------------------------------------- # The memory address at which the created notes section begins. const.CREATED_NOTE_SECTION_OFFSET=4194304 # The offsets at which data of a created note is stored relative to the start of its data segment. const.CREATED_NOTE_HASH_OFFSET=0 const.CREATED_NOTE_METADATA_OFFSET=1 const.CREATED_NOTE_RECIPIENT_OFFSET=2 const.CREATED_NOTE_ASSETS_HASH_OFFSET=3 const.CREATED_NOTE_NUM_ASSETS_OFFSET=4 const.CREATED_NOTE_ASSETS_OFFSET=5 # MEMORY PROCEDURES # ================================================================================================= # BOOK KEEPING # ------------------------------------------------------------------------------------------------- #! Returns the number of created notes. #! #! Stack: [] #! Output: [num_created_notes] export.get_num_created_notes push.NUM_CREATED_NOTES_PTR mem_load end #! Sets the number of created notes. #! #! Stack: [num_created_notes] #! Output: [] export.set_num_created_notes push.NUM_CREATED_NOTES_PTR mem_store end #! Returns a pointer to the consumed note being executed. #! #! Stack: [] #! Output: [ptr] export.get_current_consumed_note_ptr push.CURRENT_CONSUMED_NOTE_PTR mem_load end #! Sets the current consumed note pointer to the consumed note being executed. #! #! Stack: [ptr] #! Output: [] export.set_current_consumed_note_ptr push.CURRENT_CONSUMED_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] #! #! - 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] #! #! - 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 is the input vault root. export.set_input_vault_root push.INPUT_VAULT_ROOT_PTR mem_storew dropw end #! Returns a pointer to the memory address at which the output vault root is stored. #! #! Stack: [] #! Output: [output_vault_root_ptr] #! #! - 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] #! #! - 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 is the output vault root. export.set_output_vault_root push.OUTPUT_VAULT_ROOT_PTR mem_storew dropw end # GLOBAL INPUTS # ------------------------------------------------------------------------------------------------- #! Saves the hash of the reference block to memory. #! #! Stack: [BLOCK_HASH] #! Output: [] #! #! Where: #! - BLOCK_HASH, reference block for the transaction execution. export.set_block_hash push.BLK_HASH_PTR mem_storew dropw 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: [] #! #! - 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 is the initial account hash. export.set_init_acct_hash push.INIT_ACCT_HASH_PTR mem_storew dropw end #! Returns the initial account hash. #! #! Stack: [] #! Output: [INIT_ACCT_HASH] #! #! - 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: [] #! #! Where: #! - INPUT_NOTES_COMMITMENT is the notes' commitment. export.set_nullifier_commitment push.INPUT_NOTES_COMMITMENT_PTR mem_storew dropw end #! Returns the initial account nonce. #! #! Stack: [] #! Output: [init_nonce] #! #! - 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 #! Gets the transaction script root. #! #! Stack: [] #! Output: [TX_SCRIPT_ROOT] #! #! - TX_SCRIPT_ROOT is the transaction script root. export.get_tx_script_root padw push.TX_SCRIPT_ROOT_PTR mem_loadw end #! Sets the transaction script root. #! #! Stack: [TX_SCRIPT_ROOT] #! Output: [] #! #! - TX_SCRIPT_ROOT is the transaction script root. export.set_tx_script_root push.TX_SCRIPT_ROOT_PTR mem_storew dropw end # BLOCK DATA # ------------------------------------------------------------------------------------------------- #! Returns a pointer to the block data section. #! #! Stack: [] #! Output: [ptr] #! #! - 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: [PRV_BLK_HASH] #! #! - PRV_BLK_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] #! #! - 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] #! #! - 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] #! #! - 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] #! #! - 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_ROOT] #! #! - ACCT_ROOT is the account root of the last known block. export.get_account_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] #! #! - 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] #! #! - 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 proof hash of the last known block. #! #! Stack: [] #! Output: [PROOF_HASH] #! #! - 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] #! #! - 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 is the note root of the last known block. export.set_note_root push.NOTE_ROOT_PTR mem_storew dropw end # CHAIN DATA # ------------------------------------------------------------------------------------------------- #! Returns a pointer to the chain MMR section. #! #! Stack: [] #! Output: [ptr] #! #! - 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: [] #! #! - 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] #! #! - 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 a pointer to the account data. #! #! Stack: [] #! Output: [ptr] #! #! - ptr is the memory address at which the account data begins. export.get_acct_data_ptr push.ACCT_DATA_SECTION_OFFSET end #! Returns a pointer to the end of the account data section. #! #! Stack: [] #! Output: [ptr] #! #! - ptr is the memory address at which the account data ends. export.get_core_acct_data_end_ptr push.ACCT_CORE_DATA_SECTION_END_OFFSET end #! Returns the account id. #! #! Stack: [] #! Output: [acct_id] #! #! - acct_id is the account id. export.get_acct_id push.ACCT_ID_AND_NONCE_PTR mem_load end #! Returns the account nonce. #! #! Stack: [] #! Output: [acct_nonce] #! #! - acct_nonce is the account nonce. export.get_acct_nonce padw push.ACCT_ID_AND_NONCE_PTR mem_loadw movdn.3 drop drop drop end #! Sets the account nonce. #! #! Stack: [acct_nonce] #! Output: [] #! #! - acct_nonce is the account nonce. export.set_acct_nonce padw push.ACCT_ID_AND_NONCE_PTR mem_loadw drop movup.3 push.ACCT_ID_AND_NONCE_PTR mem_storew dropw end #! Sets the code root of the account. #! #! Stack: [CODE_ROOT] #! Output: [] #! #! - CODE_ROOT is the code root to be set. export.set_acct_code_root push.ACCT_CODE_ROOT_PTR mem_storew dropw end #! Returns the code root of the account. #! #! Stack: [] #! Output: [CODE_ROOT] #! #! - CODE_ROOT is the code root of the account. export.get_acct_code_root padw push.ACCT_CODE_ROOT_PTR mem_loadw end #! Stores the new account code root in memory. #! #! Stack: [CODE_ROOT] #! Output: [] #! #! - CODE_ROOT is the new account code root. export.set_new_acct_code_root push.ACCT_NEW_CODE_ROOT_PTR mem_storew dropw end #! Returns the new account code root. #! #! Stack: [] #! Output: [CODE_ROOT] #! #! - CODE_ROOT is the new account code root. export.get_new_acct_code_root padw push.ACCT_NEW_CODE_ROOT_PTR mem_loadw end #! Returns the account storage root. #! #! Stack: [] #! Output: [STORAGE_ROOT] #! #! - STORAGE_ROOT is the account storage root. export.get_acct_storage_root padw push.ACCT_STORAGE_ROOT_PTR mem_loadw end #! Sets the account storage root. #! #! Stack: [STORAGE_ROOT] #! Output: [] #! #! - STORAGE_ROOT is the account storage root. export.set_acct_storage_root push.ACCT_STORAGE_ROOT_PTR mem_storew dropw end #! Returns a pointer to the memory address at which the account vault root is stored. #! #! Stack: [] #! Output: [output_vault_root_ptr] #! #! - output_vault_root_ptr is a pointer to the memory address at which the account vault root is stored. export.get_acct_vault_root_ptr push.ACCT_VAULT_ROOT_PTR end #! Returns the account vault root. #! #! Stack: [] #! Output: [ACCT_VAULT_ROOT] #! #! - ACCT_VAULT_ROOT is the account asset vault root. export.get_acct_vault_root padw push.ACCT_VAULT_ROOT_PTR mem_loadw end #! Sets the account vault root. #! #! Stack: [ACCT_VAULT_ROOT] #! Output: [] #! #! - ACCT_VAULT_ROOT is the account vault root to be set. export.set_acct_vault_root push.ACCT_VAULT_ROOT_PTR mem_storew dropw end #! Returns a pointer to the memory address at which the account storage slot type data begins. #! #! Stack: [] #! Output: [ptr] #! #! - ptr is a pointer to the memory address at which the account storage slot type data begins. export.get_acct_storage_slot_type_data_ptr push.ACCT_STORAGE_SLOT_TYPE_DATA_OFFSET end #! Returns the storage slot type info for the specified storage slot. This includes both the #! storage slot type and the entry arity. #! #! Stack: [idx] #! Output: [slot_type_info] #! #! - idx is the index of the storage slot. #! - slot_type_info contains the slot type and entry arity. export.get_acct_storage_slot_type_data # assert the idx is a u32 value u32assert # => [idx] # compute the word offset and element offset exec.constants::get_word_size u32divmod # => [element_offset, word_offset] # compute the memory address of the storage slot type info swap exec.get_acct_storage_slot_type_data_ptr add # => [word_ptr, element_offset] # load the storage slot type info padw movup.4 mem_loadw # => [slot_type_info_i+3, slot_type_info_i+2, slot_type_info_i+1, slot_type_i, element_offset] # check if element offset == 3 and filter accordingly push.3 dup.5 eq cdrop # => [slot_type_info_i+(3|2), slot_type_info_i+1, slot_type_info_i, element_offset] # check if element offset == 1 and filter accordingly swap push.1 dup.4 eq cdrop # => [slot_type_info_i+(3|2|1), slot_type_info_i, element_offset] # check if element offset == 0 and filter accordingly swap push.0 movup.3 eq cdrop # => [slot_type_info] end # CONSUMED NOTES # ------------------------------------------------------------------------------------------------- #! Gets the total number of consumed notes in the transaction. #! #! Stack: [] #! Output: [num_consumed_notes] #! #! - num_consumed_notes is the total number of consumed notes in the transaction. export.get_total_num_consumed_notes push.CONSUMED_NOTE_NUM_PTR mem_load end #! Sets the total number of consumed notes in the transaction. #! #! Stack: [num_consumed_notes] #! Output: [] #! #! - num_consumed_notes is the total number of consumed notes in the transaction. export.set_total_num_consumed_notes push.CONSUMED_NOTE_NUM_PTR mem_store end #! Computes a pointer to the memory address at which the data associated with a consumed note with #! index i is stored. #! #! Stack: [i] #! Output: [ptr] #! #! - i is the index of the consumed note. #! - ptr is the memory address of the data segment for consumed note i. export.get_consumed_note_ptr exec.constants::get_note_mem_size mul push.CONSUMED_NOTE_DATA_SECTION_OFFSET add end #! Set the note id of the consumed note. #! #! Stack: [consumed_note_ptr, NOTE_ID] #! Output: [NOTE_ID] #! #! Where: #! - consumed_note_ptr, the consumed note's the memory address. #! - NOTE_ID, the note's id. export.set_consumed_note_id mem_storew end #! Computes a pointer to the memory address at which the nullifier associated a note with index i #! is stored. #! #! Stack: [i] #! Output: [ptr] #! #! - i is the index of the consumed note. #! - ptr is the nullifier memory address for note i. export.get_consumed_note_nullifier_ptr push.CONSUMED_NOTE_SECTION_OFFSET.1 add add end #! Returns the nullifier of a consumed note with index i. #! #! Stack: [i] #! Output: [nullifier] #! #! - i is the index of the consumed note. #! - nullifier is the nullifier of the consumed note. export.get_consumed_note_nullifier padw movup.4 push.CONSUMED_NOTE_SECTION_OFFSET.1 add add mem_loadw end #! Returns a pointer to the start of the consumed note core data segment for the note located at #! the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [ptr] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - ptr is the memory address at which the consumed note core data begins. export.get_consumed_note_core_ptr push.CONSUMED_NOTE_CORE_DATA_OFFSET add end #! Returns the script root of a consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [R] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - R is the script root of the consumed note. export.get_consumed_note_script_root padw movup.4 push.CONSUMED_NOTE_SCRIPT_ROOT_OFFSET add mem_loadw end #! Returns the inputs hash of a consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [I] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - I is the inputs hash of the consumed note. export.get_consumed_note_inputs_hash padw movup.4 push.CONSUMED_NOTE_INPUTS_HASH_OFFSET add mem_loadw end #! Returns the metadata of a consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [M] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - M is the metadata of the consumed note. export.get_consumed_note_metadata padw movup.4 push.CONSUMED_NOTE_METADATA_OFFSET add mem_loadw end #! Sets the metadata for a consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr, M] #! Output: [] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - M is the metadata of the consumed note. export.set_consumed_note_metadata push.CONSUMED_NOTE_METADATA_OFFSET add mem_storew dropw end #! Returns the note's args. #! #! Stack: [consumed_note_ptr] #! Output: [NOTE_ARGS] #! #! Where: #! - consumed_note_ptr, the start memory address of the note. #! - NOTE_ARGS, the note's args. export.get_consumed_note_args padw movup.4 push.CONSUMED_NOTE_ARGS_OFFSET add mem_loadw end #! Sets the note args for a consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr, NOTE_ARGS] #! Output: [] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - NOTE_ARGS are optional note args of the consumed note. export.set_consumed_note_args push.CONSUMED_NOTE_ARGS_OFFSET add mem_storew dropw end #! Returns the number of assets in the consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [num_assets] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - num_assets is the number of assets in the consumed note. export.get_consumed_note_num_assets push.CONSUMED_NOTE_NUM_ASSETS_OFFSET add mem_load end #! Sets the number of assets for a consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr, num_assets] #! Output: [] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - num_assets is the number of assets in the consumed note. export.set_consumed_note_num_assets push.CONSUMED_NOTE_NUM_ASSETS_OFFSET add mem_store end #! Returns a pointer to the start of the assets segment for the consumed note located at #! the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [assets_ptr] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - assets_ptr is the memory address at which the assets segment for the consumed note begins. export.get_consumed_note_assets_ptr push.CONSUMED_NOTE_ASSETS_OFFSET add end #! Returns the assets hash for the consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [AH] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - AH is the assets root for the consumed note. export.get_consumed_note_assets_hash padw movup.4 push.CONSUMED_NOTE_ASSETS_HASH_OFFSET add mem_loadw end #! Returns the serial number for the consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [S] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - S is the serial number for the consumed note. export.get_consumed_note_serial_num padw movup.4 push.CONSUMED_NOTE_SERIAL_NUM_OFFSET add mem_loadw end #! Returns the sender for the consumed note located at the specified memory address. #! #! Stack: [consumed_note_ptr] #! Output: [sender] #! #! - consumed_note_ptr is the memory address at which the consumed note data begins. #! - sender is the sender for the consumed note. export.get_consumed_note_sender padw movup.4 push.CONSUMED_NOTE_METADATA_OFFSET add mem_loadw # => [0, 0, sender, tag] drop drop swap drop # => [sender] end # CREATED NOTES # ------------------------------------------------------------------------------------------------- #! Returns the offset of the created note data segment. #! #! Stack: [] #! Output: [offset] #! #! - offset is the offset of the created note data segment. export.get_created_note_data_offset push.CREATED_NOTE_SECTION_OFFSET end #! Computes a pointer to the memory address at which the data associated with a created note with #! index i is stored. #! #! Stack: [i] #! Output: [ptr] #! #! - i is the index of the created note. #! - ptr is the memory address of the data segment for created note i. export.get_created_note_ptr exec.constants::get_note_mem_size mul push.CREATED_NOTE_SECTION_OFFSET add end #! Returns the created note recipient #! #! Stack: [created_note_data_ptr] #! Output: [R] #! #! - created_note_data_ptr is the memory address at which the created note data begins. #! - R is the recipient of the created note. export.get_created_note_recipient padw movup.4 push.CREATED_NOTE_RECIPIENT_OFFSET add mem_loadw end #! Sets the created note's recipient #! #! Stack: [note_ptr, RECIPIENT] #! Output: [] #! #! - recipient is the recipient of the note #! - note_ptr is the memory address at which the created note data begins. export.set_created_note_recipient push.CREATED_NOTE_RECIPIENT_OFFSET add mem_storew dropw end #! Sets the created note's metadata #! #! Stack: [note_ptr, METADATA] #! Output: [] #! #! - METADATA is the note metadata #! - note_ptr is the memory address at which the created note data begins. export.set_created_note_metadata push.CREATED_NOTE_METADATA_OFFSET add mem_storew dropw end #! Returns the number of assets in the created note #! #! Stack: [note_ptr] #! Output: [num_assets] #! #! - note_ptr is a pointer to the memory address at which the created note is stored. #! - num_assets is the number of assets in the created note. export.get_created_note_num_assets push.CREATED_NOTE_NUM_ASSETS_OFFSET add mem_load end #! Sets the number of assets in the created note #! #! Stack: [note_ptr, num_assets] #! Output: [] #! #! Panics: if the number of assets exceeds the maximum allowed number of assets per note. #! - note_ptr is the memory address at which the created note data begins. #! - num_assets is the number of assets in the created note. export.set_created_note_num_assets push.CREATED_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_TOO_MANY_ASSETS mem_store end #! Returns a pointer to the created note asset data #! #! Stack: [created_note_data_ptr] #! Output: [asset_data_ptr] #! #! - created_note_data_ptr is the memory address at which the created note data begins. #! - asset_data_ptr is the memory address at which the created note asset data begins. export.get_created_note_asset_data_ptr push.CREATED_NOTE_ASSETS_OFFSET add end #! Sets the created note assets hash. #! #! Stack: [created_note_data_ptr, AH] #! Output: [] #! #! - created_note_data_ptr is the memory address at which the created note data begins. #! - AH is the assets hash of the created note. export.set_created_note_assets_hash push.CREATED_NOTE_ASSETS_HASH_OFFSET add mem_storew end