Skip to content

Defer Barrett reduction in the Spartan sumcheck round bodies #47

Not planned

Description

@shreyas-londhe

Fq reduces after every multiplication. mul calls reduce_wide, a Barrett step, on each 256-bit product before handing back a canonical residue.

The sumcheck round bodies are sums of products, so most of those reductions are thrown away. cubic_contribution performs nine multiplications and returns three numbers, each one a sum of one or two products. sum_coefficients then adds those across the whole table before anything has to be canonical. Barrett reduction is linear over addition, so a sum of unreduced products reduces once to the same residue as reducing each term first.

What it could win: nine reductions per table entry become three per round. Reduction is a large share of a modular multiply, so the round body should drop by something near half.

We already do this for the other field. Wide256 (crates/field/src/gf128/wide.rs) is that accumulator for F128, and PR #40 uses it in the GKR round bodies. Fq has no equivalent.

The width is comfortable. Q100 is just under 2^100, so a product is below 2^200, and summing 2^24 of them stays below 2^224. reduce_wide already accepts a 256-bit input as a (lo, hi) pair, so a 256-bit accumulator covers any table we would build.

This replaces the "raw Montgomery residues" item from #41, which was wrong: Fq is Barrett, so there is no Montgomery conversion to defer.

Effort M.

Current optimization audit — 2026-09-23

This section supersedes historical implementation descriptions, cost claims, and estimates above where they conflict with the current target. The earlier body is retained for context.

Extend target prime-field arithmetic with explicitly bounded unreduced product accumulators and use them for outer/inner coefficient sums.

Current behavior and sources

At the audited target commit, the direct cubic body has eight field multiplications per pair before equality-pair formation, and inner coefficients use two products. The earlier nine-products/roughly-half-runtime claim above is not a current measurement. Field reductions cannot simply be removed across nonlinear intermediate products.

The target's current field profile, relation, index ordering, transcript, and terminal-claim contracts remain authoritative (including #19 and the specification tracked by #2). The current target implementation establishes the behavior to preserve. The PoC implementation reference is an implementation reference, not a replacement protocol specification. Preserve the target arithmetic representations; convert explicitly when crossing between canonical Barrett field elements and tape Montgomery residues.

In scope

  • Derive accumulator capacity from the actual target modulus, operand bounds, term count and merged parallel workers. Reduce or split accumulation before overflow; do not assume every future table fits 256 bits.
  • Retain required reductions before dependent products. Prepare reduction schedules outside hot loops and integrate with existing fused fold/message passes.
  • Expose mixed integer×field accumulation needed by native inputs without importing Montgomery encoding assumptions from the PoC.

Done when

  • Compare every coefficient, final claim and transcript with reduced arithmetic for largest admitted domains, maximal residues, cancellation and zero/one challenges.
  • Exercise exact capacity boundaries, merged worker counts, signed/mixed input extrema and rejected unsupported bounds; serial and parallel proofs must agree.
  • Preserve proof messages, Fiat–Shamir absorb/squeeze order, verifier-derived points and final PCS handoff; assert transcript-byte equivalence against the existing implementation for valid inputs.
  • Report matched release-build phase timings and named-buffer/peak-memory measurements with fixed field, input, compiler, thread count and proof validation. State regressions and setup amortization separately.

Impact and boundaries

Specialized inner coefficient sums can replace two modular reductions per pair with two bounded accumulator reductions per round, or per safe chunk. Outer savings depend on retained residual products and other ports; no fixed overall speedup is established. Wall-clock improvement is unmeasured on the target and is not an acceptance assumption.

Out of scope: changing the relation, field/security profile, proof format, PCS, or transcript; unrelated refactors and new workload support.

Related: #19, #41.

Difficulty: hard; urgency: high. High priority shared arithmetic foundation. Hard difficulty is assigned to overflow-safe public bounds and reduction correctness across native, field and parallel paths; historical Effort M is not a current estimate.

Activity

  1. added
    enhancement
    delayed-reduction
    difficulty: hard
    field-arithmetic
    optimization-port
    sumcheck
    urgency: high
    on Sep 24, 2026
  2. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Status update (main 34addac): still open and high-priority (DynField and Fq both reduce on every multiplication via Barrett reduce_wide, and crates/spartan/src/sumcheck.rs has no unreduced accumulator).

    Important post-#141 note: production proving now uses DynField (crates/field/src/dynamic.rs) with runtime primes up to 126 bits (e.g., 121 bits on 600-block SHA-256), rather than fixed Q100. Two 121–126-bit residues multiply to 242–252 bits, so a 256-bit accumulator can hold at most 2^4–2^14 terms (not 2^24 as the original body estimated) before reducing, or requires a wider (>256-bit) accumulator; the implementation must support DynField in addition to Fq.

  3. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Closing as out of current focus: Spartan sumcheck delayed Barrett reduction; current focus is on the BitZ PCS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    delayed-reductiondifficulty: hardenhancementfield-arithmeticoptimization-portsumcheckurgency: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions