miden-protocol 0.14.5

Core components of the Miden protocol
Documentation
use $kernel::memory

# ERRORS
# =================================================================================================

const ERR_INPUT_NOTE_INDEX_OUT_OF_BOUNDS="requested input note index should be less than the total number of input notes"

# INPUT NOTE PROCEDURES
# =================================================================================================

#! Returns the information about assets in the input note with the specified memory pointer.
#!
#! Inputs:  [input_note_ptr]
#! Outputs: [ASSETS_COMMITMENT, num_assets]
#!
#! Where:
#! - input_note_ptr is the memory address of the data segment for the requested input note.
#! - num_assets is the number of assets in the specified note.
#! - ASSETS_COMMITMENT is a sequential hash of the assets in the specified note.
pub proc get_assets_info
    # get the number of assets in the note
    dup exec.memory::get_input_note_num_assets
    # => [num_assets, input_note_ptr]

    # get the assets commitment from the note pointer
    swap exec.memory::get_input_note_assets_commitment
    # => [ASSETS_COMMITMENT, num_assets]
end

#! Assert that the provided note index is less than the total number of input notes.
#!
#! Inputs:  [note_index]
#! Outputs: [note_index]
pub proc assert_note_index_in_bounds
    # assert that the provided note index is less than the total number of notes
    dup exec.memory::get_num_input_notes 
    # => [input_notes_num, note_index, note_index]
    
    u32assert2.err=ERR_INPUT_NOTE_INDEX_OUT_OF_BOUNDS
    u32lt assert.err=ERR_INPUT_NOTE_INDEX_OUT_OF_BOUNDS
    # => [note_index]
end

#! Computes a pointer to the memory address at which the data associated with an input note with
#! index `idx` is stored.
#!
#! Inputs:  [idx]
#! Outputs: [note_ptr]
#!
#! Where:
#! - idx is the index of the input note.
#! - note_ptr is the memory address of the data segment for the input note with `idx`.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
pub proc get_input_note_ptr
    # asset that the provided input note index is valid
    exec.assert_note_index_in_bounds
    # => [idx]

    # get the memory pointer to the specified input note
    exec.memory::get_input_note_ptr
    # => [note_ptr]
end