miden-protocol 0.14.3

Core components of the Miden protocol
Documentation
use miden::protocol::kernel_proc_offsets::INPUT_NOTE_GET_ASSETS_INFO_OFFSET
use miden::protocol::kernel_proc_offsets::INPUT_NOTE_GET_RECIPIENT_OFFSET
use miden::protocol::kernel_proc_offsets::INPUT_NOTE_GET_METADATA_OFFSET
use miden::protocol::kernel_proc_offsets::INPUT_NOTE_GET_STORAGE_INFO_OFFSET
use miden::protocol::kernel_proc_offsets::INPUT_NOTE_GET_SCRIPT_ROOT_OFFSET
use miden::protocol::kernel_proc_offsets::INPUT_NOTE_GET_SERIAL_NUMBER_OFFSET
use miden::protocol::note

# PROCEDURES
# =================================================================================================

#! Returns the information about assets in the input note with the specified index.
#!
#! This information can then be used to retrieve the actual assets from the advice map.
#!
#! Inputs:  [note_index]
#! Outputs: [ASSETS_COMMITMENT, num_assets]
#!
#! Where:
#! - note_index is the index of the input note whose assets info should be returned.
#! - num_assets is the number of assets in the specified note.
#! - ASSETS_COMMITMENT is a sequential hash of the assets in the specified note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_assets_info
    # start padding the stack
    push.0 swap
    # => [note_index, 0]

    # push the flag indicating that we want to request assets info from the note with the specified
    # index
    push.0
    # => [is_active_note = 0, note_index, 0]

    push.INPUT_NOTE_GET_ASSETS_INFO_OFFSET
    # => [offset, is_active_note = 0, note_index, 0]

    # pad the stack
    padw swapw padw padw swapdw
    # => [offset, 0, note_index, pad(13)]

    syscall.exec_kernel_proc
    # => [ASSETS_COMMITMENT, num_assets, pad(11)]

    # clean the stack
    swapdw dropw dropw
    repeat.3
        movup.5 drop
    end
    # => [ASSETS_COMMITMENT, num_assets]
end

#! Writes the assets of the input note with the specified index into memory starting at the
#! specified address.
#!
#! Attention: memory starting from the `dest_ptr` should have enough space to store all the assets
#! in the specified note. Make sure that at least `4 * num_assets` memory elements are available,
#! or if the number of assets is not yet known, at least `4 * MAX_ASSETS_PER_NOTE`.
#!
#! The memory layout after the execution of this procedure will look like so:
#! [ASSET_0, ASSET_1, ..., ASSET_N], where each asset occupies one word. For more detailed
#! information about the layout of each asset see the description of the `Asset` Rust type.
#!
#! Inputs:  [dest_ptr, note_index]
#! Outputs: [num_assets, dest_ptr, note_index]
#!
#! Where:
#! - dest_ptr is the memory address to write the assets.
#! - note_index is the index of the input note whose assets info should be returned.
#! - num_assets is the number of assets in the specified note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_assets
    # get the assets commitment and assets number
    dup.1 exec.get_assets_info
    # => [ASSETS_COMMITMENT, num_assets, dest_ptr, note_index]

    # write the assets stored in the advice map to the specified memory pointer
    exec.note::write_assets_to_memory
    # => [num_assets, dest_ptr, note_index]
end

#! Returns the recipient of the input note with the specified index.
#!
#! Inputs:  [note_index]
#! Outputs: [RECIPIENT]
#!
#! Where:
#! - note_index is the index of the input note whose recipient should be returned.
#! - RECIPIENT is the commitment to the input note's script, storage, the serial number.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_recipient
    # start padding the stack
    push.0 swap
    # => [note_index, 0]

    # push the flag indicating that we want to request assets info from the note with the specified
    # index
    push.0
    # => [is_active_note = 0, note_index, 0]

    push.INPUT_NOTE_GET_RECIPIENT_OFFSET
    # => [offset, is_active_note = 0, note_index, 0]

    # pad the stack
    padw swapw padw padw swapdw
    # => [offset, note_index, pad(14)]

    syscall.exec_kernel_proc
    # => [RECIPIENT, pad(12)]

    # clean the stack
    swapdw dropw dropw swapw dropw
    # => [RECIPIENT]
end

