Small value sumcheck#112
Open
wu-s-john wants to merge 32 commits into
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
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds the core implementation of the “small-value sumcheck” optimization (Algorithm 6 from IACR 2025/1117) by introducing Lagrange-accumulator infrastructure and a new small-value sumcheck prover path that uses native integer arithmetic and delayed reduction during the first ℓ₀ rounds.
Changes:
- Add
src/lagrange_accumulator/with domain types, Lagrange basis/extension logic, accumulator structures, and an optimized accumulator builder (including thread-local scratch state). - Add
src/small_sumcheck.rsimplementingprove_cubic_small_valueand a batched transition binding step from small-integer polynomials into field polynomials. - Extend big-number infrastructure to support field×small delayed reduction via Barrett reduction (plus provider wiring and tests), and update sumcheck types to support equality comparisons.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/sumcheck.rs | Adjust EqSumCheckInstance API to accept tau slices; add EqSumCheckInstance::from_pyramids; make SumcheckProof comparable and expose compressed polys internally. |
| src/small_sumcheck.rs | New small-value sumcheck prover (ℓ₀ rounds via accumulators + transition + remaining rounds via eq-sumcheck instance). |
| src/provider/pt256.rs | Wire Barrett + small-value + delayed-reduction traits/tests for P256/T256 scalar fields. |
| src/provider/pasta.rs | Wire Barrett + small-value + delayed-reduction traits/tests for Pasta scalar fields. |
| src/provider/bn254.rs | Wire Barrett + small-value + delayed-reduction traits/tests for BN254 scalar field. |
| src/polys/univariate.rs | Make CompressedUniPoly derive PartialEq, Eq for proof equality checks. |
| src/polys/multilinear.rs | Generalize MultilinearPolynomial over coefficient type; move binding ops behind Field; add small-value helpers. |
| src/polys/eq.rs | Add eq “pyramid” builders used for accumulator building and pyramid reuse. |
| src/lib.rs | Register new internal modules (lagrange_accumulator, small_sumcheck). |
| src/lagrange_accumulator/mod.rs | New module root and re-exports for accumulator infrastructure. |
| src/lagrange_accumulator/thread_state.rs | Add per-rayon-thread scratch buffers to reduce allocations in accumulator building. |
| src/lagrange_accumulator/index.rs | Implement β→(round,v,u,y) index mapping (Definition A.5) for scatter. |
| src/lagrange_accumulator/extension.rs | Implement boolean→Lagrange-domain extension (Procedure 6). |
| src/lagrange_accumulator/evals.rs | Add compact evaluation containers for U_d and Û_d points. |
| src/lagrange_accumulator/eq_round.rs | Add per-round eq-factor tracking and t(1) derivation helper. |
| src/lagrange_accumulator/domain.rs | Add type-safe domain/index types for U_d/Û_d. |
| src/lagrange_accumulator/csr.rs | Add CSR container for compact storage of per-β index lists. |
| src/lagrange_accumulator/basis.rs | Add barycentric Lagrange basis factory and tensor coefficients. |
| src/lagrange_accumulator/accumulator.rs | Add round accumulators and accumulator collection types. |
| src/lagrange_accumulator/accumulator_builder.rs | Implement optimized accumulator builder for Spartan’s cubic relation and return reusable eq pyramids. |
| src/errors.rs | Add new error variants for small-value overflow and invalid ℓ₀ selection. |
| src/big_num/wide_mul.rs | Add widening multiplication trait for small integers. |
| src/big_num/small_value_field.rs | Add small-integer↔field conversion traits/helpers and tests. |
| src/big_num/mod.rs | Export Barrett/small-value modules and re-export new traits/types. |
| src/big_num/macros.rs | Add macros for Barrett constants, SmallValueField impls, and delayed-reduction impls for small ints. |
| src/big_num/limbs.rs | Add signed wide accumulators, magnitude subtraction helper, and limb utilities used by Barrett/DMR. |
| src/big_num/field_reduction_constants.rs | Introduce BarrettReductionConstants and corresponding test helpers. |
| src/big_num/delayed_reduction.rs | Add accumulation helpers for field×small and field×i128; add tests for small-value delayed reduction. |
| src/big_num/barrett.rs | Implement μ-Barrett reduction for 6- and 7-limb inputs plus test macros. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wu-s-john
force-pushed
the
small-value-sumcheck
branch
from
April 11, 2026 21:06
d851a37 to
8736aed
Compare
wu-s-john
force-pushed
the
small-value-sumcheck
branch
from
April 12, 2026 13:43
08de38b to
8736aed
Compare
wu-s-john
force-pushed
the
small-value-sumcheck
branch
from
April 22, 2026 15:52
636ad17 to
4c47440
Compare
wu-s-john
force-pushed
the
small-value-sumcheck
branch
from
June 12, 2026 03:21
4c47440 to
d489120
Compare
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.
wu-s-john
force-pushed
the
small-value-sumcheck
branch
from
June 12, 2026 19:09
d489120 to
72bc667
Compare
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