Skip to content

Wengert recording: intern coefficients before building raw edges #92

Not planned

Description

@wu-s-john

Intern public exact-integer coefficients as they are recorded and store compact coefficient IDs on raw edges.

Current behavior and sources

The target deduplicates coefficients when finishing its tape, after raw recording has allocated repeated boxed coefficient values. The final table therefore understates temporary recording memory.

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

  • Use a canonical signed-magnitude/equivalent exact-value key while retaining enough declared-width information for correct later embedding.
  • Replace raw edge coefficient ownership with checked IDs; preserve deterministic compilation and ensure discarded/dead nodes cannot leave invalid references.
  • Reuse the resulting table during final tape construction, avoiding a second independent coefficient-copy path.

Done when

  • Compare compiled arithmetic and downstream transcript outputs with the existing recorder for repeated coefficients across widths, zero, ±1 and signed extrema.
  • Test hash collisions through equality semantics, invalid IDs at checked construction boundaries, dead-node removal and reproducible tape output.
  • 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

Eliminates repeated recording-time coefficient allocations and reduces raw edge payload. Final tape interning already exists, so this primarily improves setup cost and peak temporary memory. Wall-clock improvement is unmeasured on the target and is not an acceptance assumption.

Out of scope: changing matrix coefficient semantics, general circuit container work in #44, or changing statement digests without an explicit compatibility decision.

Related: #20, #41, #44.

Difficulty: medium; urgency: med. Medium priority bounded preprocessing work; exact signed normalization and deterministic graph output make this more than a mechanical container replacement.

Activity

  1. added
    enhancement
    allocation
    difficulty: medium
    optimization-port
    preprocessing
    urgency: med
    wengert
    on Sep 24, 2026
  2. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Status update (main 34addac): partially mitigated for SHA-256 by #149, which made StoredInteger (crates/circuit/src/matrix_products.rs:297) store single-word (<= 64-bit) values inline (Words::Inline(u64)), removing per-edge heap allocations for narrow coefficients. Still relevant for multi-limb circuits (P-256) and shrinking RawTerm (crates/circuit/src/matrix_wengert.rs:45) from a 16-byte StoredInteger to a compact coefficient ID.

  3. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Closing as premature while Wengert binding is not yet integrated into production Spartan (#90), and already partially mitigated for SHA-256 by inline StoredInteger in #149. Referenced from #90.

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

    allocationdifficulty: mediumenhancementoptimization-portpreprocessingurgency: medwengert

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions