Repository navigation
perf(halo2_proofs): Booth MSM, GLV IPA generator collapse, prefix instance commitments (verify −27–51%) - #2
PastaPastaPasta wants to merge 11 commits into
Conversation
Upstream subject: "Precompute MSM scalar representations". best_multiexp converted every scalar to its canonical representation once per window (33 Montgomery reductions per scalar for a 2^11 MSM); convert once per MSM instead. Applied cleanly onto halo2_proofs 0.3.2. Ported from zcash#937 ("Signed Booth recoding for multiexp", branch dw/booth-multiexp, commit c80ba53), itself upstreamed from https://github.com/zakura-core/libraries. Source-Commit: 1a3f293511fde465124752374c1b6785ef037d3f Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Upstream subject: "Use signed Booth recoding for multiexp". Recode each c-bit window into a signed digit in [-2^(c-1), 2^(c-1)], halving the bucket count per window (negating an affine base is free). The window above the scalar representation absorbs the final carry. Applied cleanly onto halo2_proofs 0.3.2. Ported from zcash#937 ("Signed Booth recoding for multiexp", branch dw/booth-multiexp, commit ab8c65e), itself upstreamed from https://github.com/zakura-core/libraries. Source-Commit: d974e1dc0f5ca8d07a290df7813eadabdb4eebfb Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Upstream subject: "Size Booth windows from scalar representations". Derive the window count from the representation length instead of assuming 256-bit scalars. Applied cleanly onto halo2_proofs 0.3.2. Ported from zcash#937 ("Signed Booth recoding for multiexp", branch dw/booth-multiexp, commit 1c69fa1), itself upstreamed from https://github.com/zakura-core/libraries. Source-Commit: 4bda24ea9860f54a71adbe209672c513342843db Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
pasta_curves 0.5.2 (zcash, crates.io, 2026-07-23) adds a `glv` module with variable-time GLV scalar multiplication for Pallas and Vesta, intended for public scalars. The next commit uses it to speed up the IPA generator collapse. The release also refactors Fp/Fq multiplication internally (mul_unreduced), with identical results. pasta_curves 0.5.2 requires Rust 1.63, so raise the MSRV of halo2_proofs and of the crates that depend on it (halo2, halo2_gadgets), and pin the workspace toolchain to 1.63.0 (verified: `cargo +1.63.0 check -p halo2_proofs -p halo2_gadgets --all-targets`). halo2_poseidon does not depend on halo2_proofs and keeps its 1.60 MSRV. Upstream zcash#927 made the same MSRV move for the same reason. Cargo.lock also picks up the halo2_gadgets 0.5.0 version that the lockfile had not been regenerated for. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each IPA round computes g_lo[i] + u_j * g_hi[i] for one challenge u_j shared by the whole half-vector, using the curve's generic double-and-add multiplication: ~255 doublings and ~255 additions per point, 2^k - 1 points per proof. For k = 11 this is most of the IPA opening (roughly 200 ms of the ~340 ms single-threaded opening). For Pallas and Vesta, use pasta_curves 0.5.2's GLV module instead: the challenge is decomposed and wNAF-recoded once per round (`Decomposed`), the per-point tables of odd multiples of P and phi(P) are built in batches that share one field inversion (`Table::batch`), and each point then costs ~128 doublings plus ~50 mixed additions. halo2_proofs is generic over CurveAffine and GlvParams is sealed to the Pasta curves, so the fast path is selected with an `Any` downcast of the generator vector; any other curve keeps the original code path. Collapse tasks are now at least 4 points, so the small late rounds also run in parallel (`parallelize` ran any round with fewer than threads^2 points serially). Security: this path is variable-time in the scalar. That is acceptable here because u_j is a public Fiat-Shamir challenge and G' depends only on the public parameters and earlier public challenges; no witness, blinding factor or key reaches parallel_generator_collapse. The same reasoning was given for upstream zcash#927 (ValarDragon, closed in favour of zakura-core/common#5), which this follows using the released pasta_curves API rather than the unreleased `batch_mul_same_scalar_vartime` hook. The results are exact group elements and are batch-normalized as before, so proofs are byte-for-byte identical. New tests compare the GLV path and the original path against a point-by-point reference for both curves, with identity points, doubling/cancelling pairs, and edge challenges (0, 1, -1, 2, 2^64-1, +-2^254, random), and check the dispatch. IPA opening for k = 11 (bench-msm `--mode ipa`, M4 Pro, heavily loaded host; medians): 14 threads 65-78 ms -> 23 ms, 6 threads ~50 ms -> ~27 ms, 1 thread 340 ms -> 225 ms. Transcript SHA-256 identical. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The parallel branch of best_multiexp shifted every window sum into place on its own (c * i doublings for window i) and then added them, i.e. c * W * (W - 1) / 2 doublings in total: 4224 for a 2^11 MSM (c = 8, W = 33), about 3% of the MSM's group operations. Compute the window sums in parallel and combine them with Horner's rule instead (acc = acc * 2^c + S_i), as the serial branch already did: c * (W - 1) doublings in total. The critical path is unchanged (the top window used to do the same 256 doublings inside its task), but total CPU drops, which matters when there are fewer cores than windows (e.g. 6 on iPhone). This removes the last user of multicore::TheBestReduce, so drop it. The result is the same group element, so proofs are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
best_multiexp is used by the verifier, so a wrong result could make it accept invalid proofs. Compare it against the naive sum of per-term scalar multiplications: - every length 0..=40 plus 63..65, 127..129, 255..257, 1023..1025 and 2049 on Vesta (and a spread of lengths on Pallas), each run under rayon pools of 1, 2, 3, 6, 14 and 64 threads so that both the serial and the parallel branch and the thread-count threshold are exercised, plus lengths 2980, 2981 and 8104 (window sizes 8, 9 and 10, as large or batched verifier MSMs use) under 1 and 6 threads; - random scalars, edge scalars interleaved with random ones, all-equal scalars and all-zero scalars; - edge scalars: 0, +-1, +-2, +-(2^c - 1), +-2^c, +-(2^(c-1) - 1), +-2^(c-1) and +-(2^(c-1) + 1) for every window size c in 1..=13, shifted to several window offsets; top-bit values; and all-ones / 0x80 / 0x7f / alternating byte patterns, positive and negated (i.e. near the modulus); - bases with identities, repeated points (bucket doubling) and negated points (bucket cancellation); - each edge scalar alone against a single base, so a wrong digit cannot be masked by the other terms. Mutating the Booth carry, the carry window count or the Horner doubling count each makes these tests fail. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The verifier zero-padded every instance column to the domain size (2^k) and committed to the padded vector with a full 2^k + 1 point MSM, although only the supplied prefix (9 values per Orchard action) can be non-zero. Commit to the prefix plus the blinding generator instead. Zero evaluations contribute the identity to the commitment, so the result is the same group element; the InstanceTooLarge check is unchanged and runs before the commitment, so the prefix always fits in g_lagrange. Zero padding via vk.domain.lagrange_from_vec also asserted that params and vk use the same domain size; keep that as an explicit assert. Adapted from zcash#929 commit 3250e8a ("Speed up verifier instance commitments", closed upstream in favour of the zakura-core stack): instead of a module-private commit_instance helper duplicated in the prover and the verifier, the shared helper is Params::commit_lagrange_prefix (pub(crate)), next to commit_lagrange, so the prover can reuse it (zcash#930). The test compares it with the zero-padded commit_lagrange for empty, short, internally-zero and full-length inputs and several blinds. Upstream measured 9-13% faster one-action Orchard verification (single-threaded, M4 Max) for this and the scalar-representation change together. Co-authored-by: Dev Ojha <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Public instance columns are prefix-populated and zero-padded to the evaluation domain. The prover passed the whole padded polynomial (2^k + 1 points) to the instance commitment MSM; commit to the supplied prefix plus the blinding generator instead (Params::commit_lagrange_prefix). The omitted trailing coefficients are all zero, so the commitment, and hence the proof, is unchanged. The padded polynomial is still built for interpolation, coset evaluation and opening, and the InstanceTooLarge check still runs before the commitment. Adapted from zcash#930 commit 7b22345 ("Avoid zero-padding prover instance commitments", closed upstream in favour of zakura-core/common#15), using the helper shared with the verifier instead of a second module-private copy. Co-authored-by: Dev Ojha <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each IPA round computed L and R as a multiexp over G' plus a separate two-term multiexp for [v * z] U + [r] W. A two-term best_multiexp uses 1-bit windows, so it costs about one full-width double-and-add (~0.1 ms); with 2k of them per opening that was ~2.3 ms for k = 11 regardless of the thread count (~7% of the 6-thread IPA opening after the GLV collapse). Append the two terms to the main multiexps instead, as the old TODO suggested. The randomness is drawn in the same order as before (the multiexps do not consume randomness), and the sums are the same group elements, so proofs are byte-for-byte unchanged. Side channels: p_prime and the blinding scalars already went through the same (variable-time) bucket multiexp, so nothing new is exposed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The Booth entry follows the one in zcash#937 (commit becadc6, Danny Willems), extended with the Horner fold. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
⛔ Files ignored due to path filters (1)
📒 Files selected for processing (15)
💤 Files with no reviewable changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe pull request raises the declared minimum Rust version to 1.63. It changes multiexponentiation to use signed Booth recoding, adds a Pasta GLV path for IPA generator collapse, and replaces zero-padded PLONK instance commitments with prefix commitments. ChangesProof-system updates
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant create_proof
participant multiexp_with_u_w
participant best_multiexp
create_proof->>multiexp_with_u_w: pass generator terms and U/W terms for an IPA round
multiexp_with_u_w->>best_multiexp: pass combined scalar and base vectors
best_multiexp-->>multiexp_with_u_w: return multiexponentiation result
multiexp_with_u_w-->>create_proof: return round result
Merge Risk: ⚪ Minimal · up to No concrete issue remains that calls for a change before merging; the proof-performance updates are mergeable after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The inspected changes preserve instance bounds, statement binding, and verifier acceptance checks. No introduced security concern was established. Residual risk remains because these are widely shared cryptographic optimizations and complete compatibility and deployment validation was not available. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
CI status: GitHub Actions has not run on this PR. GitHub has not registered any workflows on CI checks run locally instead (head
In total, 297 tests passed and 0 failed across these runs. That includes the new 🤖 Posted autonomously by Claude on behalf of pasta. |
Switch halo2_proofs, halo2_gadgets and halo2_poseidon from crates.io to https://github.com/dashpay/halo2, which starts from the exact crates.io halo2_proofs 0.3.2 / halo2_gadgets 0.5.0 / halo2_poseidon 0.1.0 sources and adds prover performance work: a compiled polynomial evaluator (dashpay/halo2#1), Booth MSM and GLV IPA generator collapse (dashpay/halo2#2), and concurrent per-circuit proving (dashpay/halo2#3). Together they cut Orchard proving time by 50-61% with byte-identical proofs. The pin points at the integration commit that merges all three; it should move to the dashified merge commit once those PRs land. pasta_curves resolves to 0.5.2 (needed by the GLV collapse). Orchard is the only halo2 user in Platform's dependency graph, so this swaps one copy for another rather than duplicating it. Add examples/prover_bench.rs, the harness used to measure that work: cold key build, warm proof timing for N-action bundles with the Dash memo (every proof is verified), and a seeded mode that prints proof digests to check two prover builds for byte-identical output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Why
Multi-scalar multiplication (MSM) and the IPA opening are the remaining shared hot spots in Orchard proving after #1. MSM is also on the verifier path that Dash Platform validators run for every shielded transition. This PR speeds up both without changing any proof bytes or verifier decisions.
What
arithmetic::best_multiexp, used by prover and verifier):poly/commitment/prover.rs):g_lo[i] + u_j·g_hi[i]usespasta_curves0.5.2's batched GLV multiplication on Pallas and Vesta. The challenge is decomposed once per round, and each chunk of points shares one inversion. Other curves keep the original path, selected through anAnydowncast that has a dispatch test. Late, small rounds now run in parallel too. Follows upstream Speed up IPA generator collapse with batched GLV zcash/halo2#927.[v·z]U + [r]Wterms are folded into the L/R multiexps instead of separate 2-term MSMs (~2.3 ms per opening).Params::commit_lagrange_prefix. Adapted from Reduce verifier instance-commitment overhead zcash/halo2#929/Avoid zero-padding prover instance commitments zcash/halo2#930. TheInstanceTooLargecheck still runs first.pasta_curves0.5.2 (an official zcash release) with theglvfeature. Its field-arithmetic changes versus 0.5.1 are a pure refactor. MSRV 1.60 → 1.63, as pasta 0.5.2 requires.Soundness and side channels
Unchanged outputs. Every change computes the same group elements, and transcript and RNG order are unchanged. Seeded Orchard proofs (1/2/6 actions) are byte-identical to crates.io
halo2_proofs0.3.2.Differential MSM tests.
best_multiexpis compared against the naive sum:Mutating the Booth carry, the carry-window count or the Horner doubling count makes them fail.
Collapse tests. The GLV collapse is tested against a point-by-point reference on both curves: identity points, pairs that double or cancel, and challenges 0, ±1, 2, ±2^254 and random values.
Tamper check. The new verifier rejects all 304 (2 actions) and 204 (6 actions) tampered Orchard proofs and instance sets: swapped instances, another bundle's instances, a dropped instance, and random bit flips.
Side channels. The only new variable-time code is the GLV collapse. Its inputs are the public generators and the public Fiat-Shamir challenges; no witness, blind or key reaches it. The bucket MSM's digit-dependent memory access already existed in 0.3.2, and Booth's sign selection is the same kind.
Benchmarks
Orchard proving and verification.
Setup:
panic=abort.halo2_proofs0.3.2 +pasta_curves0.5.1.nice 19. Every proof is verified, and all variants produce byte-identical seeded proofs.Micro-benchmarks (M4 Pro, best-of): IPA opening at k=11 went 337 → 107 ms on 1 thread and 55 → 23.5 ms on 6 threads; a 2049-point MSM went 15.3 → 13.1 ms on 1 thread.
Combined with #1 (compiled evaluator) and #3 (parallel synthesis), from the same run and baseline:
Testing
cargo test --release -p halo2_proofs, with default features and with--no-default-features --features batch: 42 + 1 + 8.cargo test --release -p halo2_gadgets: 38.cargo +1.63.0 check -p halo2_proofs -p halo2_gadgets --all-targets.cargo fmt --checkis clean.Notes for downstream
Platform picks up
pasta_curves0.5.2 with this change. Not done here, possible follow-ups:🤖 Generated with Claude Code
Summary by CodeRabbit
Compatibility
Performance