Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
947c455
feat: wip get_note_script()
partylikeits1983 Oct 8, 2025
78e7a36
refactor: simplify test
partylikeits1983 Oct 8, 2025
333e477
Merge branch 'next' into ajl-get-note-script-datastore
partylikeits1983 Oct 8, 2025
a4cc600
Merge branch 'next' into ajl-get-note-script-datastore
partylikeits1983 Oct 9, 2025
c9ed0b2
wip
partylikeits1983 Oct 10, 2025
aa47af7
feat: it works :)
partylikeits1983 Oct 10, 2025
85905b3
updates
partylikeits1983 Oct 10, 2025
ae76d56
wip
partylikeits1983 Oct 10, 2025
88e5f57
chore: merge next & cleanup
partylikeits1983 Oct 13, 2025
1c48bd1
refactor: cleanup
partylikeits1983 Oct 13, 2025
77f003f
refactor: cleanup host logic
partylikeits1983 Oct 13, 2025
56c3865
refactor: cleanup
partylikeits1983 Oct 13, 2025
286a665
fix: rm debug mode
partylikeits1983 Oct 13, 2025
3f06267
fix: rm debug.stack
partylikeits1983 Oct 13, 2025
d85e4e6
Update CHANGELOG.md
partylikeits1983 Oct 14, 2025
c9f549c
Update crates/miden-lib/asm/miden/note.masm
partylikeits1983 Oct 14, 2025
95ca790
refactor: optimize build_recipient proc
partylikeits1983 Oct 14, 2025
4f9b027
feat: document build_recipient proc
partylikeits1983 Oct 14, 2025
ee5787f
refactor: simplify host & cleanup test
partylikeits1983 Oct 14, 2025
602ec99
refactor: address refactor comments
partylikeits1983 Oct 14, 2025
55e99c5
feat: refactor on_note_script_requested
partylikeits1983 Oct 14, 2025
1aafcc2
feat: use locaddr in build_recipient
partylikeits1983 Oct 14, 2025
bc82716
feat: rename format_for_advice to to_elements
partylikeits1983 Oct 14, 2025
24985a2
Merge branch 'next' into ajl-public-output-note-ntx
partylikeits1983 Oct 15, 2025
e3c9289
wip: simplify script_root extraction in on_note_after_created
partylikeits1983 Oct 15, 2025
9ee1ef9
feat: pass modified AdviceMap to NoteBuilder & cleanup
partylikeits1983 Oct 15, 2025
53f0c8d
refactor: cleanup miden::note masm
partylikeits1983 Oct 16, 2025
2b01c4f
refactor: simplify OutputNoteBuilder construction by removing AdviceP…
partylikeits1983 Oct 16, 2025
7e562fa
refactor: remove redundant note index validation in on_note_after_cre…
partylikeits1983 Oct 16, 2025
f610ae9
Merge branch 'next' into ajl-public-output-note-ntx
partylikeits1983 Oct 16, 2025
5fee2e8
fix: changelog
partylikeits1983 Oct 16, 2025
9a99eac
refactor: update build_recipient doc comments
partylikeits1983 Oct 16, 2025
14237c5
refactor: simplify local memory read write addresses
partylikeits1983 Oct 20, 2025
38e7701
chore: merge next
partylikeits1983 Oct 27, 2025
611608a
refactor: add RECIPIENT_DATA_ADVICE_STACK_LENGTH const to build_recip…
partylikeits1983 Oct 27, 2025
dd0b31f
refactor: replace AccountId::dummy with ACCOUNT_ID_PRIVATE_SENDER
partylikeits1983 Oct 27, 2025
6ea0d17
Update crates/miden-lib/asm/miden/note.masm
partylikeits1983 Oct 28, 2025
03b452d
refactor: reset changelog.md, build.rs & rm println! statements
partylikeits1983 Oct 28, 2025
fc20f89
Update crates/miden-lib/asm/miden/note.masm
partylikeits1983 Oct 29, 2025
f4f62ad
refactor: fix locals doc comment for build_recipient proc
partylikeits1983 Oct 29, 2025
c6ef424
refactor: replace is_none/unwrap with let-else pattern
partylikeits1983 Oct 29, 2025
acff08f
refactor: improve type safety and validation in note handling
partylikeits1983 Oct 29, 2025
c2f4ea3
refactor: validate recipient digest in OutputNoteBuilder
partylikeits1983 Oct 29, 2025
be77f21
refactor: consolidate note builder insertion logic
partylikeits1983 Oct 29, 2025
0575f40
refactor: remove redundant public note validation
partylikeits1983 Oct 29, 2025
f7022d3
fix: clippy
partylikeits1983 Oct 29, 2025
f341d47
refactor: add explanatory comment about script fetching in faucet test
partylikeits1983 Oct 29, 2025
6838137
refactor: use NoteBuilder in faucet test
partylikeits1983 Oct 29, 2025
7def703
refactor: improve error handling and simplify note construction
partylikeits1983 Oct 29, 2025
7c70e10
refactor: remove ProcessState parameter from on_note_script_requested
partylikeits1983 Oct 30, 2025
390401a
refactor: rm full import paths
partylikeits1983 Oct 30, 2025
2900169
Merge branch 'next' into ajl-public-output-note-ntx
partylikeits1983 Oct 30, 2025
3415196
chore: merge next & resolve conflicts
partylikeits1983 Oct 30, 2025
a944611
refactor: restructure build_recipient advice map layout
partylikeits1983 Oct 30, 2025
df692a1
refactor: revert change back to format_for_advice()
partylikeits1983 Oct 30, 2025
7b42e70
refactor: rm RECIPIENT_DATA_ADVICE_STACK_LENGTH const in note.masm
partylikeits1983 Oct 30, 2025
9b430fa
refactor: rm full import path of DataStoreError
partylikeits1983 Oct 30, 2025
215e132
refactor: simplify test to use build_p2id_recipient instead of buildi…
partylikeits1983 Oct 30, 2025
0133dca
refactor: cleanup implementation of on_note_after_created
partylikeits1983 Oct 30, 2025
93ca303
refactor: refactor NoteRecipient::to_advice_map_entries
partylikeits1983 Oct 30, 2025
cfd02f6
refactor: simplify on_note_script_requested()
partylikeits1983 Oct 30, 2025
59ab872
refactor: rm duplicate dupw in note.masm
partylikeits1983 Oct 31, 2025
440c2da
refactor: inline note recipient advice map logic and rename NoteScrip…
partylikeits1983 Oct 31, 2025
c2cb098
refactor: add read_double_word_from_adv_map() helper fn to simplify …
partylikeits1983 Oct 31, 2025
192c95a
refactor: improve on_note_after_created() doc comment to clarify cond…
partylikeits1983 Oct 31, 2025
cc1e84e
refactor: refactor: implement trial unhashing for note input extracti…
partylikeits1983 Oct 31, 2025
cf540d6
fix: clippy
partylikeits1983 Oct 31, 2025
893b92a
Update crates/miden-lib/build.rs
partylikeits1983 Nov 1, 2025
6fa2ff2
refactor: simplify build_recipient & rm loc memory
partylikeits1983 Nov 1, 2025
398a8be
refactor: rm leftover unused functions
partylikeits1983 Nov 1, 2025
4c1f38a
refactor: simplify add_output_note_recipient
partylikeits1983 Nov 1, 2025
2ca4e02
refactor: make read_double_word_from_adv_map free fn
partylikeits1983 Nov 1, 2025
38a5d62
refactor: fix comment in add_output_note_recipient fn
partylikeits1983 Nov 1, 2025
b168baf
refactor: revert regression to format_for_advice
partylikeits1983 Nov 1, 2025
cd4a76f
refactor: expand SN abbreviation to SERIAL in comments for clarity
partylikeits1983 Nov 1, 2025
ee6441d
Merge branch 'next' into ajl-public-output-note-ntx
partylikeits1983 Nov 1, 2025
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 @@ -42,6 +42,7 @@
- Re-add bech32 encoding for `AccountId` ([#2018](https://github.com/0xMiden/miden-base/pull/2018)).
- [BREAKING] Change `AccountTree` to be generic over `Smt` implementations ([#2006](https://github.com/0xMiden/miden-base/pull/2006)).
- [BREAKING] Change `AccountTree` to be generic over `trait AccountTreeBackend` implementations ([#2006](https://github.com/0xMiden/miden-base/pull/2006)).
- [BREAKING] Added `get_note_script()` method to `DataStore` trait to enable lazy loading of note scripts during transaction execution ([#1995](https://github.com/0xMiden/miden-base/pull/1995)).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was done in #1981
I guess we need a new entry for the current PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of. That PR didn't have a changelog entry, and this PR finalizes the functionality outlined in the changelog entry.

- [BREAKING] Separate account APIs in `miden::account` into `active_account` and `native_account` ([#2026](https://github.com/0xMiden/miden-base/pull/2026)).
- [BREAKING] Remove `miden::account::get_native_nonce` procedure ([#2026](https://github.com/0xMiden/miden-base/pull/2026)).

Expand Down
60 changes: 49 additions & 11 deletions crates/miden-lib/asm/miden/note.masm
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use.miden::account_id
use.std::crypto::hashes::rpo
use.std::mem

use.miden::account_id

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

Expand Down Expand Up @@ -56,7 +55,7 @@ end
#! - max_inputs_per_note is the max inputs per note.
export.::miden::util::note::get_max_inputs_per_note

#! Writes the assets data stored in the advice map to the memory specified by the provided
#! Writes the assets data stored in the advice map to the memory specified by the provided
#! destination pointer.
#!
#! Inputs:
Expand Down Expand Up @@ -91,31 +90,70 @@ end
#! Builds the recipient hash from note inputs, script root, and serial number.
#!
#! This procedure computes the commitment of the note inputs and then uses it to calculate the note
#! recipient by hashing this commit, the provided script root, and the serial number.
#! recipient by hashing this commitment, the provided script root, and the serial number.
#!
#! Inputs: [inputs_ptr, num_inputs, SERIAL_NUM, SCRIPT_ROOT]
#! Outputs: [RECIPIENT]
#! Inputs:
#! Operand stack: [inputs_ptr, num_inputs, SERIAL_NUM, SCRIPT_ROOT]
#! Advice map: {
#! INPUTS_COMMITMENT: [INPUTS],
#! }
#! Outputs:
#! Operand stack: [RECIPIENT]
#! Advice map: {
#! INPUTS_COMMITMENT: [INPUTS],
#! RECIPIENT: [SERIAL_SCRIPT_HASH, INPUTS_COMMITMENT],
#! SERIAL_SCRIPT_HASH: [SERIAL_HASH, SCRIPT_ROOT],
#! SERIAL_HASH: [SERIAL_NUM, EMPTY_WORD],
#! }
#!
#! Where:
#! - inputs_ptr is the memory address where the note inputs are stored.
#! - num_inputs is the number of input values.
#! - SCRIPT_ROOT is the script root of the note.
#! - SERIAL_NUM is the serial number of the note.
#! - RECIPIENT is the commitment to the input note's script, inputs, the serial number.
#! - RECIPIENT is the commitment to the input note's script, inputs, and the serial number.
#!
#! Locals:
#! - 0: inputs_ptr
#! - 1: num_inputs
#!
#! Panics if:
#! - inputs_ptr is not word-aligned (i.e., is not a multiple of 4).
#! - num_inputs is greater than 128.
#!
#! Invocation: exec
export.build_recipient
dup.1 dup.1
# => [inputs_ptr, num_inputs, inputs_ptr, num_inputs, SERIAL_NUM, SCRIPT_ROOT]

exec.compute_inputs_commitment
# => [INPUTS_HASH, SERIAL_NUM, SCRIPT_ROOT]
# => [INPUTS_COMMITMENT, inputs_ptr, num_inputs, SERIAL_NUM, SCRIPT_ROOT]

movup.5 movup.5 dup movdn.2
# => [inputs_ptr, num_inputs, inputs_ptr, INPUTS_COMMITMENT, SERIAL_NUM, SCRIPT_ROOT]

add swap
# => [inputs_ptr, end_ptr, INPUTS_COMMITMENT, SERIAL_NUM, SCRIPT_ROOT]

movdn.5 movdn.5
# => [INPUTS_COMMITMENT, inputs_ptr, end_ptr, SERIAL_NUM, SCRIPT_ROOT]

adv.insert_mem
# => [INPUTS_COMMITMENT, inputs_ptr, end_ptr, SERIAL_NUM, SCRIPT_ROOT]

movup.4 drop movup.4 drop
# => [INPUTS_COMMITMENT, SERIAL_NUM, SCRIPT_ROOT]

movdnw.2
# => [SERIAL_NUM, SCRIPT_ROOT, INPUTS_HASH]
# => [SERIAL_NUM, SCRIPT_ROOT, INPUTS_COMMITMENT]

padw adv.insert_hdword hmerge
# => [SERIAL_HASH, SCRIPT_ROOT, INPUTS_COMMITMENT]

swapw adv.insert_hdword hmerge
# => [SERIAL_SCRIPT_HASH, INPUTS_COMMITMENT]

exec.build_recipient_hash
swapw adv.insert_hdword hmerge
# => [RECIPIENT]
end

Expand Down Expand Up @@ -149,7 +187,7 @@ end
#!
#! Where:
#! - METADATA is the metadata of some note.
#! - sender_{prefix,suffix} are the prefix and suffix felts of the sender ID of the note which
#! - sender_{prefix,suffix} are the prefix and suffix felts of the sender ID of the note which
#! metadata was provided.
export.extract_sender_from_metadata
# => [aux, merged_tag_hint_payload, merged_sender_id_type_hint_tag, sender_id_prefix]
Expand Down
2 changes: 1 addition & 1 deletion crates/miden-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn compile_tx_kernel(source_dir: &Path, target_dir: &Path) -> Result<Assembler>
let output_file = target_dir.join("tx_kernel").with_extension(Library::LIBRARY_EXTENSION);
kernel_lib.write_to_file(output_file).into_diagnostic()?;

let assembler = build_assembler(Some(kernel_lib))?.with_debug_mode(true);
let assembler = build_assembler(Some(kernel_lib))?;

// assemble the kernel program and write it to the "tx_kernel.masb" file
let mut main_assembler = assembler.clone();
Expand Down
5 changes: 1 addition & 4 deletions crates/miden-lib/src/transaction/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,7 @@ impl TransactionAdviceInputs {
let note_arg = tx_inputs.tx_args().get_note_args(note.id()).unwrap_or(&EMPTY_WORD);

// recipient inputs / assets commitments
self.add_map_entry(
recipient.inputs().commitment(),
recipient.inputs().format_for_advice(),
);
self.add_map_entry(recipient.inputs().commitment(), recipient.inputs().to_elements());
self.add_map_entry(assets.commitment(), assets.to_padded_assets());

// note details / metadata
Expand Down
5 changes: 2 additions & 3 deletions crates/miden-objects/src/note/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ impl NoteInputs {
&self.values
}

/// Returns the note's input formatted to be used with the advice map.
/// Returns the note's input as a vector of field elements.
///
/// The format is `INPUTS || PADDING`, where:
///
/// Where:
/// - INPUTS is the variable inputs for the note
/// - PADDING is the optional padding to align the data with a 2WORD boundary
pub fn format_for_advice(&self) -> Vec<Felt> {
pub fn to_elements(&self) -> Vec<Felt> {
pad_inputs(&self.values)
}
}
Expand Down
21 changes: 0 additions & 21 deletions crates/miden-objects/src/note/recipient.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use alloc::vec::Vec;
use core::fmt::Debug;

use miden_crypto::Felt;

use super::{
ByteReader,
ByteWriter,
Expand Down Expand Up @@ -63,24 +60,6 @@ impl NoteRecipient {
pub fn digest(&self) -> Word {
self.digest
}

/// Returns the recipient formatted to be used with the advice map.
///
/// The format is `inputs_length || INPUTS_COMMITMENT || SCRIPT_ROOT || SERIAL_NUMBER`
///
/// Where:
/// - inputs_length is the length of the note inputs
/// - INPUTS_COMMITMENT is the commitment of the note inputs
/// - SCRIPT_ROOT is the commitment of the note script (i.e., the script's MAST root)
/// - SERIAL_NUMBER is the recipient's serial number
pub fn format_for_advice(&self) -> Vec<Felt> {
let mut result = Vec::with_capacity(13);
result.push(self.inputs.num_values().into());
result.extend(self.inputs.commitment());
result.extend(self.script.root());
result.extend(self.serial_num);
result
}
}

fn compute_recipient_digest(serial_num: Word, script: &NoteScript, inputs: &NoteInputs) -> Word {
Expand Down
27 changes: 21 additions & 6 deletions crates/miden-objects/src/transaction/tx_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ impl TransactionArgs {

/// Populates the advice inputs with the expected recipient data for creating output notes.
///
/// The advice inputs' map is extended with the following keys:
///
/// - recipient_digest |-> recipient details (inputs_hash, script_root, serial_num).
/// The advice inputs' map is extended with the following entries:
/// - RECIPIENT: [SERIAL_SCRIPT_HASH, INPUTS_COMMITMENT]
/// - SERIAL_SCRIPT_HASH: [SERIAL_HASH, SCRIPT_ROOT]
/// - SERIAL_HASH: [SERIAL_NUM, EMPTY_WORD]
/// - inputs_commitment |-> inputs.
/// - script_root |-> script.
pub fn add_output_note_recipient<T: AsRef<NoteRecipient>>(&mut self, note_recipient: T) {
Expand All @@ -165,9 +166,15 @@ impl TransactionArgs {
let script = note_recipient.script();
let script_encoded: Vec<Felt> = script.into();

let new_elements = [
(note_recipient.digest(), note_recipient.format_for_advice()),
(inputs.commitment(), inputs.format_for_advice()),
// Build the advice map entries
let sn_hash = Hasher::merge(&[note_recipient.serial_num(), Word::empty()]);
let sn_script_hash = Hasher::merge(&[sn_hash, script.root()]);

let new_elements = vec![
(sn_hash, concat_words(note_recipient.serial_num(), Word::empty())),
(sn_script_hash, concat_words(sn_hash, script.root())),
(note_recipient.digest(), concat_words(sn_script_hash, inputs.commitment())),
(inputs.commitment(), inputs.to_elements()),
(script.root(), script_encoded),
];

Expand Down Expand Up @@ -224,6 +231,14 @@ impl TransactionArgs {
}
}

/// Concatenates two [`Word`]s into a [`Vec<Felt>`] containing 8 elements.
fn concat_words(first: Word, second: Word) -> Vec<Felt> {
let mut result = Vec::with_capacity(8);
result.extend(first);
result.extend(second);
result
}

impl Default for TransactionArgs {
fn default() -> Self {
Self::new(AdviceMap::default())
Expand Down
4 changes: 2 additions & 2 deletions crates/miden-testing/src/tx_context/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ impl TransactionContextBuilder {
},
};

let tx_args = TransactionArgs::default().with_note_args(self.note_args);
let mut tx_args = TransactionArgs::default().with_note_args(self.note_args);

let mut tx_args = if let Some(tx_script) = self.tx_script {
tx_args = if let Some(tx_script) = self.tx_script {
tx_args.with_tx_script_and_args(tx_script, self.tx_script_args)
} else {
tx_args
Expand Down
Loading