From 8955ccbe87c42990f7f95a7cfe207be194a39fe2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 21:18:16 +0000 Subject: [PATCH 1/5] Update NoteMetadata::new API calls in miden-testing crate Changed from NoteMetadata::new(sender, note_type, tag) to NoteMetadata::new(sender, note_type).with_tag(tag) across all files in the miden-testing crate. Updated files: - tests/agglayer/bridge_out.rs (2 occurrences) - tests/agglayer/bridge_in.rs (1 occurrence) - tests/scripts/faucet.rs (2 occurrences) - tests/scripts/send_note.rs (2 occurrences) - tests/scripts/swap.rs (1 occurrence) - tests/lib.rs (1 occurrence) - src/kernel_tests/tx/test_output_note.rs (3 occurrences) - src/kernel_tests/tx/test_tx.rs (2 occurrences) - src/kernel_tests/tx/test_account_interface.rs (1 occurrence) - src/kernel_tests/tx/test_note.rs (2 occurrences) - src/kernel_tests/tx/test_active_note.rs (1 occurrence) - src/standards/network_account_target.rs (1 occurrence) --- crates/miden-protocol/src/note/file.rs | 3 ++- crates/miden-protocol/src/note/metadata.rs | 22 +++++++++++++++---- crates/miden-protocol/src/testing/note.rs | 7 ++---- .../kernel_tests/tx/test_account_interface.rs | 2 +- .../src/kernel_tests/tx/test_active_note.rs | 2 +- .../src/kernel_tests/tx/test_note.rs | 4 ++-- .../src/kernel_tests/tx/test_output_note.rs | 7 +++--- .../src/kernel_tests/tx/test_tx.rs | 4 ++-- .../src/standards/network_account_target.rs | 3 ++- .../miden-testing/tests/agglayer/bridge_in.rs | 2 +- .../tests/agglayer/bridge_out.rs | 4 ++-- crates/miden-testing/tests/lib.rs | 2 +- crates/miden-testing/tests/scripts/faucet.rs | 4 ++-- .../miden-testing/tests/scripts/send_note.rs | 6 +++-- crates/miden-testing/tests/scripts/swap.rs | 2 +- crates/miden-tx/src/host/tx_event.rs | 2 +- 16 files changed, 46 insertions(+), 30 deletions(-) diff --git a/crates/miden-protocol/src/note/file.rs b/crates/miden-protocol/src/note/file.rs index 7777eeee77..617182c35c 100644 --- a/crates/miden-protocol/src/note/file.rs +++ b/crates/miden-protocol/src/note/file.rs @@ -171,7 +171,8 @@ mod tests { let recipient = NoteRecipient::new(serial_num, script, note_storage); let asset = Asset::Fungible(FungibleAsset::new(faucet, 100).unwrap()); - let metadata = NoteMetadata::new(faucet, NoteType::Public, NoteTag::from(123)); + let metadata = NoteMetadata::new(faucet, NoteType::Public) + .with_tag(NoteTag::from(123)); Note::new(NoteAssets::new(vec![asset]).unwrap(), metadata, recipient) } diff --git a/crates/miden-protocol/src/note/metadata.rs b/crates/miden-protocol/src/note/metadata.rs index d1a58ceace..933a2f5102 100644 --- a/crates/miden-protocol/src/note/metadata.rs +++ b/crates/miden-protocol/src/note/metadata.rs @@ -77,11 +77,14 @@ impl NoteMetadata { // -------------------------------------------------------------------------------------------- /// Returns a new [`NoteMetadata`] instantiated with the specified parameters. - pub fn new(sender: AccountId, note_type: NoteType, tag: NoteTag) -> Self { + /// + /// The tag defaults to [`NoteTag::default()`]. Use [`NoteMetadata::with_tag`] to set a + /// specific tag if needed. + pub fn new(sender: AccountId, note_type: NoteType) -> Self { Self { sender, note_type, - tag, + tag: NoteTag::default(), attachment: NoteAttachment::default(), } } @@ -153,6 +156,17 @@ impl NoteMetadata { // MUTATORS // -------------------------------------------------------------------------------------------- + /// Overwrites the note's tag with the provided one. + pub fn set_tag(&mut self, tag: NoteTag) { + self.tag = tag; + } + + /// Overwrites the note's tag with the provided one. + pub fn with_tag(mut self, tag: NoteTag) -> Self { + self.tag = tag; + self + } + /// Overwrites the note's attachment with the provided one. pub fn set_attachment(&mut self, attachment: NoteAttachment) { self.attachment = attachment; @@ -184,7 +198,7 @@ impl Deserializable for NoteMetadata { let tag = NoteTag::read_from(source)?; let attachment = NoteAttachment::read_from(source)?; - Ok(NoteMetadata::new(sender, note_type, tag).with_attachment(attachment)) + Ok(NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment)) } } @@ -351,7 +365,7 @@ mod tests { let sender = AccountId::try_from(ACCOUNT_ID_MAX_ONES).unwrap(); let note_type = NoteType::Public; let tag = NoteTag::new(u32::MAX); - let metadata = NoteMetadata::new(sender, note_type, tag).with_attachment(attachment); + let metadata = NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); // Serialization Roundtrip let deserialized = NoteMetadata::read_from_bytes(&metadata.to_bytes())?; diff --git a/crates/miden-protocol/src/testing/note.rs b/crates/miden-protocol/src/testing/note.rs index 4ce184788f..913fd0f7ee 100644 --- a/crates/miden-protocol/src/testing/note.rs +++ b/crates/miden-protocol/src/testing/note.rs @@ -24,11 +24,8 @@ impl Note { let note_script = NoteScript::mock(); let assets = NoteAssets::new(vec![FungibleAsset::mock(200)]).expect("note assets should be valid"); - let metadata = NoteMetadata::new( - sender_id, - NoteType::Private, - NoteTag::with_account_target(sender_id), - ); + let metadata = NoteMetadata::new(sender_id, NoteType::Private) + .with_tag(NoteTag::with_account_target(sender_id)); let inputs = NoteStorage::new(Vec::new()).unwrap(); let recipient = NoteRecipient::new(serial_num, note_script, inputs); diff --git a/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs b/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs index e8f0efed52..3fa28f6d28 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs @@ -791,7 +791,7 @@ fn create_p2ide_note_with_storage( ); let tag = NoteTag::with_account_target(sender); - let metadata = NoteMetadata::new(sender, NoteType::Public, tag); + let metadata = NoteMetadata::new(sender, NoteType::Public).with_tag(tag); Note::new(NoteAssets::default(), metadata, recipient) } diff --git a/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs index 1c5b8488d7..9507e3393e 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs @@ -408,7 +408,7 @@ async fn test_active_note_get_exactly_8_inputs() -> anyhow::Result<()> { // prepare note data let serial_num = RpoRandomCoin::new(Word::from([4u32; 4])).draw_word(); let tag = NoteTag::with_account_target(target_id); - let metadata = NoteMetadata::new(sender_id, NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_id, NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![]).context("failed to create input note assets")?; let note_script = CodeBuilder::default() .compile_note_script("begin nop end") diff --git a/crates/miden-testing/src/kernel_tests/tx/test_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_note.rs index 36fb76b3f3..55a79ad364 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_note.rs @@ -382,8 +382,8 @@ async fn test_build_metadata_header() -> anyhow::Result<()> { .map_err(|e| anyhow::anyhow!("Failed to convert account ID: {}", e))?; let test_metadata1 = - NoteMetadata::new(sender, NoteType::Private, NoteTag::with_account_target(receiver)); - let test_metadata2 = NoteMetadata::new(sender, NoteType::Public, NoteTag::new(u32::MAX)); + NoteMetadata::new(sender, NoteType::Private).with_tag(NoteTag::with_account_target(receiver)); + let test_metadata2 = NoteMetadata::new(sender, NoteType::Public).with_tag(NoteTag::new(u32::MAX)); for (iteration, test_metadata) in [test_metadata1, test_metadata2].into_iter().enumerate() { let code = format!( diff --git a/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs index f03dce4331..f2fffc33db 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs @@ -100,7 +100,7 @@ async fn test_create_note() -> anyhow::Result<()> { "recipient must be stored at the correct memory location", ); - let metadata = NoteMetadata::new(account_id, NoteType::Public, tag); + let metadata = NoteMetadata::new(account_id, NoteType::Public).with_tag(tag); let expected_metadata_header = metadata.to_header_word(); let expected_note_attachment = metadata.to_attachment_word(); @@ -251,7 +251,7 @@ async fn test_get_output_notes_commitment() -> anyhow::Result<()> { let output_tag_1 = NoteTag::with_account_target(network_account); let assets = NoteAssets::new(vec![input_asset_1])?; let metadata = - NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public, output_tag_1); + NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public).with_tag(output_tag_1); let inputs = NoteStorage::new(vec![])?; let recipient = NoteRecipient::new(output_serial_no_1, input_note_1.script().clone(), inputs); let output_note_1 = Note::new(assets, metadata, recipient); @@ -265,7 +265,8 @@ async fn test_get_output_notes_commitment() -> anyhow::Result<()> { [42, 43, 44, 45, 46u32].map(Felt::from).to_vec(), )?; let metadata = - NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public, output_tag_2) + NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public) + .with_tag(output_tag_2) .with_attachment(attachment); let inputs = NoteStorage::new(vec![])?; let recipient = NoteRecipient::new(output_serial_no_2, input_note_2.script().clone(), inputs); diff --git a/crates/miden-testing/src/kernel_tests/tx/test_tx.rs b/crates/miden-testing/src/kernel_tests/tx/test_tx.rs index fb9d672668..f98ea2e190 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_tx.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_tx.rs @@ -224,7 +224,7 @@ async fn executed_transaction_output_notes() -> anyhow::Result<()> { let note_script_2 = CodeBuilder::default().compile_note_script(DEFAULT_NOTE_CODE)?; let inputs_2 = NoteStorage::new(vec![ONE])?; let metadata_2 = - NoteMetadata::new(account_id, note_type2, tag2).with_attachment(attachment2.clone()); + NoteMetadata::new(account_id, note_type2).with_tag(tag2).with_attachment(attachment2.clone()); let vault_2 = NoteAssets::new(vec![removed_asset_3, removed_asset_4])?; let recipient_2 = NoteRecipient::new(serial_num_2, note_script_2, inputs_2); let expected_output_note_2 = Note::new(vault_2, metadata_2, recipient_2); @@ -234,7 +234,7 @@ async fn executed_transaction_output_notes() -> anyhow::Result<()> { let note_script_3 = CodeBuilder::default().compile_note_script(DEFAULT_NOTE_CODE)?; let inputs_3 = NoteStorage::new(vec![ONE, Felt::new(2)])?; let metadata_3 = - NoteMetadata::new(account_id, note_type3, tag3).with_attachment(attachment3.clone()); + NoteMetadata::new(account_id, note_type3).with_tag(tag3).with_attachment(attachment3.clone()); let vault_3 = NoteAssets::new(vec![])?; let recipient_3 = NoteRecipient::new(serial_num_3, note_script_3, inputs_3); let expected_output_note_3 = Note::new(vault_3, metadata_3, recipient_3); diff --git a/crates/miden-testing/src/standards/network_account_target.rs b/crates/miden-testing/src/standards/network_account_target.rs index 9908377592..3550fdadac 100644 --- a/crates/miden-testing/src/standards/network_account_target.rs +++ b/crates/miden-testing/src/standards/network_account_target.rs @@ -17,7 +17,8 @@ async fn network_account_target_get_id() -> anyhow::Result<()> { let attachment = NoteAttachment::from(NetworkAccountTarget::new(target_id, exec_hint)?); let metadata = - NoteMetadata::new(target_id, NoteType::Public, NoteTag::with_account_target(target_id)) + NoteMetadata::new(target_id, NoteType::Public) + .with_tag(NoteTag::with_account_target(target_id)) .with_attachment(attachment.clone()); let metadata_header = metadata.to_header_word(); diff --git a/crates/miden-testing/tests/agglayer/bridge_in.rs b/crates/miden-testing/tests/agglayer/bridge_in.rs index c87bd0d77c..7dfac45d5c 100644 --- a/crates/miden-testing/tests/agglayer/bridge_in.rs +++ b/crates/miden-testing/tests/agglayer/bridge_in.rs @@ -131,7 +131,7 @@ async fn test_bridge_in_claim_to_p2id() -> anyhow::Result<()> { let output_note_tag = NoteTag::with_account_target(user_account.id()); let expected_p2id_note = Note::new( NoteAssets::new(vec![mint_asset])?, - NoteMetadata::new(agglayer_faucet.id(), NoteType::Public, output_note_tag), + NoteMetadata::new(agglayer_faucet.id(), NoteType::Public).with_tag(output_note_tag), p2id_recipient, ); diff --git a/crates/miden-testing/tests/agglayer/bridge_out.rs b/crates/miden-testing/tests/agglayer/bridge_out.rs index ee22a0a502..4344dfaf20 100644 --- a/crates/miden-testing/tests/agglayer/bridge_out.rs +++ b/crates/miden-testing/tests/agglayer/bridge_out.rs @@ -90,7 +90,7 @@ async fn test_bridge_out_consumes_b2agg_note() -> anyhow::Result<()> { let inputs = NoteStorage::new(input_felts.clone())?; // Create the B2AGG note with assets from the faucet - let b2agg_note_metadata = NoteMetadata::new(faucet.id(), note_type, tag); + let b2agg_note_metadata = NoteMetadata::new(faucet.id(), note_type).with_tag(tag); let b2agg_note_assets = NoteAssets::new(vec![bridge_asset])?; let serial_num = Word::from([1, 2, 3, 4u32]); let b2agg_note_script = NoteScript::new(b2agg_script); @@ -247,7 +247,7 @@ async fn test_b2agg_note_reclaim_scenario() -> anyhow::Result<()> { // Create the B2AGG note with the USER ACCOUNT as the sender // This is the key difference - the note sender will be the same as the consuming account - let b2agg_note_metadata = NoteMetadata::new(user_account.id(), note_type, tag); + let b2agg_note_metadata = NoteMetadata::new(user_account.id(), note_type).with_tag(tag); let b2agg_note_assets = NoteAssets::new(vec![bridge_asset])?; let serial_num = Word::from([1, 2, 3, 4u32]); let b2agg_note_script = NoteScript::new(b2agg_script); diff --git a/crates/miden-testing/tests/lib.rs b/crates/miden-testing/tests/lib.rs index ac31d839cd..ef884c34a8 100644 --- a/crates/miden-testing/tests/lib.rs +++ b/crates/miden-testing/tests/lib.rs @@ -62,7 +62,7 @@ pub fn get_note_with_fungible_asset_and_script( let sender_id = AccountId::try_from(ACCOUNT_ID_SENDER).unwrap(); let vault = NoteAssets::new(vec![fungible_asset.into()]).unwrap(); - let metadata = NoteMetadata::new(sender_id, NoteType::Public, 1.into()); + let metadata = NoteMetadata::new(sender_id, NoteType::Public).with_tag(1.into()); let inputs = NoteStorage::new(vec![]).unwrap(); let recipient = NoteRecipient::new(serial_num, note_script, inputs); diff --git a/crates/miden-testing/tests/scripts/faucet.rs b/crates/miden-testing/tests/scripts/faucet.rs index c5daa5792e..0878097a61 100644 --- a/crates/miden-testing/tests/scripts/faucet.rs +++ b/crates/miden-testing/tests/scripts/faucet.rs @@ -117,7 +117,7 @@ pub fn verify_minted_output_note( assert_eq!(output_note.id(), id); assert_eq!( output_note.metadata(), - &NoteMetadata::new(faucet.id(), params.note_type, params.tag) + &NoteMetadata::new(faucet.id(), params.note_type).with_tag(params.tag) ); Ok(()) @@ -329,7 +329,7 @@ async fn test_public_note_creation_with_script_from_datastore() -> anyhow::Resul let output_script_root = note_recipient.script().root(); let asset = FungibleAsset::new(faucet.id(), amount.into())?; - let metadata = NoteMetadata::new(faucet.id(), note_type, tag); + let metadata = NoteMetadata::new(faucet.id(), note_type).with_tag(tag); let expected_note = Note::new(NoteAssets::new(vec![asset.into()])?, metadata, note_recipient); let trigger_note_script_code = format!( diff --git a/crates/miden-testing/tests/scripts/send_note.rs b/crates/miden-testing/tests/scripts/send_note.rs index 0655f4bdd5..0053ae3e5d 100644 --- a/crates/miden-testing/tests/scripts/send_note.rs +++ b/crates/miden-testing/tests/scripts/send_note.rs @@ -39,7 +39,8 @@ async fn test_send_note_script_basic_wallet() -> anyhow::Result<()> { let tag = NoteTag::with_account_target(sender_basic_wallet_account.id()); let elements = [9, 8, 7, 6, 5u32].map(Felt::from).to_vec(); let attachment = NoteAttachment::new_array(NoteAttachmentScheme::new(42), elements.clone())?; - let metadata = NoteMetadata::new(sender_basic_wallet_account.id(), NoteType::Public, tag) + let metadata = NoteMetadata::new(sender_basic_wallet_account.id(), NoteType::Public) + .with_tag(tag) .with_attachment(attachment.clone()); let assets = NoteAssets::new(vec![sent_asset]).unwrap(); let note_script = CodeBuilder::default().compile_note_script("begin nop end").unwrap(); @@ -97,7 +98,8 @@ async fn test_send_note_script_basic_fungible_faucet() -> anyhow::Result<()> { let tag = NoteTag::with_account_target(sender_basic_fungible_faucet_account.id()); let attachment = NoteAttachment::new_word(NoteAttachmentScheme::new(100), Word::empty()); let metadata = - NoteMetadata::new(sender_basic_fungible_faucet_account.id(), NoteType::Public, tag) + NoteMetadata::new(sender_basic_fungible_faucet_account.id(), NoteType::Public) + .with_tag(tag) .with_attachment(attachment); let assets = NoteAssets::new(vec![Asset::Fungible( FungibleAsset::new(sender_basic_fungible_faucet_account.id(), 10).unwrap(), diff --git a/crates/miden-testing/tests/scripts/swap.rs b/crates/miden-testing/tests/scripts/swap.rs index c26d236d30..463cfff6d6 100644 --- a/crates/miden-testing/tests/scripts/swap.rs +++ b/crates/miden-testing/tests/scripts/swap.rs @@ -348,7 +348,7 @@ pub fn create_p2id_note_exact( let tag = NoteTag::with_account_target(target); - let metadata = NoteMetadata::new(sender, note_type, tag); + let metadata = NoteMetadata::new(sender, note_type).with_tag(tag); let vault = NoteAssets::new(assets)?; Ok(Note::new(vault, metadata, recipient)) diff --git a/crates/miden-tx/src/host/tx_event.rs b/crates/miden-tx/src/host/tx_event.rs index d6fe1b73d6..94151e560d 100644 --- a/crates/miden-tx/src/host/tx_event.rs +++ b/crates/miden-tx/src/host/tx_event.rs @@ -724,7 +724,7 @@ fn build_note_metadata( .map_err(|_| TransactionKernelError::other("failed to decode note tag into u32")) .map(NoteTag::new)?; - Ok(NoteMetadata::new(sender, note_type, tag)) + Ok(NoteMetadata::new(sender, note_type).with_tag(tag)) } fn extract_note_attachment( From 1d33a1dab22ce4479dc539f1492b2b91af052f13 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 21:19:58 +0000 Subject: [PATCH 2/5] Change NoteMetadata constructor to not take tag by default - Modified NoteMetadata::new() to only take sender and note_type - Added with_tag() method for setting tag explicitly - Updated all call sites across protocol, testing, standards, tx, and agglayer crates - Tag now defaults to NoteTag::default() if not explicitly set Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com> --- crates/miden-agglayer/src/lib.rs | 3 ++- crates/miden-standards/src/account/interface/test.rs | 8 ++++---- crates/miden-standards/src/note/burn.rs | 2 +- crates/miden-standards/src/note/mint.rs | 2 +- crates/miden-standards/src/note/p2id.rs | 2 +- crates/miden-standards/src/note/p2ide.rs | 2 +- crates/miden-standards/src/note/swap.rs | 2 +- crates/miden-standards/src/testing/note.rs | 2 +- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/miden-agglayer/src/lib.rs b/crates/miden-agglayer/src/lib.rs index 6905e776a9..7f65265a14 100644 --- a/crates/miden-agglayer/src/lib.rs +++ b/crates/miden-agglayer/src/lib.rs @@ -482,7 +482,8 @@ pub fn create_claim_note(params: ClaimNoteParams<'_, R>) -> Result Date: Sun, 1 Feb 2026 21:28:49 +0000 Subject: [PATCH 3/5] Fix formatting and missed call site Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com> --- crates/miden-protocol/src/note/file.rs | 3 +-- crates/miden-protocol/src/note/metadata.rs | 7 ++++--- crates/miden-standards/src/note/burn.rs | 3 ++- crates/miden-standards/src/note/mint.rs | 3 ++- crates/miden-standards/src/note/p2id.rs | 3 ++- crates/miden-standards/src/note/p2ide.rs | 3 ++- crates/miden-standards/src/note/swap.rs | 5 +++-- crates/miden-standards/src/testing/note.rs | 3 ++- crates/miden-testing/src/kernel_tests/tx/test_note.rs | 9 +++++---- .../src/kernel_tests/tx/test_output_note.rs | 11 +++++------ crates/miden-testing/src/kernel_tests/tx/test_tx.rs | 10 ++++++---- .../src/standards/network_account_target.rs | 7 +++---- crates/miden-testing/tests/scripts/send_note.rs | 7 +++---- 13 files changed, 40 insertions(+), 34 deletions(-) diff --git a/crates/miden-protocol/src/note/file.rs b/crates/miden-protocol/src/note/file.rs index 617182c35c..4a0d21001b 100644 --- a/crates/miden-protocol/src/note/file.rs +++ b/crates/miden-protocol/src/note/file.rs @@ -171,8 +171,7 @@ mod tests { let recipient = NoteRecipient::new(serial_num, script, note_storage); let asset = Asset::Fungible(FungibleAsset::new(faucet, 100).unwrap()); - let metadata = NoteMetadata::new(faucet, NoteType::Public) - .with_tag(NoteTag::from(123)); + let metadata = NoteMetadata::new(faucet, NoteType::Public).with_tag(NoteTag::from(123)); Note::new(NoteAssets::new(vec![asset]).unwrap(), metadata, recipient) } diff --git a/crates/miden-protocol/src/note/metadata.rs b/crates/miden-protocol/src/note/metadata.rs index 933a2f5102..044cd83007 100644 --- a/crates/miden-protocol/src/note/metadata.rs +++ b/crates/miden-protocol/src/note/metadata.rs @@ -77,8 +77,8 @@ impl NoteMetadata { // -------------------------------------------------------------------------------------------- /// Returns a new [`NoteMetadata`] instantiated with the specified parameters. - /// - /// The tag defaults to [`NoteTag::default()`]. Use [`NoteMetadata::with_tag`] to set a + /// + /// The tag defaults to [`NoteTag::default()`]. Use [`NoteMetadata::with_tag`] to set a /// specific tag if needed. pub fn new(sender: AccountId, note_type: NoteType) -> Self { Self { @@ -365,7 +365,8 @@ mod tests { let sender = AccountId::try_from(ACCOUNT_ID_MAX_ONES).unwrap(); let note_type = NoteType::Public; let tag = NoteTag::new(u32::MAX); - let metadata = NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); // Serialization Roundtrip let deserialized = NoteMetadata::read_from_bytes(&metadata.to_bytes())?; diff --git a/crates/miden-standards/src/note/burn.rs b/crates/miden-standards/src/note/burn.rs index 1d21c39e28..162d6b0a54 100644 --- a/crates/miden-standards/src/note/burn.rs +++ b/crates/miden-standards/src/note/burn.rs @@ -94,7 +94,8 @@ impl BurnNote { let inputs = NoteStorage::new(vec![])?; let tag = NoteTag::with_account_target(faucet_id); - let metadata = NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let assets = NoteAssets::new(vec![fungible_asset])?; // BURN notes contain the asset to burn let recipient = NoteRecipient::new(serial_num, note_script, inputs); diff --git a/crates/miden-standards/src/note/mint.rs b/crates/miden-standards/src/note/mint.rs index ddf5ff3403..32f7ca477e 100644 --- a/crates/miden-standards/src/note/mint.rs +++ b/crates/miden-standards/src/note/mint.rs @@ -99,7 +99,8 @@ impl MintNote { let tag = NoteTag::with_account_target(faucet_id); - let metadata = NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let assets = NoteAssets::new(vec![])?; // MINT notes have no assets let recipient = NoteRecipient::new(serial_num, note_script, storage); diff --git a/crates/miden-standards/src/note/p2id.rs b/crates/miden-standards/src/note/p2id.rs index c21dd52852..741f20adc5 100644 --- a/crates/miden-standards/src/note/p2id.rs +++ b/crates/miden-standards/src/note/p2id.rs @@ -82,7 +82,8 @@ impl P2idNote { let tag = NoteTag::with_account_target(target); - let metadata = NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let vault = NoteAssets::new(assets)?; Ok(Note::new(vault, metadata, recipient)) diff --git a/crates/miden-standards/src/note/p2ide.rs b/crates/miden-standards/src/note/p2ide.rs index f55bccaace..1b580c3101 100644 --- a/crates/miden-standards/src/note/p2ide.rs +++ b/crates/miden-standards/src/note/p2ide.rs @@ -87,7 +87,8 @@ impl P2ideNote { let recipient = Self::build_recipient(target, reclaim_height, timelock_height, serial_num)?; let tag = NoteTag::with_account_target(target); - let metadata = NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let vault = NoteAssets::new(assets)?; Ok(Note::new(vault, metadata, recipient)) diff --git a/crates/miden-standards/src/note/swap.rs b/crates/miden-standards/src/note/swap.rs index b8f31b05c9..a1ea06fe8b 100644 --- a/crates/miden-standards/src/note/swap.rs +++ b/crates/miden-standards/src/note/swap.rs @@ -114,8 +114,9 @@ impl SwapNote { let serial_num = rng.draw_word(); // build the outgoing note - let metadata = - NoteMetadata::new(sender, swap_note_type).with_tag(tag).with_attachment(swap_note_attachment); + let metadata = NoteMetadata::new(sender, swap_note_type) + .with_tag(tag) + .with_attachment(swap_note_attachment); let assets = NoteAssets::new(vec![offered_asset])?; let recipient = NoteRecipient::new(serial_num, note_script, inputs); let note = Note::new(assets, metadata, recipient); diff --git a/crates/miden-standards/src/testing/note.rs b/crates/miden-standards/src/testing/note.rs index f64834fe66..cc077e35ef 100644 --- a/crates/miden-standards/src/testing/note.rs +++ b/crates/miden-standards/src/testing/note.rs @@ -149,7 +149,8 @@ impl NoteBuilder { .compile_note_script(virtual_source_file) .expect("note script should compile"); let vault = NoteAssets::new(self.assets)?; - let metadata = NoteMetadata::new(self.sender, self.note_type).with_tag(self.tag) + let metadata = NoteMetadata::new(self.sender, self.note_type) + .with_tag(self.tag) .with_attachment(self.attachment); let storage = NoteStorage::new(self.storage)?; let recipient = NoteRecipient::new(self.serial_num, note_script, storage); diff --git a/crates/miden-testing/src/kernel_tests/tx/test_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_note.rs index 55a79ad364..ae97fa739f 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_note.rs @@ -381,9 +381,10 @@ async fn test_build_metadata_header() -> anyhow::Result<()> { let receiver = AccountId::try_from(ACCOUNT_ID_REGULAR_PRIVATE_ACCOUNT_UPDATABLE_CODE) .map_err(|e| anyhow::anyhow!("Failed to convert account ID: {}", e))?; - let test_metadata1 = - NoteMetadata::new(sender, NoteType::Private).with_tag(NoteTag::with_account_target(receiver)); - let test_metadata2 = NoteMetadata::new(sender, NoteType::Public).with_tag(NoteTag::new(u32::MAX)); + let test_metadata1 = NoteMetadata::new(sender, NoteType::Private) + .with_tag(NoteTag::with_account_target(receiver)); + let test_metadata2 = + NoteMetadata::new(sender, NoteType::Public).with_tag(NoteTag::new(u32::MAX)); for (iteration, test_metadata) in [test_metadata1, test_metadata2].into_iter().enumerate() { let code = format!( @@ -524,7 +525,7 @@ async fn test_public_key_as_note_input() -> anyhow::Result<()> { let serial_num = RpoRandomCoin::new(Word::from([1, 2, 3, 4u32])).draw_word(); let tag = NoteTag::with_account_target(target_account.id()); - let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![])?; let note_script = CodeBuilder::default().compile_note_script("begin nop end")?; let recipient = diff --git a/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs index f2fffc33db..714aa5b493 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs @@ -250,8 +250,8 @@ async fn test_get_output_notes_commitment() -> anyhow::Result<()> { let output_serial_no_1 = Word::from([8u32; 4]); let output_tag_1 = NoteTag::with_account_target(network_account); let assets = NoteAssets::new(vec![input_asset_1])?; - let metadata = - NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public).with_tag(output_tag_1); + let metadata = NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public) + .with_tag(output_tag_1); let inputs = NoteStorage::new(vec![])?; let recipient = NoteRecipient::new(output_serial_no_1, input_note_1.script().clone(), inputs); let output_note_1 = Note::new(assets, metadata, recipient); @@ -264,10 +264,9 @@ async fn test_get_output_notes_commitment() -> anyhow::Result<()> { NoteAttachmentScheme::new(5), [42, 43, 44, 45, 46u32].map(Felt::from).to_vec(), )?; - let metadata = - NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public) - .with_tag(output_tag_2) - .with_attachment(attachment); + let metadata = NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public) + .with_tag(output_tag_2) + .with_attachment(attachment); let inputs = NoteStorage::new(vec![])?; let recipient = NoteRecipient::new(output_serial_no_2, input_note_2.script().clone(), inputs); let output_note_2 = Note::new(assets, metadata, recipient); diff --git a/crates/miden-testing/src/kernel_tests/tx/test_tx.rs b/crates/miden-testing/src/kernel_tests/tx/test_tx.rs index f98ea2e190..126e493bd7 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_tx.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_tx.rs @@ -223,8 +223,9 @@ async fn executed_transaction_output_notes() -> anyhow::Result<()> { let serial_num_2 = Word::from([1, 2, 3, 4u32]); let note_script_2 = CodeBuilder::default().compile_note_script(DEFAULT_NOTE_CODE)?; let inputs_2 = NoteStorage::new(vec![ONE])?; - let metadata_2 = - NoteMetadata::new(account_id, note_type2).with_tag(tag2).with_attachment(attachment2.clone()); + let metadata_2 = NoteMetadata::new(account_id, note_type2) + .with_tag(tag2) + .with_attachment(attachment2.clone()); let vault_2 = NoteAssets::new(vec![removed_asset_3, removed_asset_4])?; let recipient_2 = NoteRecipient::new(serial_num_2, note_script_2, inputs_2); let expected_output_note_2 = Note::new(vault_2, metadata_2, recipient_2); @@ -233,8 +234,9 @@ async fn executed_transaction_output_notes() -> anyhow::Result<()> { let serial_num_3 = Word::from([Felt::new(5), Felt::new(6), Felt::new(7), Felt::new(8)]); let note_script_3 = CodeBuilder::default().compile_note_script(DEFAULT_NOTE_CODE)?; let inputs_3 = NoteStorage::new(vec![ONE, Felt::new(2)])?; - let metadata_3 = - NoteMetadata::new(account_id, note_type3).with_tag(tag3).with_attachment(attachment3.clone()); + let metadata_3 = NoteMetadata::new(account_id, note_type3) + .with_tag(tag3) + .with_attachment(attachment3.clone()); let vault_3 = NoteAssets::new(vec![])?; let recipient_3 = NoteRecipient::new(serial_num_3, note_script_3, inputs_3); let expected_output_note_3 = Note::new(vault_3, metadata_3, recipient_3); diff --git a/crates/miden-testing/src/standards/network_account_target.rs b/crates/miden-testing/src/standards/network_account_target.rs index 3550fdadac..e3d0b0f798 100644 --- a/crates/miden-testing/src/standards/network_account_target.rs +++ b/crates/miden-testing/src/standards/network_account_target.rs @@ -16,10 +16,9 @@ async fn network_account_target_get_id() -> anyhow::Result<()> { let exec_hint = NoteExecutionHint::Always; let attachment = NoteAttachment::from(NetworkAccountTarget::new(target_id, exec_hint)?); - let metadata = - NoteMetadata::new(target_id, NoteType::Public) - .with_tag(NoteTag::with_account_target(target_id)) - .with_attachment(attachment.clone()); + let metadata = NoteMetadata::new(target_id, NoteType::Public) + .with_tag(NoteTag::with_account_target(target_id)) + .with_attachment(attachment.clone()); let metadata_header = metadata.to_header_word(); let source = format!( diff --git a/crates/miden-testing/tests/scripts/send_note.rs b/crates/miden-testing/tests/scripts/send_note.rs index 0053ae3e5d..35ef74b57f 100644 --- a/crates/miden-testing/tests/scripts/send_note.rs +++ b/crates/miden-testing/tests/scripts/send_note.rs @@ -97,10 +97,9 @@ async fn test_send_note_script_basic_fungible_faucet() -> anyhow::Result<()> { let tag = NoteTag::with_account_target(sender_basic_fungible_faucet_account.id()); let attachment = NoteAttachment::new_word(NoteAttachmentScheme::new(100), Word::empty()); - let metadata = - NoteMetadata::new(sender_basic_fungible_faucet_account.id(), NoteType::Public) - .with_tag(tag) - .with_attachment(attachment); + let metadata = NoteMetadata::new(sender_basic_fungible_faucet_account.id(), NoteType::Public) + .with_tag(tag) + .with_attachment(attachment); let assets = NoteAssets::new(vec![Asset::Fungible( FungibleAsset::new(sender_basic_fungible_faucet_account.id(), 10).unwrap(), )])?; From c1feb17e8308579da9ed15dbdb3e3d442a3f7ab2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 21:29:33 +0000 Subject: [PATCH 4/5] Improve documentation for mutator methods Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com> --- crates/miden-protocol/src/note/metadata.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/miden-protocol/src/note/metadata.rs b/crates/miden-protocol/src/note/metadata.rs index 044cd83007..d21afc4c3a 100644 --- a/crates/miden-protocol/src/note/metadata.rs +++ b/crates/miden-protocol/src/note/metadata.rs @@ -156,23 +156,27 @@ impl NoteMetadata { // MUTATORS // -------------------------------------------------------------------------------------------- - /// Overwrites the note's tag with the provided one. + /// Mutates the note's tag by setting it to the provided value. pub fn set_tag(&mut self, tag: NoteTag) { self.tag = tag; } - /// Overwrites the note's tag with the provided one. + /// Returns a new [`NoteMetadata`] with the tag set to the provided value. + /// + /// This is a builder method that consumes self and returns a new instance for method chaining. pub fn with_tag(mut self, tag: NoteTag) -> Self { self.tag = tag; self } - /// Overwrites the note's attachment with the provided one. + /// Mutates the note's attachment by setting it to the provided value. pub fn set_attachment(&mut self, attachment: NoteAttachment) { self.attachment = attachment; } - /// Overwrites the note's attachment with the provided one. + /// Returns a new [`NoteMetadata`] with the attachment set to the provided value. + /// + /// This is a builder method that consumes self and returns a new instance for method chaining. pub fn with_attachment(mut self, attachment: NoteAttachment) -> Self { self.attachment = attachment; self From 9de85f1e4fa836a86bfdf15ebb9add345fc8bcb7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 22:01:37 +0000 Subject: [PATCH 5/5] Add changelog entry for PR #2384 Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com> --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9972fe5b31..47fa046a5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Changes - [BREAKING] Prefixed transaction kernel events with `miden::protocol` ([#2364](https://github.com/0xMiden/miden-base/pull/2364)). +- [BREAKING] Simplified `NoteMetadata::new()` constructor to not require tag parameter; tag defaults to zero and can be set via `with_tag()` builder method ([#2384](https://github.com/0xMiden/miden-base/pull/2384)). - [BREAKING] Renamed `WellKnownComponent` to `StandardAccountComponent`, `WellKnownNote` to `StandardNote`, and `WellKnownNoteAttachment` to `StandardNoteAttachment` ([#2332](https://github.com/0xMiden/miden-base/pull/2332)). - Skip requests to the `DataStore` for asset vault witnesses which are already in transaction inputs ([#2298](https://github.com/0xMiden/miden-base/pull/2298)). - [BREAKING] Refactored `TransactionAuthenticator::get_public_key()` method to return `Arc `instead of `&PublicKey` ([#2304](https://github.com/0xMiden/miden-base/pull/2304)).