Skip to content

Switch Groth16 SNARK circuit from SHA-256 to Poseidon hash#31

Merged
sweis merged 1 commit intomainfrom
claude/symmetric-key-proofs-lgsxG
Feb 26, 2026
Merged

Switch Groth16 SNARK circuit from SHA-256 to Poseidon hash#31
sweis merged 1 commit intomainfrom
claude/symmetric-key-proofs-lgsxG

Conversation

@sweis
Copy link
Copy Markdown
Owner

@sweis sweis commented Feb 26, 2026

Replace the SHA-256 gadget (~150K R1CS constraints) with Poseidon sponge (~480 constraints) for the in-circuit key hash and MAC computation. This yields ~300x fewer constraints and significantly faster prove times (~3s vs ~30s in debug).

  • Add src/poseidon.rs: BN254 Poseidon config (t=3, rate=2, alpha=5), native hash, bytes<->field element conversion
  • Rewrite src/snark.rs: PoseidonKeyProofCircuit with 3 native field element public inputs (key_hash, payload_hash, mac) instead of 768 Boolean vars; private witness is 1 field element (key)
  • Rename Groth16Sha256 -> Groth16Poseidon across all modules
  • Update CLAUDE.md documentation

All 132 tests pass. Clippy clean. No wire format changes (algorithm 4 byte value unchanged).

https://claude.ai/code/session_01LJyL1uYXD1JHMq8Q3v7shM

Replace the SHA-256 gadget (~150K R1CS constraints) with Poseidon sponge
(~480 constraints) for the in-circuit key hash and MAC computation. This
yields ~300x fewer constraints and significantly faster prove times (~3s
vs ~30s in debug).

- Add src/poseidon.rs: BN254 Poseidon config (t=3, rate=2, alpha=5),
  native hash, bytes<->field element conversion
- Rewrite src/snark.rs: PoseidonKeyProofCircuit with 3 native field
  element public inputs (key_hash, payload_hash, mac) instead of 768
  Boolean vars; private witness is 1 field element (key)
- Rename Groth16Sha256 -> Groth16Poseidon across all modules
- Update CLAUDE.md documentation

All 132 tests pass. Clippy clean. No wire format changes (algorithm 4
byte value unchanged).

https://claude.ai/code/session_01LJyL1uYXD1JHMq8Q3v7shM
@sweis sweis merged commit 89dc922 into main Feb 26, 2026
5 of 6 checks passed
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.

2 participants