#! Returns the metadata of the input note with the specified index.
#!
#! Inputs:  [note_index]
#! Outputs: [NOTE_ATTACHMENT, METADATA_HEADER]
#!
#! Where:
#! - note_index is the index of the input note whose metadata should be returned.
#! - METADATA_HEADER is the metadata header of the specified input note.
#! - NOTE_ATTACHMENT is the attachment of the specified input note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_metadata
    # start padding the stack
    push.0 swap
    # => [note_index, 0]

    # push the flag indicating that we want to request metadata from the note with the specified
    # index
    push.0
    # => [is_active_note = 0, note_index, 0]

    push.INPUT_NOTE_GET_METADATA_OFFSET
    # => [offset, is_active_note = 0, note_index, 0]

    # pad the stack
    padw swapw padw padw swapdw
    # => [offset, is_active_note = 0, note_index, pad(13)]

    syscall.exec_kernel_proc
    # => [NOTE_ATTACHMENT, METADATA_HEADER, pad(8)]

    # clean the stack
    swapdw dropw dropw
    # => [NOTE_ATTACHMENT, METADATA_HEADER]
end

#! Returns the sender of the input note with the specified index.
#!
#! Inputs:  [note_index]
#! Outputs: [sender_id_suffix, sender_id_prefix]
#!
#! Where:
#! - note_index is the index of the input note whose sender should be returned.
#! - sender_{suffix,prefix} are the suffix and prefix felts of the specified note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_sender
    # get metadata and drop attachment
    exec.get_metadata dropw
    # => [METADATA_HEADER]

    # extract the sender ID from the metadata header
    exec.note::extract_sender_from_metadata
    # => [sender_id_suffix, sender_id_prefix]
end

#! Returns the inputs commitment and length of the input note with the specified index.
#!
#! Inputs:  [note_index]
#! Outputs: [NOTE_STORAGE_COMMITMENT, num_storage_items]
#!
#! Where:
#! - note_index is the index of the input note whose data should be returned.
#! - NOTE_STORAGE_COMMITMENT is the inputs commitment of the specified input note.
#! - num_storage_items is the number of input values of the specified input note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_storage_info
    # start padding the stack
    push.0 swap
    # => [note_index, 0]

    # push the flag indicating that we want to request inputs info from the note with the specified
    # index
    push.0
    # => [is_active_note = 0, note_index, 0]

    push.INPUT_NOTE_GET_STORAGE_INFO_OFFSET
    # => [offset, is_active_note = 0, note_index, 0]

    # pad the stack
    padw swapw padw padw swapdw
    # => [offset, is_active_note = 0, note_index, pad(13)]

    syscall.exec_kernel_proc
    # => [NOTE_STORAGE_COMMITMENT, num_storage_items, pad(11)]

    # clean the stack
    swapdw dropw dropw
    repeat.3
        movup.5 drop
    end
    # => [NOTE_STORAGE_COMMITMENT, num_storage_items]
end

#! Returns the script root of the input note with the specified index.
#!
#! Inputs:  [note_index]
#! Outputs: [SCRIPT_ROOT]
#!
#! Where:
#! - note_index is the index of the input note whose script root should be returned.
#! - SCRIPT_ROOT is the script root of the specified input note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_script_root
    # start padding the stack
    push.0 swap
    # => [note_index, 0]

    # push the flag indicating that we want to request script root from the note with the specified
    # index
    push.0
    # => [is_active_note = 0, note_index, 0]

    push.INPUT_NOTE_GET_SCRIPT_ROOT_OFFSET
    # => [offset, is_active_note = 0, note_index, 0]

    # pad the stack
    padw swapw padw padw swapdw
    # => [offset, is_active_note = 0, note_index, pad(13)]

    syscall.exec_kernel_proc
    # => [SCRIPT_ROOT, pad(12)]

    # clean the stack
    swapdw dropw dropw swapw dropw
    # => [SCRIPT_ROOT]
end

#! Returns the serial number of the input note with the specified index.
#!
#! Inputs:  [note_index]
#! Outputs: [SERIAL_NUMBER]
#!
#! Where:
#! - note_index is the index of the input note whose serial number should be returned.
#! - SERIAL_NUMBER is the serial number of the specified input note.
#!
#! Panics if:
#! - the note index is greater or equal to the total number of input notes.
#!
#! Invocation: exec
pub proc get_serial_number
    # start padding the stack
    push.0 swap
    # => [note_index, 0]

    # push the flag indicating that we want to request serial number from the note with the
    # specified index
    push.0
    # => [is_active_note = 0, note_index, 0]

    push.INPUT_NOTE_GET_SERIAL_NUMBER_OFFSET
    # => [offset, is_active_note = 0, note_index, 0]

    # pad the stack
    padw swapw padw padw swapdw
    # => [offset, is_active_note = 0, note_index, pad(13)]

    syscall.exec_kernel_proc
    # => [SERIAL_NUMBER, pad(12)]

    # clean the stack
    swapdw dropw dropw swapw dropw
    # => [SERIAL_NUMBER]
end