Repository navigation
Description
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
zkfriendly commentedon Nov 24, 2026
Status update (
main34addac): #151 already narrowed SHA-256 circuit coefficients fromBigInttoi64, and #141 introducedPreparedIntegerMatrices<R>/PreparedConstraintMatrices<DynField>incrates/spartan/src/matrix.rsas the production Spartan contraction path (whereascrates/circuit/src/matrix_sparse.rslinked above is currently benchmark-only). Still valid for accumulating signedi64coefficients with delayed reduction directly duringbind_and_batch/evaluate_batched(note #20 is now closed/superseded).zkfriendly commentedon Nov 24, 2026
Closing as out of current focus: Spartan/circuit sparse matrix contraction optimization; current focus is on the BitZ PCS.