Skip to content

matrix contraction: accumulate signed narrow coefficients directly #98

Not planned

Description

@wu-s-john

Add a checked signed-narrow sparse contraction backend using mixed field×integer MACs and delayed reduction, preserving existing ±1 fast paths.

Current behavior and sources

Target sparse modular contraction multiplies general field coefficients, even for relation families whose public coefficients have checked narrow signed bounds. The target already special-cases ±1 coefficients and parallelizes independent columns; those are not new features. Narrow specialization is not safe for all circuits.

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

  • Retain i64 coefficients only for matrices whose public coefficient bounds admit them; use the general exact/wide backend otherwise.
  • Use unsigned_abs and sign correction so i64::MIN cannot overflow. Bound each column/merged accumulator from public topology and the target modulus using Defer Barrett reduction in the Spartan sumcheck round bodies #47 facilities.
  • Parallelize independent column jobs with a small-work fallback, preserving row/column ordering and deterministic results.

Done when

  • Compare all outputs and downstream proof/transcript bytes with generic field contraction on real narrow matrices and randomized sparse shapes.
  • Cover i64::MIN/MAX, zeros, singleton ±1, long columns, cancellation, padding, empty columns and zero/one weights; reject unsupported coefficients or malformed sparse metadata.
  • 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

Avoids full field×field reduction for general narrow nonzeros and can reduce once per bounded column/chunk; existing ±1 multiplication bypasses remain intact. Matrix traversal and output storage remain. 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.

Depends: #47. Related: #19, #20, #41, #47.

Difficulty: medium; urgency: high. High priority for narrow-coefficient SHA matrices; moderate difficulty with explicit fallback, signed-minimum handling and accumulator bounds.

Activity

  1. added
    enhancement
    delayed-reduction
    difficulty: medium
    matrix
    optimization-port
    small-values
    urgency: high
    on Sep 24, 2026
  2. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Status update (main 34addac): #151 already narrowed SHA-256 circuit coefficients from BigInt to i64, and #141 introduced PreparedIntegerMatrices<R> / PreparedConstraintMatrices<DynField> in crates/spartan/src/matrix.rs as the production Spartan contraction path (whereas crates/circuit/src/matrix_sparse.rs linked above is currently benchmark-only). Still valid for accumulating signed i64 coefficients with delayed reduction directly during bind_and_batch / evaluate_batched (note #20 is now closed/superseded).

  3. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Closing as out of current focus: Spartan/circuit sparse matrix contraction optimization; 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: mediumenhancementmatrixoptimization-portsmall-valuesurgency: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions