Skip to content

feat(batch): construct BatchNoteTree during batch construction#3022

Draft
mmagician wants to merge 4 commits into
nextfrom
mmagician-claude/wire-batch-note-tree
Draft

feat(batch): construct BatchNoteTree during batch construction#3022
mmagician wants to merge 4 commits into
nextfrom
mmagician-claude/wire-batch-note-tree

Conversation

@mmagician

@mmagician mmagician commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

First of two PRs for #3020. Wires the BatchNoteTree into batch construction on the Rust side, the foundation needed before the batch kernel can output (and later verify) BATCH_NOTE_TREE_ROOT in MASM.

The follow-up PR will wire these per-batch trees into block construction via BlockNoteTree::insert_batch_note_subtree and stop cross-batch note erasure.

Changes

  • ProposedBatch::new_batch_inner builds a BatchNoteTree (via BatchNoteTree::with_contiguous_leaves) over the batch's final, post-erasure output notes. The tree is stored on ProposedBatch, exposed via a batch_note_tree() accessor, and included in into_parts. Serialization is unchanged since deserialization deterministically reconstructs the batch via new_batch_inner.
  • ProvenBatch carries the tree's root in a new note_tree_root field, exposed via note_tree_root(), so the commitment flows to block construction and is ready for batch-kernel verification. LocalBatchProver passes the root from the ProposedBatch tree. This changes the ProvenBatch serialization format and the new_unchecked signature ([BREAKING]).
    • note_tree_root is stored as-is and is not recomputed/checked against output_notes by new_unchecked or 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).
  • New error variant ProposedBatchError::BatchNoteTreeConstructionFailed (defensive; unreachable given the MAX_OUTPUT_NOTES_PER_BATCH bound 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 a ProvenBatch and asserts the root survives.
  • Extended proposed_batch_serialization to assert batch_note_tree equality after the round-trip.

Verified with cargo test -p miden-protocol -p miden-tx-batch-prover, the batch and block kernel test suites, and make lint.

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.
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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`.

@mmagician mmagician changed the title feat(batch): construct BatchNoteTree during batch construction feat(batch): construct BatchNoteTree during batch construction Jun 1, 2026
@mmagician mmagician added kernels Related to transaction, batch, or block kernels pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority labels Jun 1, 2026
claude added 3 commits June 1, 2026 13:54
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernels Related to transaction, batch, or block kernels pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants