diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b171cee09..7bc7a6c8df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm b/crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm index 0364f4a3f0..e4abf8e986 100644 --- a/crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm +++ b/crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm @@ -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 @@ -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 # ------------------------------------------------------------------------------------------------- @@ -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 # ------------------------------------------------------------------------------------------------- @@ -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] @@ -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] diff --git a/crates/miden-standards/asm/standards/notes/mint.masm b/crates/miden-standards/asm/standards/notes/mint.masm index 7780a67052..b35a9eddb4 100644 --- a/crates/miden-standards/asm/standards/notes/mint.masm +++ b/crates/miden-standards/asm/standards/notes/mint.masm @@ -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. @@ -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) -#! 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 @@ -81,17 +84,17 @@ 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 @@ -99,7 +102,7 @@ pub proc main # 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 @@ -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)] @@ -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 diff --git a/crates/miden-standards/asm/standards/notes/swap.masm b/crates/miden-standards/asm/standards/notes/swap.masm index cedb7a6236..da1417db1f 100644 --- a/crates/miden-standards/asm/standards/notes/swap.masm +++ b/crates/miden-standards/asm/standards/notes/swap.masm @@ -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" @@ -35,14 +32,11 @@ 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. @@ -50,8 +44,6 @@ const ERR_SWAP_WRONG_NUMBER_OF_ASSETS="SWAP script requires exactly 1 note asset #! - 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 @@ -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 ------------------------- diff --git a/crates/miden-standards/src/account/interface/test.rs b/crates/miden-standards/src/account/interface/test.rs index 5aef3f6203..23e1f8201f 100644 --- a/crates/miden-standards/src/account/interface/test.rs +++ b/crates/miden-standards/src/account/interface/test.rs @@ -100,7 +100,6 @@ fn test_basic_wallet_default_notes() { NoteType::Public, NoteAttachment::default(), NoteType::Public, - NoteAttachment::default(), &mut RandomCoin::new(Word::from([1, 2, 3, 4u32])), ) .unwrap(); @@ -195,7 +194,6 @@ fn test_custom_account_default_note() { NoteType::Public, NoteAttachment::default(), NoteType::Public, - NoteAttachment::default(), &mut RandomCoin::new(Word::from([1, 2, 3, 4u32])), ) .unwrap(); @@ -228,7 +226,6 @@ fn test_required_asset_same_as_offered() { NoteType::Public, NoteAttachment::default(), NoteType::Public, - NoteAttachment::default(), &mut RandomCoin::new(Word::from([1, 2, 3, 4u32])), ); diff --git a/crates/miden-standards/src/note/mint.rs b/crates/miden-standards/src/note/mint.rs index f3363eaa76..a020802833 100644 --- a/crates/miden-standards/src/note/mint.rs +++ b/crates/miden-standards/src/note/mint.rs @@ -45,7 +45,7 @@ impl MintNote { // -------------------------------------------------------------------------------------------- /// Expected number of storage items of the MINT note (private mode). - pub const NUM_STORAGE_ITEMS_PRIVATE: usize = 8; + pub const NUM_STORAGE_ITEMS_PRIVATE: usize = 6; // PUBLIC ACCESSORS // -------------------------------------------------------------------------------------------- @@ -117,10 +117,10 @@ impl MintNote { // ================================================================================================ /// Represents the different storage formats for MINT notes. -/// - Private: Creates a private output note using a precomputed recipient digest (12 MINT note +/// - Private: Creates a private output note using a precomputed recipient digest (6 MINT note /// storage items) /// - Public: Creates a public output note by providing script root, serial number, and -/// variable-length storage (16+ MINT note storage items: 16 fixed + variable number of output +/// variable-length storage (12+ MINT note storage items: 12 fixed + variable number of output /// note storage items) #[derive(Debug, Clone, PartialEq, Eq)] pub enum MintNoteStorage { @@ -128,24 +128,17 @@ pub enum MintNoteStorage { recipient_digest: Word, amount: Felt, tag: Felt, - attachment: NoteAttachment, }, Public { recipient: NoteRecipient, amount: Felt, tag: Felt, - attachment: NoteAttachment, }, } impl MintNoteStorage { pub fn new_private(recipient_digest: Word, amount: Felt, tag: Felt) -> Self { - Self::Private { - recipient_digest, - amount, - tag, - attachment: NoteAttachment::default(), - } + Self::Private { recipient_digest, amount, tag } } pub fn new_public( @@ -154,9 +147,9 @@ impl MintNoteStorage { tag: Felt, ) -> Result { // Calculate total number of storage items that will be created: - // 16 fixed items (tag, amount, attachment_kind, attachment_scheme, ATTACHMENT, - // SCRIPT_ROOT, SERIAL_NUM) + variable recipient number of storage items - const FIXED_PUBLIC_STORAGE_ITEMS: usize = 16; + // 12 fixed items (SCRIPT_ROOT, SERIAL_NUM, tag, amount, 2 padding) + variable recipient + // number of storage items + const FIXED_PUBLIC_STORAGE_ITEMS: usize = 12; let total_storage_items = FIXED_PUBLIC_STORAGE_ITEMS + recipient.storage().num_items() as usize; @@ -164,69 +157,25 @@ impl MintNoteStorage { return Err(NoteError::TooManyStorageItems(total_storage_items)); } - Ok(Self::Public { - recipient, - amount, - tag, - attachment: NoteAttachment::default(), - }) - } - - /// Overwrites the [`NoteAttachment`] of the note storage. - pub fn with_attachment(self, attachment: NoteAttachment) -> Self { - match self { - MintNoteStorage::Private { - recipient_digest, - amount, - tag, - attachment: _, - } => MintNoteStorage::Private { - recipient_digest, - amount, - tag, - attachment, - }, - MintNoteStorage::Public { recipient, amount, tag, attachment: _ } => { - MintNoteStorage::Public { recipient, amount, tag, attachment } - }, - } + Ok(Self::Public { recipient, amount, tag }) } } impl From for NoteStorage { fn from(mint_storage: MintNoteStorage) -> Self { match mint_storage { - MintNoteStorage::Private { - recipient_digest, - amount, - tag, - attachment, - } => { - let attachment_scheme = Felt::from(attachment.attachment_scheme().as_u32()); - let attachment_kind = Felt::from(attachment.attachment_kind().as_u8()); - let attachment = attachment.content().to_word(); - - let mut storage_values = Vec::with_capacity(12); - storage_values.extend_from_slice(&[ - tag, - amount, - attachment_kind, - attachment_scheme, - ]); - storage_values.extend_from_slice(attachment.as_elements()); + MintNoteStorage::Private { recipient_digest, amount, tag } => { + let mut storage_values = Vec::with_capacity(MintNote::NUM_STORAGE_ITEMS_PRIVATE); storage_values.extend_from_slice(recipient_digest.as_elements()); + storage_values.extend_from_slice(&[tag, amount]); NoteStorage::new(storage_values) .expect("number of storage items should not exceed max storage items") }, - MintNoteStorage::Public { recipient, amount, tag, attachment } => { - let attachment_scheme = Felt::from(attachment.attachment_scheme().as_u32()); - let attachment_kind = Felt::from(attachment.attachment_kind().as_u8()); - let attachment = attachment.content().to_word(); - - let mut storage_values = vec![tag, amount, attachment_kind, attachment_scheme]; - storage_values.extend_from_slice(attachment.as_elements()); + MintNoteStorage::Public { recipient, amount, tag } => { + let mut storage_values = Vec::new(); storage_values.extend_from_slice(recipient.script().root().as_elements()); storage_values.extend_from_slice(recipient.serial_num().as_elements()); + storage_values.extend_from_slice(&[tag, amount, Felt::ZERO, Felt::ZERO]); storage_values.extend_from_slice(recipient.storage().items()); NoteStorage::new(storage_values) .expect("number of storage items should not exceed max storage items") diff --git a/crates/miden-standards/src/note/swap.rs b/crates/miden-standards/src/note/swap.rs index 1d473b9c7f..e95c20c543 100644 --- a/crates/miden-standards/src/note/swap.rs +++ b/crates/miden-standards/src/note/swap.rs @@ -1,5 +1,6 @@ use alloc::vec::Vec; +use miden_protocol::Word; use miden_protocol::account::AccountId; use miden_protocol::assembly::Path; use miden_protocol::asset::Asset; @@ -18,7 +19,6 @@ use miden_protocol::note::{ NoteType, }; use miden_protocol::utils::sync::LazyLock; -use miden_protocol::{Felt, Word}; use crate::StandardsLib; use crate::note::P2idNoteStorage; @@ -82,7 +82,6 @@ impl SwapNote { swap_note_type: NoteType, swap_note_attachment: NoteAttachment, payback_note_type: NoteType, - payback_note_attachment: NoteAttachment, rng: &mut R, ) -> Result<(Note, NoteDetails), NoteError> { if requested_asset == offered_asset { @@ -91,13 +90,8 @@ impl SwapNote { let payback_serial_num = rng.draw_word(); - let swap_storage = SwapNoteStorage::new( - sender, - requested_asset, - payback_note_type, - payback_note_attachment, - payback_serial_num, - ); + let swap_storage = + SwapNoteStorage::new(sender, requested_asset, payback_note_type, payback_serial_num); let serial_num = rng.draw_word(); let recipient = swap_storage.into_recipient(serial_num); @@ -172,7 +166,6 @@ impl SwapNote { pub struct SwapNoteStorage { payback_note_type: NoteType, payback_tag: NoteTag, - payback_attachment: NoteAttachment, requested_asset: Asset, payback_recipient_digest: Word, } @@ -182,7 +175,7 @@ impl SwapNoteStorage { // -------------------------------------------------------------------------------------------- /// Expected number of storage items of the SWAP note. - pub const NUM_ITEMS: usize = 20; + pub const NUM_ITEMS: usize = 14; // CONSTRUCTORS // -------------------------------------------------------------------------------------------- @@ -192,7 +185,6 @@ impl SwapNoteStorage { sender: AccountId, requested_asset: Asset, payback_note_type: NoteType, - payback_attachment: NoteAttachment, payback_serial_number: Word, ) -> Self { let payback_recipient = P2idNoteStorage::new(sender).into_recipient(payback_serial_number); @@ -201,7 +193,6 @@ impl SwapNoteStorage { Self::from_parts( payback_note_type, payback_tag, - payback_attachment, requested_asset, payback_recipient.digest(), ) @@ -211,14 +202,12 @@ impl SwapNoteStorage { pub fn from_parts( payback_note_type: NoteType, payback_tag: NoteTag, - payback_attachment: NoteAttachment, requested_asset: Asset, payback_recipient_digest: Word, ) -> Self { Self { payback_note_type, payback_tag, - payback_attachment, requested_asset, payback_recipient_digest, } @@ -234,11 +223,6 @@ impl SwapNoteStorage { self.payback_tag } - /// Returns the payback note attachment. - pub fn payback_attachment(&self) -> &NoteAttachment { - &self.payback_attachment - } - /// Returns the requested asset. pub fn requested_asset(&self) -> Asset { self.requested_asset @@ -260,20 +244,11 @@ impl SwapNoteStorage { impl From for NoteStorage { fn from(storage: SwapNoteStorage) -> Self { - let attachment_scheme = Felt::from(storage.payback_attachment.attachment_scheme().as_u32()); - let attachment_kind = Felt::from(storage.payback_attachment.attachment_kind().as_u8()); - let attachment = storage.payback_attachment.content().to_word(); - let mut storage_values = Vec::with_capacity(SwapNoteStorage::NUM_ITEMS); - storage_values.extend_from_slice(&[ - storage.payback_note_type.into(), - storage.payback_tag.into(), - attachment_scheme, - attachment_kind, - ]); - storage_values.extend_from_slice(attachment.as_elements()); storage_values.extend_from_slice(&storage.requested_asset.as_elements()); storage_values.extend_from_slice(storage.payback_recipient_digest.as_elements()); + storage_values + .extend_from_slice(&[storage.payback_note_type.into(), storage.payback_tag.into()]); NoteStorage::new(storage_values) .expect("number of storage items should not exceed max storage items") @@ -291,7 +266,7 @@ mod tests { use miden_protocol::Felt; use miden_protocol::account::{AccountIdVersion, AccountStorageMode, AccountType}; use miden_protocol::asset::{FungibleAsset, NonFungibleAsset, NonFungibleAssetDetails}; - use miden_protocol::note::{NoteAttachment, NoteStorage, NoteTag, NoteType}; + use miden_protocol::note::{NoteStorage, NoteTag, NoteType}; use miden_protocol::testing::account_id::{ ACCOUNT_ID_PUBLIC_FUNGIBLE_FAUCET, ACCOUNT_ID_PUBLIC_NON_FUNGIBLE_FAUCET, @@ -321,7 +296,6 @@ mod tests { fn swap_note_storage() { let payback_note_type = NoteType::Private; let payback_tag = NoteTag::new(0x12345678); - let payback_attachment = NoteAttachment::default(); let requested_asset = fungible_asset(); let payback_recipient_digest = Word::new([Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]); @@ -329,14 +303,12 @@ mod tests { let storage = SwapNoteStorage::from_parts( payback_note_type, payback_tag, - payback_attachment.clone(), requested_asset, payback_recipient_digest, ); assert_eq!(storage.payback_note_type(), payback_note_type); assert_eq!(storage.payback_tag(), payback_tag); - assert_eq!(storage.payback_attachment(), &payback_attachment); assert_eq!(storage.requested_asset(), requested_asset); assert_eq!(storage.payback_recipient_digest(), payback_recipient_digest); @@ -349,7 +321,6 @@ mod tests { fn swap_note_storage_with_non_fungible_asset() { let payback_note_type = NoteType::Public; let payback_tag = NoteTag::new(0xaabbccdd); - let payback_attachment = NoteAttachment::default(); let requested_asset = non_fungible_asset(); let payback_recipient_digest = Word::new([Felt::new(10), Felt::new(20), Felt::new(30), Felt::new(40)]); @@ -357,7 +328,6 @@ mod tests { let storage = SwapNoteStorage::from_parts( payback_note_type, payback_tag, - payback_attachment, requested_asset, payback_recipient_digest, ); diff --git a/crates/miden-testing/src/mock_chain/chain_builder.rs b/crates/miden-testing/src/mock_chain/chain_builder.rs index 468953f38b..9b9baef042 100644 --- a/crates/miden-testing/src/mock_chain/chain_builder.rs +++ b/crates/miden-testing/src/mock_chain/chain_builder.rs @@ -619,7 +619,6 @@ impl MockChainBuilder { NoteType::Public, NoteAttachment::default(), payback_note_type, - NoteAttachment::default(), &mut self.rng, )?;