Multiproof optimisations#173
Draft
ajhavlin wants to merge 22 commits into
Draft
Conversation
- Refactored CoPath::verify into smaller helpers (ingest_leaves, expected_leaf_coset, validate_leaf_copath, recompute_bottom_parents, recompute_inner_layers) to cut control-flow complexity. - Clarified iterator naming in verify (now leaves_iter) to avoid shadowing and improve readability. - Added brief doc comments to the new helpers to document their roles (leaf hashing, copath expectations/validation, and parent recomputation).
CoPath::verify could be crashed by a prover-controlled tree_height of 0 or 1, causing usize underflow in debug mode and attacker OOB access. - Validate tree_height >= 2 in extended CanonicalDeserialize trait so malformed proofs are rejected before a CoPath value is constructed - Restrict tree_height to pub(crate) so external code cannot mutate it after deserialization, preserving the invariant throughout the value's lifetime - Add expected_tree_height parameter to CoPath::verify, supplied by the verifier rather than read from the proof -> prevent height confusion attacks
…figures - Add scripts/ for presentation plot generation - Extend bench_report with coordinate encoding size benchmarks (natural vs leb128) - Fix error types in CoPath verification to use ark_std::io::Error - Apply rustfmt to mod.rs and tests - Add figures/ to .gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduce ImplicitCoPath as a leaner alternative to CoPath that drops all coordinate metadata (start_depth, start_index, deltas). Both prover and verifier derive copath positions from leaf_indexes and tree_height, so only the digests are transmitted in canonical depth-then-index order. Adds generate_implicit_multi_proof to MerkleTree and a full test suite covering single-leaf, full-batch, tampering, and edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…cripts Strip all benchmark-specific code from the merkle_tree module: - Remove legacy.rs (MultiPath front-incremental encoding, bench_harness only) - Remove tests/bench_report.rs (encoding comparison benchmarks) - Remove scripts/ (presentation plot generators) - Remove bench_harness feature flag and plotters dev-dependency - Fix multiproof_empty_batch test to expect Err (caller error per spec) The coordinate-based CoPath and coordinate-free ImplicitCoPath remain intact for production use. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove PackedInnerCopath, delta/varint encoding, pack_inner_copath, decode_inner_copath - Merge generate_implicit_multi_proof into generate_multi_proof - Delete implicit.rs (logic absorbed into CoPath) - Change helper visibility from pub(super) to private - Consolidate test suite; add six structural copath-count tests
This comment was marked as outdated.
This comment was marked as outdated.
z-tech
reviewed
Apr 14, 2026
z-tech
reviewed
Apr 14, 2026
| let mut index_in_tree = convert_index_to_last_level(leaf_index, tree_height); | ||
| index >>= 1; | ||
| index_in_tree = parent(index_in_tree).unwrap(); | ||
| assert!( |
Contributor
There was a problem hiding this comment.
Little roadmap here about verification
z-tech
reviewed
Apr 14, 2026
z-tech
reviewed
Apr 14, 2026
| if copath_iter.next().is_some() { | ||
| return Ok(false); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Maybe think about just one function for the time being that it's not clear what benefit this provides (and this purely readability).
z-tech
reviewed
Apr 14, 2026
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.
Description
Batch proof pruning: switch to CoSet multi-proof
This PR optimizes multiproofs within
Merkle_Tree. Inspired by the CoSet strategy described by Chiesa and Yogev, the proof that is transmit is compressed to the optimal set of digests by applying deduplication and excluding nodes along any of the individual computation paths.Motivation and old strategy (front-incremental / prefix encoding)
For example, verifying the set${\ I, J, L\ }$ with the prefix strategy in the following tree:
proceeds as follows:
prefix_length=suffix=prefix_length=suffix=prefix_length=suffix=New strategy: CoSet
Prefix encoding was transmitting redundant digests.
Consider a new strategy where, for a batch$I$ of leaf indexes, we define the on-path sets $A_j$ as the union across single-openings of parent nodes at depth $j$ , and define the minimal copath $B_j^$ as the nodes at depth $j$ that must be transmit for the verifier's checks, given that the verifier can compute $A_j$ ($B_j^ = \textsf{siblings}(A_j) \setminus A_j$).
Taking the example above:$\textsf{CoSet} = {\ D, H, M\ }$ , split as $= {\ M\ }$ and $= {\ D, H\ }$ .
leaf_copathinner_copathBoth the prover and verifier can independently recompute$A_j$ for all depths from
leaf_indexesandtree_heightalone, usingcompute_on_path. Therefore the proof needed is:Digests in$1$ ascending, depth $2$ ascending, …, depth $d-2$ ascending. The verifier reconstructs the same ordering, consumes the iterator, and rejects on any count mismatch.
inner_copathare emitted in canonical order: depthSecurity. The prover now only has the ability to choose the digests that it transmits. Therefore, any malicious choice of digests will reject so long as collision-resistance holds.
Proof size. Exactly $|B_\text{leaf}^| + |\bigcup_j B_j^|$ digests. This is at most$|I| \cdot (d - \log_2|I|) + |I| - 1$ digests in the most spread apart choice of $I$ , and is strictly smaller than the front-incremental scheme whenever opened leaves share on-path ancestors.
Implementation
CoPath.inner_copathis a flatVec<P::InnerDigest>, traversed from leaf level to root.Copath.leaf_copathis built in the same manner but left explicit to separate between theLeafHashandTwoToOneHashdomains. Additional proof supplements are onlytree_heightandleaf_indexes.MerkleTree::generate_multi_proofis the single entry point for batch proof generation.CoPath::verifyconsumesinner_copathvia an iterator;copath_iter.next().is_some()asserts exact exhaustion.inner_levelsis the sole authoritative map inverifyand the recompute helpers.CoPathimplements the batch proof logic directly; helpers (ingest_leaves,expected_leaf_coset,validate_leaf_copath,recompute_bottom_parents,recompute_inner_layers) are module-private.Test suite
field_mt_testscovers three categories:inner_copath.len()is met for the structures sharing a parent, having divergent paths, full subtrees, spread leaves, and all leaves.Benchmark Results
Benchmark comparisons for the two Merkle tree batching strategies were ran across various tree depths and opening structures.
Key outcomes:
Limitations
Security / correctness
Formal definitions of$A_j$ (on-path) and $B_j^*$ (minimal copath), the inductive reconstruction argument, and the collision-resistance binding are in Section. 29.2 of Building Cryptographic Proofs from Hash Functions (Chiesa and Yogev, 2024).
References
Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why.
Pendingsection inCHANGELOG.mdFiles changedin the Github PR explorer