Skip to content

Fix of the rounding up note inputs number#1399

Merged
Fumuran merged 5 commits intonextfrom
andrew-test-note-outputs
May 27, 2025
Merged

Fix of the rounding up note inputs number#1399
Fumuran merged 5 commits intonextfrom
andrew-test-note-outputs

Conversation

@Fumuran
Copy link
Copy Markdown
Contributor

@Fumuran Fumuran commented May 26, 2025

This PR:

  • fixes the bug in the miden::note::get_inputs assembly procedure where the real number of note inputs was rounded up to the next multiple of 8 incorrectly.
  • adds a small test checking the corner case which previously was handled wrongly — the case when the number of note inputs divides by 8.
  • adds additional asserts to the executed_transaction_output_notes test to check the number of note inputs in the output notes.

Closes: #1363

@Fumuran Fumuran added no changelog This PR does not require an entry in the `CHANGELOG.md` file no docs labels May 26, 2025
Comment on lines +301 to +307
//
// Notice that note input values are not loaded to the memory, only their length. On order to obtain
// the input values the advice map should be used: they are stored there as
// `INPUTS_COMMITMENT -> INPUTS || PADDING`.
//
// As opposed to the asset values, input values are never used in kernel memory, so their presence
// there is unnecessary.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As a side task I added a brief comment explaining why note inputs are not loaded to the memory, as it was discussed in the corresponding issue: #1355

Copy link
Copy Markdown
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Left some minor comments, but they are optional.

# => [num_words, INPUTS_COMMITMENT, num_inputs, dest_ptr]
# AS => [[INPUT_VALUES]]

# round up the number of words the next multiple of 2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# round up the number of words the next multiple of 2
# round up the number of words to the next multiple of 2

Nit

// - INPUTS_COMMITMENT is the key to look up note inputs in the advice map.
// - ASSETS_HASH is the key to look up note assets in the advice map.
//
// Notice that note input values are not loaded to the memory, only their length. On order to obtain
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Notice that note input values are not loaded to the memory, only their length. On order to obtain
// Notice that note input values are not loaded to the memory, only their length. In order to obtain

}

/// Value that represents under which condition a note can be consumed.
/// Note's recipient.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Note's recipient.
/// Returns the output note's recipient.
///
/// Note that the recipient is only present on [`OutputNote::Full`].

Suggestion

Comment on lines +382 to +383
# execute the `get_inputs` procedure to trigger note inputs number assertion
push.0 exec.note::get_inputs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would add an assertion here that num_inputs is 8.

end
";

tx_context.execute_code(tx_code).unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: For all new or updated tests I would change the return type of the test function to anyhow::Result<()> and then use .context("failed to do xyz")? instead of unwrap. If a test fails in the future, this leads to more easily readable errors and it's a way to dogfood our own errors to see if they are any good when debugging.

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I reviewed mostly non-test code, and left one small comment inline.

Comment on lines +198 to +201
/// Returns the output note's recipient.
///
/// See [crate::note::NoteRecipient] for more details.
pub fn recipient(&self) -> Option<&NoteRecipient> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would mention that this only works for Full output notes.

@bobbinth bobbinth linked an issue May 27, 2025 that may be closed by this pull request
@Fumuran Fumuran merged commit 8995ef2 into next May 27, 2025
16 checks passed
@Fumuran Fumuran deleted the andrew-test-note-outputs branch May 27, 2025 10:34
SantiagoPittella pushed a commit that referenced this pull request May 30, 2025
* test: add checks for inputs number of output notes

* refactor: rework rounding up inputs number, add test

* chore: add comment abount absence of note inputs in memory

* refactor: update docs and comments, return anyhow::Result from test

* chore: update function doc comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: implement a test where an output note is consumed as an input note Investigate moving note inputs to the memory

3 participants