Skip to main content
Version: Next (unstable)

Notes

A Note is the medium through which Accounts communicate. A Note holds assets and defines how they can be consumed.

What is the purpose of a note?​

In Miden's hybrid UTXO and account-based model notes represent UTXO's which enable parallel transaction execution and privacy through asynchronous local Note production and consumption.

Notes serve two purposes:

  • Transferring assets between accounts.
  • Invoking an account's public procedures: when a note is consumed, its script runs and calls into the target account's interface, acting on the data carried in the note's storage. A note cannot change an account arbitrarily; it interacts only through the procedures the account exposes.

Note core components​

A Note is composed of several core components, illustrated below:

Note diagram

These components are:

  1. Assets
  2. Script
  3. Storage
  4. Serial number
  5. Metadata

Assets​

An asset container for a Note.

A Note can contain from 0 up to 16 different assets. These assets represent fungible or non-fungible tokens, enabling flexible asset transfers.

Script​

The code executed when the Note is consumed.

Each Note has a script that defines the conditions under which it can be consumed. When accounts consume notes in transactions, Note scripts call the account's interface functions. This enables all sorts of operations beyond simple asset transfers. The Miden VM's Turing completeness allows for arbitrary logic, making Note scripts highly versatile. There is no limit to the amount of code a Note can hold.

Storage​

The storage of the Note that it can access during execution.

A Note can store up to 1024 items in its storage, which adds up to a maximum of 8 KB of data. The Note script can access storage during execution and it is used to parameterize a note's script. For instance, a P2ID note stores the ID of the target account that can consume the note. This makes the P2ID note script reusable by changing the target account ID.

Serial number​

A unique and immutable identifier for the Note.

The serial number is a random 32-byte value chosen by the note's creator. It serves two purposes:

  • Uniqueness: its randomness ensures each note is distinct even when two notes hold identical assets, scripts, and inputs, preventing collisions in the notes database.
  • Privacy: for a private note the serial number is kept secret. It is one of the inputs to the note's nullifier, which is what keeps the note's creation unlinkable from its consumption.

Metadata​

Additional public Note information.

Every note includes metadata:

  • the account ID of the sender, i.e. the creator of the note.
  • its note type, i.e. private or public.
  • the note tag that aids in discovery of the note.
  • optional note attachments (up to 4).

Regardless of note type, these metadata fields are always public.

Attachments​

A note can have up to 4 attachments. Each attachment is a variable-size, public extension to the note's metadata consisting of:

  • Content: Between 1 and 256 words of data (up to 8 KB per attachment, 16 KB total across all attachments). The content of an individual attachment is committed to via a sequential hash over its field elements. The full attachment contents are publicly stored on-chain, even for private notes.
  • Scheme: A 16-bit (limited to 65534) user-defined value that identifies the kind of attachment. This allows consumers to detect the presence of certain standardized attachments. For untyped attachments, the none = 1 scheme can be used.

The note commits to all of its attachments via a sequential hash over the individual attachment commitments (the attachments commitment). The attachment schemes are encoded in the note's metadata. When the note is consumed, the actual attachment content is provided via the advice provider.

Sealing a note means invoking the asset callbacks of the faucets whose assets it holds. Each callback can return attachments, which the kernel appends to the note. The note is then sealed to prevent further changes to it. These attachments count toward the same limits, so the note's creator must leave room for them.

Schemes are not required to be unique within a note, but adding multiple attachments with the same scheme is discouraged. It provides no additional benefit and only increases the note's public on-chain data and the fees its creator pays.

Example use cases for attachments are:

  • Communicate the note details of a private note in encrypted form. This means the encrypted note is attached publicly to the otherwise private note.
  • For network transactions, encode the ID of the network account that should consume the note. This is a standardized attachment scheme in miden-standards called NetworkAccountTarget.
  • Communicate the details of a private note to the receiver so they can derive the note. For example, the payback note of a partially fillable swap note can be private. The receiver knows it is a P2ID note with a serial number derived from the SWAP note's serial number and storage containing the receiver account ID. The only missing input is the exact amount filled. Encoding that amount in a public attachment lets the receiver derive the full note without a side-channel.

Encrypted asset attachments​

A faucet can attach the details of each private note that carries its asset, encrypted to the issuer's key, so that the issuer can track its asset. Its on_before_note_sealed callback calls miden::standards::attachments::encrypted_assets::new, which returns no attachment for a public note, and returns the result as an attachment list through miden::protocol::output_note::single_attachment_list. For a private note with n assets, it encrypts the plaintext (3 + 2n words, assets in note order)

[SERIAL_NUM, SCRIPT_ROOT, STORAGE_COMMITMENT, ASSET_ID_0, ASSET_VALUE_0, ..., ASSET_ID_{n-1}, ASSET_VALUE_{n-1}]

with miden::protocol::ies::ecgfp5_eidos::seal to the public key in the faucet's value slots miden::standards::attachments::encrypted_assets::issuer_key_head and issuer_key_tail, under the context [8] (the attachment scheme). The attachment has scheme 8 and holds the envelope [ephemeral_public_key(5), auth_tag(2), plaintext_len, ciphertext(2 * plaintext_len)], which is 8 + 4n words. The note cannot be sealed unless the creator puts the note's RECIPIENT preimage into the advice map and the transaction arguments carry an IesSealSeed. Each such faucet adds its own attachment. The issuer decrypts all attachments with scheme 8 and then recomputes the note's ID to compare it to the onchain note ID (since anyone can encrypt to its key). The note's nullifier can also be computed from the same data for inflow tracking.

A faucet with a TokenPolicyManager builds the attachment with the send policy SendPolicy::with_encrypted_assets(issuer_key), which installs the key with the EncryptedAssetsIssuerKey account component. The policy rejects a private note that holds more than one asset, since the attachment would show the assets of other faucets to the issuer. The faucet's authority rotates the key with that component's set_issuer_key; notes sealed before a rotation stay encrypted to the previous key, so the issuer keeps its previous secret keys and tries each of them. A custom send policy can compose this policy together with other checks, such as a blocklist, and ships the key component as well. The notes the faucet creates itself, e.g. the notes it mints, get no attachment, so the policy should only be used on a faucet whose mint policy lets only the issuer mint, such as MintPolicy::owner_only. A network faucet can thus mint the private output note of a MINT note, which holds only its recipient digest. Another account cannot create a private note holding the asset if it knows only the note's recipient digest, e.g. the filler of a SWAP note that requests the asset cannot create a private payback note.

Note Lifecycle​

Note lifecycle

The Note lifecycle proceeds through four primary phases: creation, validation, discovery, and consumption. Creation and consumption requires two separate transactions. Throughout this process, notes function as secure, privacy-preserving vehicles for asset transfers and logic execution.

Note creation​

Accounts can create notes in a transaction. The Note exists if it is included in the global notes DB.

  • Users: Executing local or network transactions.
  • Miden node infrastructure: Facilitating on-chain actions, e.g. such as executing user notes against a DEX or other contracts.

Note Type​

As with accounts, notes can be stored either publicly or privately:

  • Public mode: The Note data is stored in the note database, making it fully visible on-chain.
  • Private mode: Only the Note's hash is stored publicly. The Note's actual data remains off-chain, enhancing privacy.

Note validation​

Once created, a Note must be validated by a Miden operator. Validation involves checking the transaction proof that produced the Note to ensure it meets all protocol requirements.

After validation notes become "live" and eligible for consumption. If creation and consumption happens within the same block, there is no entry in the Notes DB. All other notes, are being added either as a commitment or fully public.

Note discovery​

Clients often need to find specific notes of interest. Miden allows clients to query the Note database using Note tags. These lightweight, 32-bit data fields serve as best-effort filters, enabling quick lookups for notes related to particular use cases, scripts, or account prefixes.

While note tags can be arbitrarily constructed from 32 bits of data, there are two categories of tags that many notes fit into.

Account Targets​

A note targeted at an account is a note that is intended or even enforced to be consumed by a specific account. One example is a P2ID note that can only be consumed by a specific account ID. The tag for such a note should make it easy for the receiver to find the note. Therefore, the tag encodes a certain number of bits of the receiver account's ID, by convention. Notably, it may not encode the full 32 bits of the target account's ID to preserve the receiver's privacy. See also the section on privacy below.

The default account-target tag selects the high 14 bits of the account ID prefix. For an Eidos-generated ID, the high bit is fixed to zero, leaving 13 varying bits. A custom tag length of 32 selects at most 31 varying bits. Under pseudorandom hashing, the default therefore matches about twice as many unrelated account-targeted notes as a filter with 14 varying bits. The note script enforces who can consume the note; the tag only helps find it.

Use Case Tags​

Use case notes are notes that are not intended to be consumed by a specific account, but by anyone willing to fulfill the note's contract. One example is a SWAP note that trades one asset against another. Such a use case note can define the structure of their note tags. A sensible structure for a SWAP note could be:

  • encoding the 1 bit of the note's type.
  • encoding the note script root, i.e. making it identifiable as a SWAP note, for example by using 16 bits of the SWAP script root.
  • encoding the SWAP pair, for example by using 8 bits of the offered asset faucet ID and 8 bits of the requested asset faucet ID.

This allows clients to search for a public SWAP note that trades USDC against ETH only through the note tag. Since tags are not validated in any way and only act as best-effort filters, further local filtering is almost always necessary. For example, there could easily be a collision on the 8 bits used in SWAP tag's faucet IDs.

Privacy vs Efficiency​

Using Note tags strikes a balance between privacy and efficiency. Without tags, querying a specific Note ID reveals a user's interest to the operator. Conversely, downloading and filtering all registered notes locally is highly inefficient. Tags allow users to adjust their level of privacy by choosing how broadly or narrowly they define their search criteria, letting them find the right balance between revealing too much information and incurring excessive computational overhead.

Note consumption​

To consume a Note, the consumer must know its data, including the note's storage which is needed to compute the nullifier. Consumption occurs as part of a transaction. Upon successful consumption a nullifier is generated for the consumed notes.

Upon successful verification of the transaction:

  1. The Miden operator records the Note's nullifier as "consumed" in the nullifier database.
  2. The Note's one-time claim is thus extinguished, preventing reuse.

Note recipient restricting consumption​

Every Note has a RECIPIENT, represented as 32 bytes, that commits to the data defining the conditions under which the note can be consumed. The RECIPIENT is computed as:

hash(hash(hash(serial_num, [0; 4]), script_root), storage_commitment)

The RECIPIENT is not necessarily just an account address. Its pre-image consists of the note's serial number, script, and storage. The consumer of the note must provide this data so the transaction prologue can recompute the RECIPIENT and verify that it matches the committed note details.

The note script and storage determine the actual consumption conditions. For example, the P2ID and P2IDE note scripts specify the target account ID as part of the note's storage. In a SWAP note, consumption is only possible if the consumer provides the asset expected in return for the asset being offered. For private notes, keeping the RECIPIENT pre-image private ensures that only parties with the required note data can attempt to consume the note.

Declaring who may consume a note​

A note script either restricts consumption to accounts the note commits to, or is open to any consumer by design. Nothing in a script's body distinguishes the second case from a restriction that was simply left out, so every standard note script states its rule on a Consumers: line in the doc comment of its @note_script procedure.

A note commits to the accounts allowed to consume it in one of two ways:

  • as a NetworkAccountTarget attachment, which the config notes and the agglayer note scripts use.
  • as an account ID in the note's storage, which P2ID and P2IDE use. MINT and BURN commit their faucet the same way, as part of the asset held in their storage.

Both are enforced through the shared miden::standards::note::note_target procedures. A note that lets its creator take its assets back enforces that separately, through miden::standards::note::note_reclaim, which checks the reclaimer alongside the block height from which reclaim is allowed.

A note that is open to any consumer states so explicitly, e.g. a SWAP note is filled by whoever provides the requested asset. Some notes' consumption rules are enforced by the account procedure they invoke, e.g. a MINT note is rejected by the faucet it is not addressed to.

Note nullifier ensuring private consumption​

Nullifier synchronization uses the high 16 bits of the nullifier's last field element as a filter. Eidos fixes the high bit to zero, leaving 15 varying bits and prefixes in 0x0000..=0x7fff. Expected bucket populations are therefore about twice those of a filter with 16 varying bits. Synchronization still matches full nullifiers after filtering.

The Note nullifier, computed as:

hash(SERIAL_NUM, SCRIPT_ROOT, STORAGE_COMMITMENT, ASSET_COMMITMENT, METADATA, ATTACHMENTS_COMMITMENT)

Where:

  • SERIAL_NUM is the note's serial number.
  • SCRIPT_ROOT is the commitment to the note's script, i.e. the script's MAST root.
  • STORAGE_COMMITMENT is a commitment to the note's storage.
  • ASSET_COMMITMENT is a commitment to the note's assets.
  • METADATA is the note's public metadata (sender, note type, and tag).
  • ATTACHMENTS_COMMITMENT is a commitment to the note's attachments.

Like the note's ID, the nullifier is a commitment to the note's data, but it is computed differently so that neither can be derived from the other. The serial number is one of its inputs, and its randomness is what makes each note's nullifier unique.

This achieves the following properties:

  • Every Note can be reduced to a single unique nullifier.
  • One cannot derive a note's ID from its nullifier.
  • To compute the nullifier, one must know all components of the Note: serial_num, script_root, storage_commitment, assets_commitment, metadata, and attachments_commitment.

For a private note, the operator stores only its ID and never sees these components, so only the parties that hold the full Note details can tell whether it has been consumed. Zcash first introduced this approach.

Nullifier diagram

Standard Note Types​

The miden::standards library provides several standard note scripts that implement common use cases for asset transfers and interactions. These pre-built note types offer secure, tested implementations for typical scenarios.

Input-note assets are stateful within a transaction: a note script claims the assets remaining in the note at consumption time, which may be less than the note was created with. Logic that prices or validates a note based on its assets must use the note's initial assets info rather than its remaining assets.

P2ID (Pay-to-ID)​

The P2ID note script implements a simple pay-to-account-ID pattern. It adds the note's remaining assets to a specific target account.

Key characteristics:

  • Purpose: Direct asset transfer to a specific account ID
  • Storage: Requires exactly 2 storage items containing the target account ID: [target_account_id_suffix, target_account_id_prefix].
  • Validation: Ensures the consuming account's ID matches the target account ID specified in the note
  • Requirements: Target account must expose the miden::standards::wallets::basic::receive_asset procedure

Use case: Simple, direct payments where you want to send assets to a known account ID.

P2IDE (Pay-to-ID Extended)​

The P2IDE note script extends P2ID with additional features including time-locking and reclaim functionality.

Key characteristics:

  • Purpose: Advanced asset transfer with time-lock and reclaim capabilities
  • Storage: Requires exactly 6 storage items:
    • Reclaimer account ID (the account allowed to reclaim the note; 2 felts)
    • Target account ID (2 felts)
    • Reclaim block height (when the reclaimer can reclaim)
    • Time-lock block height (when target can consume)
  • Time-lock: Note cannot be consumed until the specified block height is reached
  • Reclaim: The note's reclaimer (stored in note storage, defaulting to the sender) can reclaim the note after the reclaim block height if not consumed by target
  • Validation: Complex logic to handle both target consumption and reclaimer reclaim scenarios
  • Requirements: Account must expose the miden::standards::wallets::basic::receive_asset procedure

Use cases:

  • Escrow-like payments with time constraints
  • Conditional payments that can be reclaimed if not consumed
  • Time-delayed transfers

TX_FEE​

The TX_FEE note script is the canonical way for a transaction to pay its fee to a batch builder. It leaves the note's assets in place for the consuming account to collect, without restricting who that account is.

Key characteristics:

  • Purpose: Fee payment to a batch builder
  • Storage: Carries no storage items
  • Note type: Always public
  • Assets: Carries one or more assets chosen by the sender to pay the fee
  • Tag: The unique 0xFEE tag. Its 18 least significant bits are non-zero, so it can never collide with a default account-target tag (those have their 18 least significant bits set to zero)
  • Validation: Any account may consume the note. The fee gives the batch builder an incentive to include and consume it
  • Requirements: The note script does not move the assets, so the consuming account's own code must remove them from the note. Only the account context can do this, via miden::protocol::input_note::remove_asset or remove_all_assets. A transaction that leaves any of the note's assets uncollected fails the kernel's asset conservation check

Use case: Paying transaction fees to whichever account builds the batch, in any asset the batch builder accepts.

FEE_SPONSORSHIP​

The FEE_SPONSORSHIP note script prepays the fee a network account charges for consuming one specific note, so that note stays fee-unaware. See the fee documentation.

Key characteristics:

  • Purpose: Prepaying a network account's fee for a single note
  • Storage: Requires exactly 7 storage items:
    • ID of the sponsored note (4 felts)
    • Reclaimer account ID (2 felts)
    • Reclaim block height (0 disables reclaim)
  • Note type: Always public
  • Assets: Exactly one asset, carrying the fee charged by the target account
  • Tag: Routes to the target network account
  • Validation: If the sponsored note is among the transaction's input notes, the script does nothing, leaving the assets for the consuming account to collect. Otherwise only the reclaimer can consume the note once the reclaim block height is reached. A zero height disables reclaim entirely
  • Requirements: Collection requires an account whose authentication procedure collects sponsored fees; reclaiming requires the miden::standards::wallets::basic::receive_asset procedure

Use case: Paying a network account up front so it will consume a note that carries no fee of its own.

SWAP​

The SWAP note script implements atomic asset swapping functionality.

Key characteristics:

  • Purpose: Atomic asset exchange between two parties
  • Storage: The requested asset and the payback note configuration: recipient, note type, tag and attachments. The layout is defined by SwapNoteStorage.
  • Assets: Must contain exactly 1 asset to be swapped
  • Mechanism:
    1. Creates a payback note that contains the requested asset. By default, it is a P2ID note for the original note issuer, but the creator can select any recipient. For a private payback, the script uses the precomputed recipient digest from storage. For a public payback, the script builds the recipient from the script root, serial number and storage embedded in the SWAP storage. This also registers the preimage in the advice map, so the consumer needs no additional advice. In both modes, the script adds the attachments from storage to the payback note. The payback note is sealed once it holds the requested asset and its attachments.
    2. Adds the note's asset to the consuming account's vault
  • Requirements: Account must expose both:
    • miden::standards::wallets::basic::receive_asset procedure
    • miden::standards::wallets::basic::move_asset_to_note procedure

Use case: Decentralized asset trading where two parties want to exchange different assets atomically.

Choosing the Right Note Type​

  • Use P2ID for simple, direct payments to known accounts
  • Use P2IDE when you need time-locks, escrow functionality, or reclaim capabilities
  • Use SWAP for atomic asset exchanges between parties
  • Create custom scripts for specialized use cases not covered by standard types

These standard note types provide a foundation for common operations while maintaining the flexibility to create custom note scripts for specialized requirements.