Open
Conversation
Add support for accumulating field × small_int products (i32, i64, i128) with delayed modular reduction using generic Barrett reduction: - SmallValueField<V> trait for small integer ↔ field conversion - WideMul trait for widening multiplication - BarrettReductionConstants with compile-time computed μ = ⌊2^512/p⌋ - SignedWideLimbs<N> accumulator for signed product sums - DelayedReduction<i32/i64/i128> implementations for all fields
This replaces expensive field multiplications with native integer
arithmetic during the first ℓ₀ rounds when polynomial values are
guaranteed small.
Key components:
Lagrange accumulator infrastructure (src/lagrange_accumulator/):
- LagrangeAccumulators: precomputed A_i(v, u) values for all rounds
- LagrangeIndex/LagrangePoint/LagrangeHatPoint: type-safe domain indices
- LagrangeBasisFactory: barycentric Lagrange basis with O(D) evaluation
- extend_to_lagrange_domain: batch extension from {0,1}^ℓ₀ to U_D^ℓ₀
- EqRoundFactor: tracks α = eq(τ_{<i}, r_{<i}) across rounds
- Csr: compressed sparse row storage (2 allocations vs N+1 for Vec<Vec>)
Performance optimizations:
- Thread-local SpartanThreadState eliminates per-iteration allocations
- Delayed modular reduction via SignedWideLimbs accumulators
- Skip binary betas (Az·Bz = Cz on {0,1}^n for satisfying witnesses)
- Batched eq-weighted binding in transition phase
API:
- SmallValue trait: WideMul + Copy + Zero + Add + Sub + Send + Sync
- SmallValueEngine<SV>: blanket impl consolidates field requirements
- prove_cubic_small_value<E, SV, const LB>: main entry point
The prove_cubic_small_value function produces identical proofs to the
standard prove_cubic_with_three_inputs, verified via equivalence tests.
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
Implement the small-value sumcheck optimization (Algorithm 6) from "Speeding Up Sum-Check Proving" (Bagad, Dao, Domb, Thaler, IACR 2025/1117). This replaces expensive field multiplications with native integer arithmetic during the first ℓ₀ rounds when polynomial values are guaranteed small.
This PR provides the core infrastructure for the optimization. Integration into the Spartan prover is planned for a follow-up PR.
Benchmarks
Measured on M1 Max MacBook Pro with
jemalloc, BN254 scalar field, ℓ₀ = 3.These results are consistent with the ~1.6-2× speedup and has achieved better overall performance than #98.
Key Components
Lagrange accumulator infrastructure (
src/lagrange_accumulator/):LagrangeAccumulators: precomputed A_i(v, u) values for all roundsLagrangeIndex/LagrangePoint/LagrangeHatPoint: type-safe domain indicesLagrangeBasisFactory: barycentric Lagrange basis with O(D) evaluationextend_to_lagrange_domain: batch extension from {0,1}^ℓ₀ to U_D^ℓ₀EqRoundFactor: tracks α = eq(τ_{<i}, r_{<i}) across roundsPerformance optimizations:
SpartanThreadStateeliminates per-iteration allocationsSignedWideLimbsaccumulatorsAPI:
SmallValuetrait:WideMul + Copy + Zero + Add + Sub + Send + SyncSmallValueEngine<SV>: blanket impl consolidates field requirementsprove_cubic_small_value<E, SV, const LB>: main entry pointTest Plan
prove_cubic_small_valueproduces identical proofs toprove_cubic_with_three_inputs(equivalence tests)cargo test -- --skip test_msm_uxcargo clippy