Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [BREAKING] Changed `NoteType` encoding from 2 bits to 1 and makes `NoteType::Private` the default ([#2691](https://github.com/0xMiden/miden-base/issues/2691)).
- Added `BlockNumber::saturating_sub()` ([#2660](https://github.com/0xMiden/protocol/issues/2660)).
- [BREAKING] Added cycle counts to notes returned by `NoteConsumptionInfo` and removed public fields from related types ([#2772](https://github.com/0xMiden/miden-base/issues/2772)).
- [BREAKING] Removed unused `payback_attachment` from `SwapNoteStorage` and `attachment` from `MintNoteStorage` ([#2789](https://github.com/0xMiden/protocol/pull/2789)).

## 0.14.3 (2026-04-07)

Expand Down
87 changes: 33 additions & 54 deletions crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use miden::core::word
use miden::protocol::note
use miden::protocol::note::NOTE_TYPE_PUBLIC
use miden::protocol::output_note
use miden::protocol::output_note::ATTACHMENT_KIND_NONE
use miden::protocol::active_account
use miden::protocol::native_account
use miden::protocol::tx
Expand Down Expand Up @@ -60,20 +59,16 @@ const CGI_CHAIN_HASH_HI_SLOT_NAME = word("agglayer::bridge::cgi_chain_hash_hi")
const CLAIM_PROOF_DATA_WORD_LEN = 134
const CLAIM_LEAF_DATA_WORD_LEN = 8

# MINT note storage layout (public mode, 18 felts total):
# - tag [0] : 1 felt
# - amount [1] : 1 felt
# - attachment_kind [2] : 1 felt
# - attachment_scheme [3] : 1 felt
# - ATTACHMENT [4..7] : 4 felts
# - P2ID_SCRIPT_ROOT [8..11] : 4 felts
# - SERIAL_NUM [12..15] : 4 felts
# - account_id_suffix [16] : 1 felt
# - account_id_prefix [17] : 1 felt
const MINT_NOTE_NUM_STORAGE_ITEMS = 18

# P2ID attachment constants (the P2ID note created by the faucet has no attachment)
const P2ID_ATTACHMENT_SCHEME_NONE = 0
# MINT note storage layout (public mode, 14 felts total):
# - P2ID_SCRIPT_ROOT [0..3] : 4 felts
# - SERIAL_NUM [4..7] : 4 felts
# - tag [8] : 1 felt
# - amount [9] : 1 felt
# - 0 [10] : 1 felt (padding)
# - 0 [11] : 1 felt (padding)
# - account_id_suffix [12] : 1 felt
# - account_id_prefix [13] : 1 felt
const MINT_NOTE_NUM_STORAGE_ITEMS = 14

# Global memory pointers
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -135,15 +130,13 @@ const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_7 = 556

# Memory addresses for MINT note output construction
const MINT_NOTE_STORAGE_MEM_ADDR_0 = 800
const MINT_NOTE_STORAGE_DEST_TAG = 800
const MINT_NOTE_STORAGE_NATIVE_AMOUNT = 801
const MINT_NOTE_STORAGE_ATTACHMENT_KIND = 802
const MINT_NOTE_STORAGE_ATTACHMENT_SCHEME = 803
const MINT_NOTE_STORAGE_ATTACHMENT = 804
const MINT_NOTE_STORAGE_OUTPUT_SCRIPT_ROOT = 808
const MINT_NOTE_STORAGE_OUTPUT_SERIAL_NUM = 812
const MINT_NOTE_STORAGE_OUTPUT_NOTE_SUFFIX = 816
const MINT_NOTE_STORAGE_OUTPUT_NOTE_PREFIX = 817
const MINT_NOTE_STORAGE_OUTPUT_SCRIPT_ROOT = 800
const MINT_NOTE_STORAGE_OUTPUT_SERIAL_NUM = 804
const MINT_NOTE_STORAGE_DEST_TAG = 808
const MINT_NOTE_STORAGE_NATIVE_AMOUNT = 809
# padding at 810, 811
const MINT_NOTE_STORAGE_OUTPUT_NOTE_SUFFIX = 812
const MINT_NOTE_STORAGE_OUTPUT_NOTE_PREFIX = 813

# Local memory offsets
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -837,30 +830,29 @@ proc build_mint_output_note
# => []
end

#! Writes all 18 MINT note storage items to global memory.
#! Writes all 14 MINT note storage items to global memory.
#!
#! Storage layout:
#! - [0]: tag (note tag for the P2ID output note, targeting the destination account)
#! - [1]: amount (the scaled-down Miden amount to mint)
#! - [2]: attachment_kind (0 = no attachment)
#! - [3]: attachment_scheme (0 = no attachment)
#! - [4-7]: ATTACHMENT ([0, 0, 0, 0])
#! - [8-11]: P2ID_SCRIPT_ROOT (script root of the P2ID note)
#! - [12-15]: SERIAL_NUM (serial number for the P2ID note, derived from PROOF_DATA_KEY)
#! - [16]: account_id_suffix (destination account suffix)
#! - [17]: account_id_prefix (destination account prefix)
#! - [0-3]: P2ID_SCRIPT_ROOT (script root of the P2ID note)
#! - [4-7]: SERIAL_NUM (serial number for the P2ID note, derived from PROOF_DATA_KEY)
#! - [8]: tag (note tag for the P2ID output note, targeting the destination account)
#! - [9]: amount (the scaled-down Miden amount to mint)
#! - [10]: 0 (padding)
#! - [11]: 0 (padding)
#! - [12]: account_id_suffix (destination account suffix)
#! - [13]: account_id_prefix (destination account prefix)
#!
#! Inputs: [destination_id_suffix, destination_id_prefix]
#! Outputs: []
#!
#! Invocation: exec
proc write_mint_note_storage
# Write P2ID storage items first (before prefix is consumed): [16..17]
# Write destination_id_suffix [16]
# Write P2ID storage items first (before prefix is consumed): [12..13]
# Write destination_id_suffix [12]
dup mem_store.MINT_NOTE_STORAGE_OUTPUT_NOTE_SUFFIX
# => [destination_id_suffix, destination_id_prefix]

# Write destination_id_prefix [17]
# Write destination_id_prefix [13]
dup.1 mem_store.MINT_NOTE_STORAGE_OUTPUT_NOTE_PREFIX
# => [destination_id_suffix, destination_id_prefix]

Expand All @@ -878,35 +870,22 @@ proc write_mint_note_storage
exec.note_tag::create_account_target
# => [dest_tag, native_amount]

# Write tag to MINT note storage [0]
# Write tag to MINT note storage [8]
mem_store.MINT_NOTE_STORAGE_DEST_TAG
# => [native_amount]

# Write amount to MINT note storage [1]
# Write amount to MINT note storage [9]
mem_store.MINT_NOTE_STORAGE_NATIVE_AMOUNT
# => []

# Write P2ID attachment fields (the P2ID note has no attachment)
# attachment_kind = NONE [2]
push.ATTACHMENT_KIND_NONE mem_store.MINT_NOTE_STORAGE_ATTACHMENT_KIND
# => []

# attachment_scheme = NONE [3]
push.P2ID_ATTACHMENT_SCHEME_NONE mem_store.MINT_NOTE_STORAGE_ATTACHMENT_SCHEME
# => []

# ATTACHMENT = empty word [4..7]
padw mem_storew_le.MINT_NOTE_STORAGE_ATTACHMENT dropw
# => []

# Write P2ID_SCRIPT_ROOT to MINT note storage [8..11]
# Write P2ID_SCRIPT_ROOT to MINT note storage [0..3]
procref.::miden::standards::notes::p2id::main
# => [P2ID_SCRIPT_ROOT]

mem_storew_le.MINT_NOTE_STORAGE_OUTPUT_SCRIPT_ROOT dropw
# => []

# Write SERIAL_NUM (PROOF_DATA_KEY) to MINT note storage [12..15]
# Write SERIAL_NUM (PROOF_DATA_KEY) to MINT note storage [4..7]
mem_loadw_be.CLAIM_PROOF_DATA_KEY_MEM_ADDR
# => [SERIAL_NUM]

Expand Down
78 changes: 35 additions & 43 deletions crates/miden-standards/asm/standards/notes/mint.masm
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
use miden::protocol::active_note
use miden::protocol::note
use miden::protocol::output_note
use miden::standards::faucets::network_fungible->network_faucet

# CONSTANTS
# =================================================================================================

const MINT_NOTE_NUM_STORAGE_ITEMS_PRIVATE=12
const MINT_NOTE_MIN_NUM_STORAGE_ITEMS_PUBLIC=16
const MINT_NOTE_NUM_STORAGE_ITEMS_PRIVATE=6
const MINT_NOTE_MIN_NUM_STORAGE_ITEMS_PUBLIC=12

use miden::protocol::note::NOTE_TYPE_PUBLIC
use miden::protocol::note::NOTE_TYPE_PRIVATE

# Memory Addresses of MINT note storage
# The attachment is at the same memory address for both private and public storage.
const ATTACHMENT_KIND_ADDRESS=2
const ATTACHMENT_SCHEME_ADDRESS=3
const ATTACHMENT_ADDRESS=4
const OUTPUT_PUBLIC_NOTE_STORAGE_ADDR=16
# Memory addresses of MINT note storage (private mode)
const STORAGE_PTR = 0
const PRIVATE_RECIPIENT_PTR = STORAGE_PTR
const PRIVATE_TAG_PTR = STORAGE_PTR + 4
const PRIVATE_AMOUNT_PTR = STORAGE_PTR + 5

# Memory addresses of MINT note storage (public mode)
const PUBLIC_SCRIPT_ROOT_PTR = STORAGE_PTR
const PUBLIC_SERIAL_NUM_PTR = STORAGE_PTR + 4
const PUBLIC_TAG_PTR = STORAGE_PTR + 8
const PUBLIC_AMOUNT_PTR = STORAGE_PTR + 9
const PUBLIC_OUTPUT_NOTE_STORAGE_PTR = STORAGE_PTR + 12

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

const ERR_MINT_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS="MINT script expects exactly 12 storage items for private or 16+ storage items for public output notes"
const ERR_MINT_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS="MINT script expects exactly 6 storage items for private or 12+ storage items for public output notes"

#! Network Faucet MINT script: mints assets by calling the network faucet's mint_and_send
#! function.
Expand All @@ -37,34 +42,32 @@ const ERR_MINT_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS="MINT script expects exactly 1
#! Note storage supports two modes. Depending on the number of note storage items,
#! a private or public note is created on consumption of the MINT note:
#!
#! Private mode (12 storage items) - creates a private note:
#! - tag: Note tag for the output note
#! - amount: The amount to mint
#! - attachment_scheme: The user-defined type of the attachment.
#! - attachment_kind: The attachment kind of the attachment.
#! - ATTACHMENT: The attachment to be set.
#! Private mode (6 storage items) - creates a private note:
#! - RECIPIENT: The recipient digest (4 elements)
#!
#! Public mode (16+ storage items) - creates a public note with variable-length storage:
#! - tag: Note tag for the output note
#! - amount: The amount to mint
#! - attachment_scheme: The user-defined type of the attachment.
#! - attachment_kind: The attachment kind of the attachment.
#! - ATTACHMENT: The attachment to be set.
#!
#! Public mode (12+ storage items) - creates a public note with variable-length storage:
#! - SCRIPT_ROOT: Script root of the output note (4 elements)
#! - SERIAL_NUM: Serial number of the output note (4 elements)
#! - tag: Note tag for the output note
#! - amount: The amount to mint
#! - padding
#! - padding
#! - [STORAGE]: Variable-length storage for the output note (Vec<Felt>)
#! The number of output note storage items = num_mint_note_storage_items - 16
#! The number of output note storage items = num_mint_note_storage_items - 12
#!
#! The padding is necessary since note::build_recipient expects a word-aligned storage_ptr.
#!
#! Panics if:
#! - account does not expose mint_and_send procedure.
#! - the number of storage items is not exactly 12 for private or less than 16 for public output notes.
#! - the number of storage items is not exactly 6 for private or less than 12 for public output notes.
@note_script
pub proc main
dropw
# => [pad(16)]
# Load note storage into memory starting at address 0
push.0 exec.active_note::get_storage
# Load note storage into memory starting at STORAGE_PTR
push.STORAGE_PTR exec.active_note::get_storage
# => [num_storage_items, storage_ptr, pad(16)]

dup
Expand All @@ -81,25 +84,25 @@ pub proc main
movdn.9 drop
# => [EMPTY_WORD, EMPTY_WORD, num_storage_items, pad(8)]

mem_loadw_le.8
mem_loadw_le.PUBLIC_SCRIPT_ROOT_PTR
# => [SCRIPT_ROOT, EMPTY_WORD, num_storage_items, pad(8)]

swapw mem_loadw_le.12
swapw mem_loadw_le.PUBLIC_SERIAL_NUM_PTR
# => [SERIAL_NUM, SCRIPT_ROOT, num_storage_items, pad(8)]

# compute variable length note storage for the output note
movup.8 sub.MINT_NOTE_MIN_NUM_STORAGE_ITEMS_PUBLIC
# => [num_output_note_storage, SERIAL_NUM, SCRIPT_ROOT, pad(8)]

push.OUTPUT_PUBLIC_NOTE_STORAGE_ADDR
push.PUBLIC_OUTPUT_NOTE_STORAGE_PTR
# => [storage_ptr, num_output_note_storage, SERIAL_NUM, SCRIPT_ROOT, pad(8)]

exec.note::build_recipient
# => [RECIPIENT, pad(12)]

# push note_type, and load tag and amount
push.NOTE_TYPE_PUBLIC
mem_load.0 mem_load.1
mem_load.PUBLIC_TAG_PTR mem_load.PUBLIC_AMOUNT_PTR
# => [amount, tag, note_type, RECIPIENT, pad(12)]
else
# private output note creation
Expand All @@ -110,12 +113,12 @@ pub proc main
drop
# => [pad(16)]

mem_loadw_le.8
mem_loadw_le.PRIVATE_RECIPIENT_PTR
# => [RECIPIENT, pad(12)]

# push note_type, and load tag and amount
push.NOTE_TYPE_PRIVATE
mem_load.0 mem_load.1
mem_load.PRIVATE_TAG_PTR mem_load.PRIVATE_AMOUNT_PTR
# => [amount, tag, note_type, RECIPIENT, pad(12)]
end
# => [amount, tag, note_type, RECIPIENT, pad(12)]
Expand All @@ -125,17 +128,6 @@ pub proc main
call.network_faucet::mint_and_send
# => [note_idx, pad(18))]

padw mem_loadw_le.ATTACHMENT_ADDRESS
# => [ATTACHMENT, note_idx, pad(18))]

mem_load.ATTACHMENT_KIND_ADDRESS
mem_load.ATTACHMENT_SCHEME_ADDRESS
movup.6
# => [note_idx, attachment_scheme, attachment_kind, ATTACHMENT, pad(18))]

exec.output_note::set_attachment
# => [pad(18))]

drop drop
drop drop drop
# => [pad(16)]
end
45 changes: 14 additions & 31 deletions crates/miden-standards/asm/standards/notes/swap.masm
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ use miden::standards::wallets::basic->wallet
# CONSTANTS
# =================================================================================================

const SWAP_NOTE_NUM_STORAGE_ITEMS=20
const SWAP_NOTE_NUM_STORAGE_ITEMS=14

const PAYBACK_NOTE_TYPE_PTR=0
const PAYBACK_NOTE_TAG_PTR=1
const ATTACHMENT_KIND_PTR=2
const ATTACHMENT_SCHEME_PTR=3
const ATTACHMENT_PTR=4
const REQUESTED_ASSET_PTR=8
const PAYBACK_RECIPIENT_PTR=16
const ASSET_PTR=20
const REQUESTED_ASSET_PTR=0
const PAYBACK_RECIPIENT_PTR=8
const PAYBACK_NOTE_TYPE_PTR=12
const PAYBACK_NOTE_TAG_PTR=13
const ASSET_PTR=16

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

const ERR_SWAP_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS="SWAP script expects exactly 16 note storage items"
const ERR_SWAP_UNEXPECTED_NUMBER_OF_STORAGE_ITEMS="SWAP script expects exactly 14 note storage items"

const ERR_SWAP_WRONG_NUMBER_OF_ASSETS="SWAP script requires exactly 1 note asset"

Expand All @@ -35,23 +32,18 @@ const ERR_SWAP_WRONG_NUMBER_OF_ASSETS="SWAP script requires exactly 1 note asset
#! Outputs: []
#!
#! Note storage is assumed to be as follows:
#! - payback_note_type
#! - payback_note_tag
#! - attachment_kind
#! - attachment_scheme
#! - ATTACHMENT
#! - REQUESTED_ASSET_KEY
#! - REQUESTED_ASSET_VALUE
#! - PAYBACK_RECIPIENT
#! - payback_note_type
#! - payback_note_tag
#!
#! Panics if:
#! - account does not expose miden::standards::wallets::basic::receive_asset procedure.
#! - account does not expose miden::standards::wallets::basic::move_asset_to_note procedure.
#! - account vault does not contain the requested asset.
#! - adding a fungible asset would result in amount overflow, i.e., the total amount would be
#! greater than 2^63.
#! - the attachment kind or scheme does not fit into a u32.
#! - the attachment kind is an unknown variant.
@note_script
pub proc main
# dropping note args
Expand Down Expand Up @@ -81,26 +73,17 @@ pub proc main
exec.output_note::create
# => [note_idx]

padw push.0.0.0 dup.7
# => [note_idx, pad(7), note_idx]
padw push.0.0.0 movup.7
# => [note_idx, pad(7)]

push.REQUESTED_ASSET_PTR exec.asset::load
# => [REQUESTED_ASSET_KEY, REQUESTED_ASSET_VALUE, note_idx, pad(7), note_idx]
# => [REQUESTED_ASSET_KEY, REQUESTED_ASSET_VALUE, note_idx, pad(7)]

# move asset to the note
call.wallet::move_asset_to_note
# => [pad(16), note_idx]

dropw
mem_loadw_le.ATTACHMENT_PTR
# => [ATTACHMENT, pad(8), note_idx]

mem_load.ATTACHMENT_KIND_PTR
mem_load.ATTACHMENT_SCHEME_PTR
movup.14
# => [note_idx, attachment_scheme, attachment_kind, ATTACHMENT, pad(8)]
# => [pad(16)]

exec.output_note::set_attachment
dropw dropw
# => [pad(8)]

# --- move assets from the SWAP note into the account -------------------------
Expand Down
Loading
Loading