Skip to content

Add BLS12-381 Poseidon, Jubjub-in-circuit support#1

Merged
satran004 merged 6 commits into
mainfrom
feat/poseidon_bls12-381
May 6, 2026
Merged

Add BLS12-381 Poseidon, Jubjub-in-circuit support#1
satran004 merged 6 commits into
mainfrom
feat/poseidon_bls12-381

Conversation

@satran004
Copy link
Copy Markdown
Member

@satran004 satran004 commented Apr 18, 2026

Summary

Adds standards-compatible Poseidon for BLS12-381, in-circuit Jubjub/EdDSA/Pedersen primitives, and three ADRs scoping the next round of zk-credential work.

Changes

  • Poseidon library (zeroj-circuit-lib/.../circuit/lib/poseidon/)
    • PoseidonParams, PoseidonHash, PoseidonGrainLFSR — Grain-LFSR-driven parameter derivation
    • PoseidonParamsBN254T3, PoseidonParamsBLS12_381T3, PoseidonParamsBLS12_381T5 — generated constants
    • PoseidonParamsCodegen + Sage generator (generate_parameters_grain.sage) for reproducible parameter generation
    • PoseidonCacheVersion for cached-parameter version pinning
    • Refactor of existing Poseidon/PoseidonN/SignalPoseidon to consume parameter sets
  • Jubjub library (zeroj-circuit-lib/.../circuit/lib/jubjub/)
    • JubjubCurve, JubjubPoint — out-of-circuit twisted Edwards arithmetic on Jubjub
    • InCircuitJubjub, InCircuitPedersen, InCircuitEdDSAJubjub — circuit gadgets
    • EdDSAJubjub, PedersenCommitment — host-side helpers
  • Circuit core — Small extensions to CircuitAPI/CircuitAPIImpl/CircuitBuilder/ConstraintGraph to support the new gadgets
  • Tests — Cross-verification against Sage reference output, parameterized gadget tests, and unit tests for Jubjub, EdDSA, Pedersen, Poseidon params/cache/LFSR

satran004 and others added 4 commits April 18, 2026 01:32
The BN254-over-BLS hybrid previously used by BLS12-381 Poseidon callers
was non-interoperable with any published BLS12-381 Poseidon implementation,
making third-party verification of ZeroJ-produced hashes impossible.

ADR-0015 replaces the hybrid with paper-canonical BLS12-381 Poseidon
(t=3, alpha=5, RF=8, RP=57) while preserving BN254 circomlib compatibility
for existing callers.

Changes:
- PoseidonGrainLFSR: pure-Java port of the hadeshash Sage parameter
  generator, byte-verified against iden3/circomlibjs BN254 constants.
- PoseidonParams record + codegen-produced BN254/BLS12-381 t=3 presets.
- Poseidon / PoseidonN / SignalPoseidon gadgets parameterized on
  PoseidonParams; back-compat no-param overloads default to BN254.
- PoseidonHash standalone BigInteger permutation for off-circuit use.
- CircuitAPI.requireField + CircuitBuilder compile/witness-time guard:
  converts field-vs-curve mismatches from silent non-canonical-hash
  footguns into thrown exceptions.
- PoseidonCacheVersion: SHA-256-derived marker that auto-wipes stale
  SRS/R1CS/Merkle caches when Poseidon parameters change.
- SageMath reference implementation committed under src/test/resources/
  poseidon-sage/ with Docker-pinned golden output. Test asserts Java
  fixtures byte-match the Sage-produced paper-spec reference.
- PoseidonConstants marked @deprecated; retained as BN254 facade.

Evidence: 92 tests pass including LFSR byte-match vs circomlibjs,
in-circuit == off-circuit self-consistency over 100 random inputs per
preset, Sage golden-file match for Poseidon_BLS12_381(0,0)/(1,2)/(123,456),
field-guard rejections, cache-version wipe behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds the twisted-Edwards Jubjub curve embedded in the BLS12-381 scalar
field, with both off-circuit primitives (curve arithmetic, EdDSA,
Pedersen) and in-circuit gadgets (Jubjub doubling/addition, EdDSA
verify with kModL/kQuotient witness reduction, Pedersen commitment).
Tests cover round-trip signing/verification both off- and in-circuit.

Also gitignores .playwright-mcp/ used by browser MCP runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds standards-compatible Poseidon constants for t=5 (4-input hash) on
BLS12-381 alongside the existing t=2/3/4. Bundles the reference Sage
script (generate_parameters_grain.sage.py) so the constants can be
regenerated and audited. Minor LFSR + codegen tweaks support t=5.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Captures the design for selective-disclosure-friendly credential circuits
(rich multi-field VC, EdDSA-Jubjub issuer signature, predicate-per-circuit
pattern) underpinning the selective-disclosure usecase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@satran004 satran004 changed the title Feat/poseidon bls12 381 Add BLS12-381 Poseidon, Jubjub-in-circuit support May 6, 2026
@satran004 satran004 merged commit 4ed5b71 into main May 6, 2026
9 checks passed
@satran004 satran004 deleted the feat/poseidon_bls12-381 branch May 6, 2026 12:49
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