Skip to main content
Version: 0.13

Cheatsheet

This is a quick-reference cheatsheet. The SDK functions below are wrappers around Miden's transaction kernel procedures — they execute locally during proof generation, not on-chain. For full API documentation with examples, see miden on docs.rs.

Quick-reference for the Miden Rust SDK — every function signature, type, trait, and macro at a glance. Each section links to the detailed page for full explanations and examples. The SDK exposes the Miden transaction kernel's host functions — all execution happens locally on the client during proof generation, not on-chain. For runnable examples, see the compiler examples directory.

Core imports

use miden::{
// Macros
component, note, note_script, tx_script, export_type, felt,

// Types
Felt, Word, Asset, AccountId, NoteIdx, Tag, NoteType, Recipient, Digest,

// Storage
Value, StorageMap, ValueAccess, StorageMapAccess,

// Modules
active_account, native_account, active_note, output_note, input_note, tx,
asset, faucet, storage,

// Crypto
hash_words, rpo_falcon512_verify,

// Allocator
BumpAlloc,
};

Macros → Components, Notes, Transaction Context, Custom Types, Cross-Component Calls

#[component]

Defines an account component. Apply to both struct and impl block.

#[component]
struct MyAccount { /* storage fields */ }

#[component]
impl MyAccount { /* public and private methods */ }

#[note]

Defines a note script. Apply to both struct and impl block.

#[note]
struct MyNote { /* fields from note inputs */ }

#[note]
impl MyNote { /* must contain a #[note_script] method */ }

#[note_script]

Marks the entry point method of a note script. Must be inside a #[note] impl block.

Constraints: self by value, returns (), one Word arg, optional &Account/&mut Account.

#[tx_script]

Marks a function as a transaction script entry point.

#[tx_script]
fn my_script(arg: Word) { ... }

#[export_type]

Exports a custom type for use in public component method signatures.

#[export_type]
pub struct MyType { pub field: Felt }

felt!(n)

Creates a Felt from an integer literal at compile time. Limited to values ≤ u32::MAX.

let f = felt!(42);

miden::generate!()

Generates WIT bindings for cross-component calls. Creates a bindings module.

miden::generate!();
bindings::export!(MyNote);

Types → Types

Felt

Field element over the Goldilocks prime (p=264232+1p = 2^{64} - 2^{32} + 1).

MethodSignatureDescription
from_u32fn(value: u32) -> SelfCreate from u32 (always safe)
from_u64_uncheckedfn(value: u64) -> SelfCreate from u64 (caller ensures < p)
newfn(value: u64) -> Result<Self, FeltError>Create with validation
as_u64fn(self) -> u64Get canonical u64 representation
is_oddfn(self) -> boolCheck parity
invfn(self) -> SelfMultiplicative inverse (panics if 0)
expfn(self, other: Self) -> SelfExponentiation: self^other mod p
pow2fn(self) -> SelfCompute 2^self (panics if > 63)

Operators: Add, Sub, Mul, Div, Neg, AddAssign, SubAssign, MulAssign, DivAssign, Eq, Ord

Word

Four-element tuple: (Felt, Felt, Felt, Felt). Repr: #[repr(C, align(16))].

MethodSignatureDescription
newfn(word: [Felt; 4]) -> SelfCreate from array
from_u64_uncheckedfn(a: u64, b: u64, c: u64, d: u64) -> SelfCreate from 4 u64 values
reversefn(&self) -> WordReverse element order

Indexing: word[0] through word[3]. Supports Index<usize> and IndexMut<usize>.

Conversions: From<[Felt; 4]>, From<(Felt, Felt, Felt, Felt)>, From<Felt>, Into<[Felt; 4]>, Into<Felt>

Asset

Wraps a Word. Field: inner: Word.

MethodSignatureDescription
newfn(word: impl Into<Word>) -> SelfCreate from Word
as_wordfn(&self) -> &WordBorrow as Word

Fungible encoding: [amount, 0, faucet_suffix, faucet_prefix] Non-fungible encoding: [hash0, hash1, hash2, faucet_prefix]

AccountId

Fields: prefix: Felt, suffix: Felt.

MethodSignatureDescription
newfn(prefix: Felt, suffix: Felt) -> SelfCreate from prefix/suffix

Recipient

Field: inner: Word.

MethodSignatureDescription
computefn(serial_num: Word, script_digest: Digest, inputs: Vec<Felt>) -> SelfCompute from components

Digest

Field: inner: Word.

MethodSignatureDescription
newfn(felts: [Felt; 4]) -> SelfCreate from array
from_wordconst fn(word: Word) -> SelfCreate from Word

Other types

TypeInnerDescription
NoteIdxFeltOutput note index
TagFeltNote routing tag
NoteTypeFeltNote visibility
StorageSlotIdprefix: Felt, suffix: FeltStorage slot identifier

Traits → Storage, Components

ValueAccess<V>

pub trait ValueAccess<V> {
fn read(&self) -> V;
fn write(&mut self, value: V) -> V; // Returns previous value
}

Implemented by Value for any V: Into<Word> + From<Word>.

StorageMapAccess<K, V>

pub trait StorageMapAccess<K, V> {
fn get(&self, key: &K) -> V;
fn set(&mut self, key: K, value: V) -> V; // Returns previous value
}

Implemented by StorageMap for K: Into<Word> + AsRef<Word>, V: From<Word> + Into<Word>.

ActiveAccount

Auto-implemented on #[component] structs. Provides read-only account queries on &self.

NativeAccount

Auto-implemented on #[component] structs. Provides account mutations on &mut self.


active_account module → Account Operations

Read-only account state queries.

FunctionSignatureDescription
get_idfn() -> AccountIdAccount ID
get_noncefn() -> FeltCurrent nonce
get_balancefn(faucet_id: AccountId) -> FeltFungible balance for faucet
get_initial_balancefn(faucet_id: AccountId) -> FeltBalance at tx start
has_non_fungible_assetfn(asset: Asset) -> boolCheck NFT ownership
get_initial_commitmentfn() -> WordAccount commitment at tx start
compute_commitmentfn() -> WordCurrent account commitment
get_code_commitmentfn() -> WordCode commitment
get_initial_storage_commitmentfn() -> WordStorage commitment at tx start
compute_storage_commitmentfn() -> WordCurrent storage commitment
get_initial_vault_rootfn() -> WordVault root at tx start
get_vault_rootfn() -> WordCurrent vault root
get_num_proceduresfn() -> FeltNumber of exported procedures
get_procedure_rootfn(index: u8) -> WordProcedure root at index
has_procedurefn(proc_root: Word) -> boolCheck procedure existence

native_account module → Account Operations

Account state mutations (write operations).

FunctionSignatureDescription
add_assetfn(asset: Asset) -> AssetAdd asset to vault
remove_assetfn(asset: Asset) -> AssetRemove asset from vault
incr_noncefn() -> FeltIncrement nonce, return new value
compute_delta_commitmentfn() -> WordCommitment of state changes
was_procedure_calledfn(proc_root: Word) -> boolCheck if procedure was called

storage module → Storage

Direct storage access (lower-level than Value/StorageMap traits).

FunctionSignatureDescription
get_itemfn(slot_id: StorageSlotId) -> WordGet slot value
get_initial_itemfn(slot_id: StorageSlotId) -> WordValue at tx start
set_itemfn(slot_id: StorageSlotId, value: Word) -> WordSet slot, return old
get_map_itemfn(slot_id: StorageSlotId, key: &Word) -> WordGet map value
get_initial_map_itemfn(slot_id: StorageSlotId, key: &Word) -> WordMap value at tx start
set_map_itemfn(slot_id: StorageSlotId, key: Word, value: Word) -> WordSet map value, return old

active_note module → Notes

Access the currently executing note's data.

FunctionSignatureDescription
get_inputsfn() -> Vec<Felt>Note input values
get_assetsfn() -> Vec<Asset>Note assets
get_senderfn() -> AccountIdNote sender
get_recipientfn() -> RecipientNote recipient hash
get_script_rootfn() -> WordNote script root
get_serial_numberfn() -> WordNote serial number
get_metadatafn() -> NoteMetadataNote metadata (attachment + header)

output_note module → Notes

Create and manage output notes.

FunctionSignatureDescription
createfn(tag: Tag, note_type: NoteType, recipient: Recipient) -> NoteIdxCreate a new output note
add_assetfn(asset: Asset, note_idx: NoteIdx)Add asset to output note
get_assets_infofn(note_idx: NoteIdx) -> OutputNoteAssetsInfoAssets commitment and count
get_assetsfn(note_idx: NoteIdx) -> Vec<Asset>All assets on note
get_recipientfn(note_idx: NoteIdx) -> RecipientNote recipient
get_metadatafn(note_idx: NoteIdx) -> NoteMetadataNote metadata (attachment + header)
set_attachmentfn(note_idx: NoteIdx, scheme: Felt, kind: Felt, data: Word)Set attachment with explicit kind
set_word_attachmentfn(note_idx: NoteIdx, scheme: Felt, data: Word)Set Word attachment
set_array_attachmentfn(note_idx: NoteIdx, scheme: Felt, data: Word)Set array attachment (commitment)

input_note module → Notes

Access specific input notes by index.

