Skip to content

fix(groth16): validate and pin streaming proving-key imports (#48) - #61

Merged
satran004 merged 3 commits into
mainfrom
fix/48-streaming-key-validation
Sep 27, 2026
Merged

satran004 merged 3 commits into
mainfrom
fix/48-streaming-key-validation

Conversation

@satran004

@satran004 satran004 commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Streaming .zkey import previously accepted on-curve points outside the prime-order subgroup and reduced some noncanonical field encodings. Validate every header, IC, G1-query and G2-query point before publishing a store; query infinity remains allowed and VK/IC infinity remains rejected.

This bounded milestone for #48/#47 adds strict section/version/length/coefficient checks, a private source snapshot hashed before parsing, externally pinned source SHA-256 (or an explicit local/test unpinned API), deterministic payload manifests, and pinned store loading. Failed imports publish nothing and existing stores are never overwritten. Unknown section types outside snarkjs 1–10 are rejected. The deprecated two-argument implicit import fails closed.

An optional trusted exact circuit fingerprint is dimension-checked and written before the manifest is sealed. The returned manifest pin therefore supports both pinned loading and circuit-aware pipeline cache hits. bindCircuitFingerprint rejects sealed stores without rewriting them; adding metadata requires a new import and explicit new pin. The CLI exposes --circuit-fingerprint, validates policy/hash arguments before import output, and returns exit 2 for malformed options. Guides use pinned loading; the rehearsal hashes the key only after successful snarkjs zkey verify and finalizes with that hash.

Security design: ADR-0025 applies the accepted import invariants; these operations process public key material, not private witnesses. The fingerprint is caller-asserted metadata, not proof of key/R1CS consistency. A malicious key made entirely of valid subgroup points can still expose low-entropy witness values through a modified L query. Independently verify the key against the exact R1CS and trusted .ptau, or pin a hash from someone trusted who did. Hashes and subgroup tests do not verify a ceremony transcript. Keep the mapped store protected from concurrent local mutation throughout its lifetime. Internal key/R1CS consistency verification is tracked separately in #67; known-unfinalized-key rejection remains #66.

Validation at e29cc3d (after incorporating merged PR #60):

  • ./gradlew :zeroj-crypto:test :zeroj-tools:test :zeroj-crypto:javadoc :zeroj-tools:javadoc :zeroj-tools:fatJar passed: 1,136 tests reported, 2 opt-in tests skipped, zero failures/errors. Includes live snarkjs contribution/import/prove interoperability.
  • Pinned import → pinned load → cache miss/hit → proof verification regression; sealed binding refusal, deterministic bound manifests and incompatible circuit metadata rejection.
  • Negative tests check rejection reasons for torsion points, canonical-coordinate-plus-modulus aliases, coefficients ≥ r, malformed/unknown sections and invalid CLI options. Removing the canonicality guard deliberately caused the strengthened alias test to fail; the guard was restored before the full passing run.
  • docs/ceremony/rehearsal.sh completed the mixed-tool contribution → beacon → snarkjs verification → hash-pinned finalize flow. bash -n and git diff --check passed.

Performance evidence is recorded in the timing report, with a reproducible predicate harness. On the local 16-core Apple M4 Max / Java 25 host, median single-thread CPU cost was 0.5113 ms/G1 and 1.4840 ms/G2. Three tiny-fixture complete CLI imports took 0.16 s process wall time each. The 19M-constraint ownership finalize timing is still pending: its artifact/path and trusted hash were unavailable. The report's 64–74k core-second extrapolation uses the reviewer's assumed point counts; it is not a measured full-size import. Future optimization must preserve the subgroup predicate and have differential evidence.

#48 remains open for full-scale measurement, production circuit freeze, real ceremony/transcript and entropy verification, audited Filecoin conversion provenance, public deployment manifests and external security review. #47 remains open for its other assurance workstreams. No production-readiness claim or issue auto-closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant