Skip to content

Parallelize SHA chain witness replay after a native state prepass #102

Not planned

Description

@wu-s-john

A chained SHA circuit currently replays through one eager witness generator. Dependency between chaining states serializes the replay even though the native hash computation can determine all those states cheaply.

This issue owns a native chaining-state prepass followed by independent per-compression hint/witness generation and deterministic assembly into the target's established coordinate layout.

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

  • Compute states and padding using the same public message-length and SHA semantics as the circuit; validate each generated circuit output against its expected next state.
  • Run independent compression jobs with the existing Rayon pool and a serial fallback; keep per-worker ownership local and assemble in compression order.
  • Preserve existing input-before-hint ordering unless the repetition work explicitly introduces a reviewed new layout. Coordinate shared constants and boundary aliases with Avoid materialising the global R1CS matrix when the relation is one local circuit repeated over instances #42.

Out of scope: new SHA equations, new public inputs, changing the global thread-pool policy (#48), or parallelizing ECDSA.

Potential impact

The expensive replay portion can benefit from worker parallelism. Native preprocessing, packing, scheduling and any ECDSA tail remain serial or independently bounded, so worker count is not an overall speedup claim. Shard retention may increase peak memory.

Done when

  • Serial and parallel generation agree bit-for-bit on witness, products when retained, digest and all boundary states across worker counts.
  • Compare complete proof/transcript golden bytes; inject an incorrect prepass state, output or padding block and demonstrate rejection.
  • Cover one block, multi-block messages, empty-message padding where supported and non-power-of-two compression counts.
  • Profile native prepass, replay, assembly, allocations and peak memory separately on matched shapes and worker counts.

Dependencies and coordination

Coordinate with #17, #42, #48.

Activity

  1. added
    enhancement
    difficulty: medium
    optimization-port
    parallelism
    sha256
    urgency: med
    witness-generation
    on Sep 24, 2026
  2. zkfriendly commented on Nov 24, 2026

    @zkfriendly
    Collaborator

    Closing as low impact: after #149, 600-block SHA-256 witness generation already takes only ~10.3 ms (<1% of total prove time). Reopen if much longer SHA chains make witgen measurable.

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

    difficulty: mediumenhancementoptimization-portparallelismsha256urgency: medwitness-generation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions