Skip to content

Defer Barrett reduction in the Spartan sumcheck round bodies #47

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.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions