Skip to content

Small value sumcheck#112

Open
wu-s-john wants to merge 32 commits into
microsoft:mainfrom
wu-s-john:small-value-sumcheck
Open

Small value sumcheck#112
wu-s-john wants to merge 32 commits into
microsoft:mainfrom
wu-s-john:small-value-sumcheck

Conversation

@wu-s-john

Copy link
Copy Markdown
Contributor

Note: This PR builds on the Barrett reduction infrastructure from #111. The changes span src/big_num/, src/lagrange_accumulator/, and src/small_sumcheck.rs. Reviewers are encouraged to focus on src/lagrange_accumulator/ and src/small_sumcheck.rs — the src/big_num/ changes are covered by #111.

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.

num_vars n baseline (DMR) small-value speedup
16 65,536 4.98 ms 3.43 ms 1.45×
17 131,072 8.83 ms 4.79 ms 1.84×
18 262,144 15.07 ms 7.54 ms 2.00×
19 524,288 27.81 ms 12.84 ms 2.17×
20 1,048,576 49.96 ms 26.37 ms 1.90×
21 2,097,152 190.66 ms* 50.73 ms 3.76×*
22 4,194,304 152.75 ms 96.09 ms 1.59×
23 8,388,608 285.86 ms 181.02 ms 1.58×
24 16,777,216 546.06 ms 333.13 ms 1.64×
25 33,554,432 1,095.2 ms 653.01 ms 1.68×
26 67,108,864 2,150.1 ms 1,314.5 ms 1.64×

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 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

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

Test Plan

  • prove_cubic_small_value produces identical proofs to prove_cubic_with_three_inputs (equivalence tests)
  • cargo test -- --skip test_msm_ux
  • cargo clippy

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.rs implementing prove_cubic_small_value and 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.

Comment thread src/small_sumcheck.rs Outdated
Comment thread src/big_num/macros.rs Outdated
Comment thread src/big_num/delayed_reduction.rs Outdated
Comment thread src/polys/multilinear.rs Outdated
Comment thread src/big_num/barrett.rs Outdated
@wu-s-john
wu-s-john force-pushed the small-value-sumcheck branch from d851a37 to 8736aed Compare April 11, 2026 21:06
@wu-s-john
wu-s-john force-pushed the small-value-sumcheck branch from 08de38b to 8736aed Compare April 12, 2026 13:43
@wu-s-john
wu-s-john force-pushed the small-value-sumcheck branch from 636ad17 to 4c47440 Compare April 22, 2026 15:52
@wu-s-john
wu-s-john force-pushed the small-value-sumcheck branch from 4c47440 to d489120 Compare June 12, 2026 03:21
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
wu-s-john force-pushed the small-value-sumcheck branch from d489120 to 72bc667 Compare June 12, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants