There are user-facing procedures and kernel procedures. Users don't directly invoke kernel procedures, but instead they invoke them indirectly via account code, note, or transaction scripts. In these cases, kernel procedures are invoked by a syscall instruction which always executes in the kernel context.
These procedures can be used to create smart contract/account code, note scripts, or account scripts. They basically serve as an API for the underlying kernel procedures. If a procedure can be called in the current context, an exec is sufficient. Otherwise the context procedures must be invoked by call. Users never need to invoke syscall procedures themselves.
Tip
If capitalized, a variable representing a word, e.g., ACCT_HASH consists of four felts. If lowercase, the variable is represented by a single felt.
To import the account procedures, set use.miden::account at the beginning of the file.
Any procedure that changes the account state must be invoked in the account context and not by note or transaction scripts. All procedures invoke syscall to the kernel API and some are restricted by the kernel procedure exec.authenticate_account_origin, which fails if the parent context is not the executing account.
Procedure name
Stack
Output
Context
Description
get_id
[]
[acct_id]
account, note
Returns the account id.
get_nonce
[]
[nonce]
account, note
Returns the account nonce.
get_initial_hash
[]
[H]
account, note
Returns the initial account hash.
get_current_hash
[]
[ACCT_HASH]
account, note
Computes and returns the account hash from account data stored in memory.
incr_nonce
[value]
[]
account
Increments the account nonce by the provided value which can be at most 2^32 - 1 otherwise the procedure panics.
get_item
[index]
[VALUE]
account, note
Gets an item VALUE by index from the account storage.
Panics if the index is out of bounds.
set_item
[index, V']
[R', V]
account
Sets an index/value pair in the account storage.
Panics if the index is out of bounds. R is the new storage commitment.
set_code
[CODE_COMMITMENT]
[]
account
Sets the code (CODE_COMMITMENT) of the account the transaction is being executed against.
This procedure can only be executed on regular accounts with updatable code. Otherwise, the procedure fails.
get_balance
[faucet_id]
[balance]
account, note
Returns the balance of a fungible asset associated with a faucet_id.
Panics if the asset is not a fungible asset.
has_non_fungible_asset
[ASSET]
[has_asset]
account, note
Returns a boolean has_asset indicating whether the non-fungible asset is present in the vault.
Panics if the ASSET is a fungible asset.
add_asset
[ASSET]
[ASSET']
account
Adds the specified asset ASSET to the vault. Panics under various conditions.
If ASSET is a non-fungible asset, then ASSET' is the same as ASSET.
If ASSET is a fungible asset, then ASSET' is the total fungible asset in the account vault after ASSET was added to it.
To import the transaction procedures set use.miden::tx at the beginning of the file. Only the create_note procedure is restricted to the account context.
Procedure name
Inputs
Outputs
Context
Description
get_block_number
[]
[num]
account, note
Returns the block number num of the last known block at the time of transaction execution.
get_block_hash
[]
[H]
account, note
Returns the block hash H of the last known block at the time of transaction execution.
get_input_notes_commitment
[]
[COM]
account, note
Returns the input notes hash COM.
This is computed as a sequential hash of (nullifier, empty_word_or_note_hash) tuples over all input notes. The empty_word_or_notes_hash functions as a flag, if the value is set to zero, then the notes are authenticated by the transaction kernel. If the value is non-zero, then note authentication will be delayed to the batch/block kernel. The delayed authentication allows a transaction to consume a public note that is not yet included to a block.
get_output_notes_commitment
[0, 0, 0, 0]
[COM]
account, note
Returns the output notes hash COM.
This is computed as a sequential hash of (note_id, note_metadata) tuples over all output notes.
create_note
[ASSET, tag, RECIPIENT]
[ptr]
account
Creates a new note and returns a pointer to the memory address at which the note is stored.
ASSET is the asset to be included in the note.
tag is the tag to be included in the note. RECIPIENT is the recipient of the note.
ptr is the pointer to the memory address at which the note is stored.