Skip to content

research: poseidon2-hash-swap - #45

Open
alexandre-mrt wants to merge 1 commit into
mainfrom
claude/intelligent-cannon-09x8uf
Open

research: poseidon2-hash-swap#45
alexandre-mrt wants to merge 1 commit into
mainfrom
claude/intelligent-cannon-09x8uf

Conversation

@alexandre-mrt

Copy link
Copy Markdown
Owner

Summary

Nightly research loop, 2026-08-27. Queue item #2: measures a domain-separated Poseidon2 sponge (@taceo/circom-lib) against Veil's current circomlib Poseidon, at every hash shape transfer.circom/withdraw.circom/compliance.circom actually call — both in isolation (8 microbenchmark circuits) and as full production-shaped variant circuits (circuits/bench/poseidon2/full/).

The headline number is more nuanced than the starting hypothesis:

Circuit Constraints (old → new) Proving time (old → new, mean of 10)
transfer 13,611 → 15,194 (+11.6%) 788.3 ms → 745.7 ms (-5.4%)
withdraw 3,058 → 3,372 (+10.3%) 272.6 ms → 236.4 ms (-13.3%)
compliance (partial swap — leaf hash unchanged) 12,743 → 13,953 (+9.5%) 762.1 ms → 763.0 ms (+0.1%, noise)

Total R1CS constraints go up for every circuit (the published Poseidon2 templates' matrix-multiplication layers don't fully collapse to linear combinations in circom's optimizer), but measured Groth16 proving time still goes down for transfer and withdraw, because non-linear (witness-generation) constraints drop in every shape and none of the three circuits cross a power-of-two constraint boundary. compliance is a wash because its credential-leaf hash needs a Poseidon2 state size (t=5) that isn't published anywhere — partial swap only, called out explicitly.

A from-scratch JS Poseidon2-sponge implementation is cross-checked against the compiled circuit's real witness (4/4 exact match) before being trusted to build any full-circuit witness. A negative test (forged commitment, forged nullifier against withdraw_v2) confirms no under-constrained signal was introduced.

No production circuit, VK, or frontend code is touched. These are research artifacts — the swap is validated and measured, BASELINE.md gets a new "Alternative constructions" section, but shipping it is a separate, scoped migration (new t=5 parameters, a real multi-contributor ceremony, VK updates via the timelock, frontend/JS rewiring) — now the top item in EXPERIMENTS.md.

Also re-confirms on-chain gas (queue item #1) as structurally blocked this session (RPC + GitHub releases + crates.io all denied/unavailable), while discovering git clone of MystenLabs/sui does work unlike release downloads — noted for a future dedicated night.

Full report: docs/research/2026-08-27-poseidon2-hash-swap.md

Test plan

  • transfer.circom / withdraw.circom / compliance.circom real-Groth16 suites: 43/35/30 pass (production circuits untouched)
  • Proof converter: 109/109 pass
  • Compliance utils: 67/67 pass
  • Frontend (vitest): 19/19 pass
  • Property-based fuzz suite: 6/6 properties pass
  • Poseidon2 sponge cross-check (JS vs compiled circuit witness): 4/4 match
  • Negative test (forged commitment / nullifier against withdraw_v2): both rejected
  • Move contracts (sui move test) — NOT RUN, no sui CLI in this session (see report's note on queue item feat: Veil privacy payment protocol — full stack MVP #1)

Generated by Claude Code

Measures a domain-separated Poseidon2 sponge (@taceo/circom-lib) against
Veil's current circomlib Poseidon at every hash shape the three production
circuits call, both in isolation and as full production-shaped variant
circuits (circuits/bench/poseidon2/). Result is more nuanced than the
starting hypothesis: total R1CS constraints go up ~10-12% per circuit, but
measured Groth16 proving time still drops (transfer -5.4%, withdraw -13.3%,
compliance a wash pending missing Poseidon2 t=5 parameters), because none
of the three circuits cross a power-of-two constraint boundary and the
swap's non-linear constraint count drops in every shape.

A from-scratch JS Poseidon2-sponge implementation is cross-checked against
the compiled circuit's actual witness (4/4 exact match) before being
trusted to build any full-circuit witness. A negative test confirms no
under-constrained signal was introduced (forged commitment/nullifier both
rejected). No production circuit, VK, or frontend code changed — see the
report's Verdict for what shipping this swap would still require.

Also re-confirms on-chain gas measurement (queue item #1) as structurally
blocked this session (RPC, GitHub releases, and crates.io all denied or
unavailable), while discovering `git clone` of MystenLabs/sui does work,
unlike release downloads — noted in EXPERIMENTS.md for a future dedicated
night.

Full report: docs/research/2026-08-27-poseidon2-hash-swap.md
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