feat(batch): construct BatchNoteTree during batch construction#3022
Draft
mmagician wants to merge 4 commits into
Draft
feat(batch): construct BatchNoteTree during batch construction#3022mmagician wants to merge 4 commits into
BatchNoteTree during batch construction#3022mmagician wants to merge 4 commits into
Conversation
Build a BatchNoteTree over the batch's final (non-erased) output notes in ProposedBatch::new_batch_inner, store it on ProposedBatch, expose it via a batch_note_tree() accessor, and include it in into_parts. This is the Rust-side foundation for the batch kernel outputting BATCH_NOTE_TREE_ROOT. Part of #3020.
mmagician
commented
Jun 1, 2026
Comment on lines
+66
to
+68
| /// The [`BatchNoteTree`] built over the batch's output notes, with note IDs packed at | ||
| /// contiguous leaf indices in the same order as `output_notes`. Its root is the batch's | ||
| /// note tree root. |
Collaborator
Author
There was a problem hiding this comment.
Suggested change
| /// The [`BatchNoteTree`] built over the batch's output notes, with note IDs packed at | |
| /// contiguous leaf indices in the same order as `output_notes`. Its root is the batch's | |
| /// note tree root. | |
| /// The [`BatchNoteTree`] built over the batch's output notes, with note IDs packed at | |
| /// contiguous leaf indices in the same order as `output_notes`. |
BatchNoteTree during batch construction
Propagate the BatchNoteTree root computed during batch construction onto ProvenBatch via a new note_tree_root field (serialization, new_unchecked, and note_tree_root() accessor), so the commitment flows to block construction and is ready for batch-kernel verification. LocalBatchProver passes the root from the ProposedBatch tree. Also renames the construction error variant to BatchNoteTreeConstructionFailed and adds an empty-output-notes batch tree test. Part of #3020.
Address review feedback: add a ProvenBatch serialization round-trip test asserting note_tree_root survives, assert batch_note_tree equality in the ProposedBatch round-trip test, and document that ProvenBatch::note_tree_root is unvalidated and must not be trusted at a trust boundary until a consumer binds it to the output notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First of two PRs for #3020. Wires the
BatchNoteTreeinto batch construction on the Rust side, the foundation needed before the batch kernel can output (and later verify)BATCH_NOTE_TREE_ROOTin MASM.The follow-up PR will wire these per-batch trees into block construction via
BlockNoteTree::insert_batch_note_subtreeand stop cross-batch note erasure.Changes
ProposedBatch::new_batch_innerbuilds aBatchNoteTree(viaBatchNoteTree::with_contiguous_leaves) over the batch's final, post-erasure output notes. The tree is stored onProposedBatch, exposed via abatch_note_tree()accessor, and included ininto_parts. Serialization is unchanged since deserialization deterministically reconstructs the batch vianew_batch_inner.ProvenBatchcarries the tree's root in a newnote_tree_rootfield, exposed vianote_tree_root(), so the commitment flows to block construction and is ready for batch-kernel verification.LocalBatchProverpasses the root from theProposedBatchtree. This changes theProvenBatchserialization format and thenew_uncheckedsignature ([BREAKING]).note_tree_rootis stored as-is and is not recomputed/checked againstoutput_notesbynew_uncheckedor deserialization; the doc comments warn it must not be trusted at a trust boundary until a consumer binds it. No current consumer trusts it (the block prover recomputes the tree from output notes).ProposedBatchError::BatchNoteTreeConstructionFailed(defensive; unreachable given theMAX_OUTPUT_NOTES_PER_BATCHbound equals the tree capacity).Tests
batch_note_tree_built_over_output_notes: tree root and leaf count match an independently built tree.batch_note_tree_excludes_erased_notes: notes erased within a batch are excluded from the tree.batch_note_tree_empty_when_no_output_notes: empty batch yields the empty-tree root;ProvenBatch::note_tree_root()matches.proven_batch_serialization_preserves_note_tree_root: round-trips aProvenBatchand asserts the root survives.proposed_batch_serializationto assertbatch_note_treeequality after the round-trip.Verified with
cargo test -p miden-protocol -p miden-tx-batch-prover, the batch and block kernel test suites, andmake lint.