Skip to content

Migrate circuit output matrices to canonical flat sparse storage #100

Not planned

Description

@wu-s-john

Circuit output matrices retain per-row vectors and arbitrary-precision coefficient objects, while later consumers construct separate compact representations. The target already has a compact Boolean M-transpose.

This issue owns migrating the finished circuit matrices and their consumers onto the canonical sparse core. It does not reimplement the core requested in #20 or the temporary expression accumulators requested in #44.

Sources

The target repository's existing relation, field encoding, coordinate order, and transcript contracts are authoritative. The current target implementation determines compatibility; the PoC implementation is reference-only and must be re-derived against those contracts.

In scope

  • Integrate Sparse matrix core: reusable matrix operations for PIOP (Spartan) #20's reviewed representation, preserving row/column order, duplicate handling and matrix-digest encoding. Do not create another competing sparse crate or arithmetic-trait hierarchy.
  • Support width-segmented exact coefficients and implicit-one Boolean entries without allocating one coefficient object per nonzero.
  • Reuse validated topology across row traversal, transpose views and downstream preparation; document where physical reordering still requires an allocation.

Out of scope: replacing BTreeMap/BTreeSet expression accumulators (#44), changing relation geometry, or rewriting Spartan/GKR protocols.

Potential impact

Flattening finished storage removes row-local owners and repeated representation copies. Implicit Boolean coefficients save coefficient payload. Compare the complete lifecycle: keeping CSR and CSC copies simultaneously can offset these savings.

Done when

  • All required Sparse matrix core: reusable matrix operations for PIOP (Spartan) #20 operations remain correct; cross-check products, transposes and bilinear evaluations against existing matrices on signed and Boolean cases.
  • Reject malformed offsets, out-of-range columns, index overflow and inconsistent coefficient counts; preserve the target's canonicalization policy.
  • Matrix digests, witness order, proof bytes and transcript goldens are identical for unchanged relations; existing negative proof tests continue to reject.
  • Report setup time, allocations and peak/live matrix bytes for SHA and P-256, with consumer conversion costs included.

Dependencies and coordination

Depends on #99. Coordinate with #20, #44.

Activity

  1. added
    enhancement
    circuit-construction
    difficulty: hard
    matrix
    optimization-port
    urgency: med
    on Sep 24, 2026
  2. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Status update (main 34addac): partially implemented by #141 and #151. crates/spartan/src/matrix.rs already flattens A/B/C into CSR (Positions { row_starts, columns } + interned coefficients), and #151 narrowed SHA-256 coefficients to i64 and closed #44. Remaining scope is flattening SparseMatrix<C> and SparseBoolMatrix in crates/circuit/src/constraints.rs (still Vec<SparseRow<C>> per-row allocations). Note #20 is now closed/superseded.

  3. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Closing as out of current focus: circuit R1CS matrix storage refactor; 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

    circuit-constructiondifficulty: hardenhancementmatrixoptimization-porturgency: med

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions