Repository navigation
perf: embed canonical k=11 params and fixed-base Lagrange tables (cold key build ~5-7x faster) - #12
PastaPastaPasta wants to merge 2 commits into
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Embedded parameters src/circuit.rs, CHANGELOG.md |
Proving- and verifying-key builders use decoded embedded parameters for K = 11. Tests compare the embedded bytes and their decoded round-trip with freshly derived parameters. |
Fixed-base coefficient tables src/constants/fixed_bases/lagrange_coeffs.rs, src/constants/fixed_bases.rs, CHANGELOG.md |
Fixed-base types dispatch to embedded coefficient tables. The table decoder checks the expected byte length and canonical field values. Tests compare each fixed base with Halo 2’s default derivation. An ignored test regenerates the tables. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Merge Risk: 
Minimal · previous review 153b2
-
No actionable issue is established for the embedded circuit data; the change is mergeable after normal checks.
Security architecture risk: 
Low · up to 153b2
-
This changes how proof-related constants are supplied, not who may create or verify proofs. No new runtime attack path was identified, but the checked-in values were not independently confirmed against their canonical derivation during this review.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — An incorrect embedded release could affect every consumer constructing Orchard keys or using these fixed-base implementations. That exposure requires changing build-time data or the built program; the inspected runtime APIs do not let proof submitters replace the embedded bytes.
Trust Boundaries and Controls
- observed — Untrusted proof bytes still enter the verification transcript and are checked against the supplied verifying key and public instances. Parameter embedding does not add an alternate verification path or remove the proving-key version check.
Resilience and Maintainability Implications
- inferred — The derivation-comparison tests provide a control against release-data and dispatch drift. Encoding validation alone would not detect a structurally valid but incorrect table, so confidence in compatibility depends on confirming those comparisons.
Hardening Proposals
- proposed — Require passing canonical-equivalence checks with the circuit feature enabled when publishing regenerated binaries or changing the parameter and coefficient derivation dependencies. This is an assurance proposal, not an observed missing release control.
-
🚥 Pre-merge checks | ✅ 4 | ❌ 1
-
❌ Failed checks (1 warning)
Check name Status Explanation Resolution Docstring Coverage ⚠️ WarningDocstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
-
Check name Status Explanation Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled. Title check ✅ Passed The title clearly summarizes the main change: embedding canonical parameters and fixed-base Lagrange tables to improve cold key-build performance. Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
046b1b5f-feca-4222-ba45-9f764c64f54c
⛔ Files ignored due to path filters (8)
-
src/circuit_data/vesta_params_k11.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/commit_ivk_r.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/note_commit_r.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/nullifier_k.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/spend_auth_g.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/spend_auth_g_short.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/value_commit_r.bin is excluded by !**/*.bin
src/constants/fixed_bases/lagrange_coeffs/value_commit_v_short.bin is excluded by !**/*.bin
📒 Files selected for processing (4)
-
CHANGELOG.md
src/circuit.rs
src/constants/fixed_bases.rs
src/constants/fixed_bases/lagrange_coeffs.rs
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
046b1b5f-feca-4222-ba45-9f764c64f54c
⛔ Files ignored due to path filters (8)
-
src/circuit_data/vesta_params_k11.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/commit_ivk_r.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/note_commit_r.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/nullifier_k.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/spend_auth_g.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/spend_auth_g_short.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/value_commit_r.binis excluded by!**/*.binsrc/constants/fixed_bases/lagrange_coeffs/value_commit_v_short.binis excluded by!**/*.bin
📒 Files selected for processing (4)
-
CHANGELOG.mdsrc/circuit.rssrc/constants/fixed_bases.rssrc/constants/fixed_bases/lagrange_coeffs.rs
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
-
|
CI note: the Code coverage failure is a pre-existing infra issue. This PR did not cause it.
All other checks pass (tests on Linux/macOS/Windows, MSRV and beta clippy, no_std builds, rustfmt, intra-doc links, book). I've left the CI config alone in this PR. Possible fixes for a separate PR: raise 🤖 Posted autonomously by Claude on behalf of pasta. |
ProvingKey::build_for_version and VerifyingKey::build_for_version derived the public Vesta commitment parameters with Params::new(11) on every call: 2048 hash-to-curve generators plus an inverse FFT over the curve to get the Lagrange basis. That is roughly 300 ms of a ~1.2 s cold proving-key build (and ~40% of a verifying-key build) on an M4 Pro, and several times that on a phone. The parameters are deterministic public data, so embed their canonical serialization (Params::write, 131,140 bytes) and decode it with Params::read, which takes ~22 ms. The keys are unchanged. embedded_params_match_derivation checks the file byte-for-byte against Params::new(11) and that it round-trips through Params::read/write. The ignored test regenerate_embedded_params rewrites it (cargo test --release --lib -- --ignored regenerate_embedded). The length is also checked at compile time. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
halo2_gadgets' default FixedPoint::lagrange_coeffs derives each fixed base's x-coordinate interpolation coefficients from its generator on every call: a scalar multiplication and normalization per window multiple plus an interpolation per window. Key generation calls it once per fixed-base multiplication in the Action circuit (seven per synthesis), and building a proving key synthesizes the circuit twice (keygen_vk then keygen_pk), so a cold ProvingKey::build spent ~0.6 s of CPU re-deriving the same public constants. Witness synthesis during proving does not evaluate fixed assignments, so proving itself was not affected. Override lagrange_coeffs for OrchardFixedBasesFull, OrchardBaseFieldBases and OrchardShortScalarBases to decode embedded canonical encodings instead (all seven tables decode in ~0.25 ms, so they are not cached). There are seven tables (117 KiB): the five full-width bases plus the short-scalar windows for ValueCommitV and SpendAuthG. SpendAuthGBase shares SpendAuthG's full-width table because it has the same generator and window count. compute_lagrange_coeffs stays the reference: lagrange_coeffs_match_default_derivation checks every enum variant's override against it with halo2_gadgets' own window count for the scalar kind, which covers the table contents and the dispatch. The ignored test regenerate_embedded_lagrange_coeffs rewrites the files (cargo test --release --lib -- --ignored regenerate_embedded). Table lengths are checked at compile time. The pinned verifying-key descriptions and stored proofs still match, and seeded proofs are byte-identical to the previous release. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
153b23a to
a1e1857
Compare
Why
A wallet has to build the Orchard
ProvingKeybefore its first shielded send in each process. On a phone that cold build is seconds of latency on the first Send. Validators build theVerifyingKeyat startup.Most of that time goes to recomputing public, deterministic data:
Params::new(11): 2,048 hash-to-curve generators plus an inverse FFT over the curve, ≈300 ms on an M4 Pro.FixedPoint::lagrange_coeffsre-derives each fixed base's Lagrange interpolation coefficients from its generator every time. Key generation calls it for each of the 7 fixed-base multiplications in each synthesis, and a proving-key build synthesizes the circuit twice (keygen_vk+keygen_pk). That is ≈260 ms per synthesis.What
Two commits embed this data as checked-in binary files and decode it instead of deriving it:
perf(circuit): embed canonical k=11 Halo 2 params.src/circuit_data/vesta_params_k11.bin(131,140 B) is the canonicalParams::writeoutput, decoded withParams::read(≈22 ms). BothProvingKey::build_for_versionandVerifyingKey::build_for_versionuse it.perf(constants): embed fixed-base Lagrange interpolation coefficients. Seven tables (120,064 B) live insrc/constants/fixed_bases/lagrange_coeffs/.lagrange_coeffs()overrides onOrchardFixedBasesFull,OrchardBaseFieldBasesandOrchardShortScalarBasesreturn them; decoding all seven takes ≈0.25 ms.SpendAuthGBaseshares the fullSpendAuthGtable, since it has the same generator and window count.Everything is public data: no keys, witnesses, randomness or trusted setup. The embedding is gated on the
circuitfeature, so builds without it are unaffected. File lengths are checked at compile time.Keys and proofs are unchanged. Warm proving is unaffected, because the prover never evaluates fixed-column assignments.
Verification
embedded_params_match_derivation(always runs): the embedded bytes equal theParams::new(11)serialization byte-for-byte, and round-trip through read/write.lagrange_coeffs_match_default_derivation(always runs): for every enum variant, the override equalscompute_lagrange_coeffs(generator, NUM_WINDOWS)for that scalar kind. This covers both the values and which table each base uses.circuit_description_fixed/_insecure) and the stored proof fixtures still pass, and would independently catch bad data.cargo test --release --lib -- --ignored regenerate_embedded. It reproduces all 8 files byte-for-byte (SHA-256 checked).cargo test --release: 84 passed, 2 ignored (the regenerators). Clippy (--all-features --all-targets) has no warnings;fmt --checkandcargo docare clean;--no-default-featuresandunstable-voting-circuitsbuild.dashified-0.14.1.Benchmarks
Cold key build in a fresh process for each run.
Setup:
panic=abort, like Platform'srelease-iosprofile.dashified-0.14.1) and this branch alternate, 8 runs each per thread count.ProvingKey::buildbefore → after (median, range)VerifyingKey::buildbefore → afterIn-process breakdown (M4 Pro):
new≈302–329 msread≈22 mskeygen_vkkeygen_pkWarm 2-action proving: CPU per proof unchanged (3.17 s vs 3.17 s).
Cost
≈245 KiB of read-only data when the
circuitfeature is enabled. A stripped release binary grows by a net ≈182 KB, because the derivation code is no longer linked.Related
Part of a series on Dash shielded send latency. The prover-side work starts with dashpay/halo2#1 (compiled evaluator, −20–42% warm proof time). A follow-up PR will switch this crate's halo2 dependencies to
dashpay/halo2.🤖 Generated with Claude Code
Summary by CodeRabbit