FunctionSignatureDescription
get_assets_infofn(note_idx: NoteIdx) -> InputNoteAssetsInfoAssets commitment and count
get_assetsfn(note_idx: NoteIdx) -> Vec<Asset>All assets on note
get_recipientfn(note_idx: NoteIdx) -> RecipientNote recipient
get_metadatafn(note_idx: NoteIdx) -> NoteMetadataNote metadata (attachment + header)
get_senderfn(note_idx: NoteIdx) -> AccountIdNote sender
get_inputs_infofn(note_idx: NoteIdx) -> InputNoteInputsInfoInputs commitment and count
get_script_rootfn(note_idx: NoteIdx) -> WordNote script root
get_serial_numberfn(note_idx: NoteIdx) -> WordNote serial number

tx module → Transaction Context

Transaction context queries.

FunctionSignatureDescription
get_block_numberfn() -> FeltCurrent block number
get_block_commitmentfn() -> WordBlock header commitment
get_block_timestampfn() -> FeltBlock timestamp (seconds)
get_input_notes_commitmentfn() -> WordHash of all input notes
get_output_notes_commitmentfn() -> WordHash of all output notes
get_num_input_notesfn() -> FeltNumber of input notes
get_num_output_notesfn() -> FeltNumber of output notes
get_expiration_block_deltafn() -> FeltExpiration delta
update_expiration_block_deltafn(delta: Felt)Set expiration delta

asset module

Asset construction.

FunctionSignatureDescription
build_fungible_assetfn(faucet_id: AccountId, amount: Felt) -> AssetCreate fungible asset
build_non_fungible_assetfn(faucet_id: AccountId, data_hash: Word) -> AssetCreate non-fungible asset

faucet module

Faucet operations (for faucet account types only).

FunctionSignatureDescription
create_fungible_assetfn(amount: Felt) -> AssetCreate asset from this faucet
create_non_fungible_assetfn(data_hash: Word) -> AssetCreate NFT from this faucet
mintfn(asset: Asset) -> AssetMint asset
burnfn(asset: Asset) -> AssetBurn asset
get_total_issuancefn() -> FeltTotal minted supply
is_non_fungible_asset_issuedfn(asset: Asset) -> boolCheck if NFT issued

Cryptography → Cryptography

Hash functions

use miden::{hash_words, blake3_hash, sha256_hash};
use miden::intrinsics::advice::adv_push_mapvaln;
FunctionSignatureDescription
hash_wordsfn(words: &[Word]) -> DigestRPO256 hash of Words
intrinsics::crypto::mergefn(digests: [Digest; 2]) -> DigestRPO 2-to-1 merge
blake3_hashfn(input: [u8; 32]) -> [u8; 32]BLAKE3 hash
blake3_mergefn(input: [u8; 64]) -> [u8; 32]BLAKE3 2-to-1 hash
sha256_hashfn(input: [u8; 32]) -> [u8; 32]SHA256 hash
sha256_mergefn(input: [u8; 64]) -> [u8; 32]SHA256 2-to-1 hash

Digital signatures

FunctionSignatureDescription
rpo_falcon512_verifyfn(pk: Word, msg: Word)Verify Falcon512 signature (panics if invalid)

Advice provider

use miden::intrinsics::advice::{adv_insert, emit_falcon_sig_to_stack, adv_push_mapvaln};
FunctionSignatureDescription
adv_insertfn(key: Word, values: &[Word])Insert into advice map
adv_push_mapvalnfn(key: Word) -> FeltPush advice map values to stack
emit_falcon_sig_to_stackfn(msg: Word, pub_key: Word)Request Falcon signature

Assertion functions

use miden::{assert, assertz, assert_eq};
FunctionSignatureDescription
assertfn(a: Felt)Fails if a != 1
assertzfn(a: Felt)Fails if a != 0
assert_eqfn(a: Felt, b: Felt)Fails if a != b

Allocator

use miden::BumpAlloc;

#[global_allocator]
static ALLOC: BumpAlloc = BumpAlloc::new();
MethodSignatureDescription
newconst fn() -> SelfCreate allocator
allocunsafe fn(&self, layout: Layout) -> *mut u8Allocate (bump pointer)
deallocunsafe fn(&self, ptr: *mut u8, layout: Layout)No-op (memory not reclaimed)

Properties: 16-byte minimum alignment, Wasm page size (64KB), grows until exhausted.


Debug

use miden::intrinsics::debug::breakpoint;
FunctionSignatureDescription
breakpointfn()Set VM breakpoint at call site

Supported account types

Configure in Cargo.toml under [package.metadata.miden]:

TypeDescription
RegularAccountUpdatableCodeStandard account with updatable code
RegularAccountImmutableCodeAccount with fixed code
FungibleFaucetToken minting faucet
NonFungibleFaucetNFT minting faucet