circomlib. Two instances of one template are compiled: a 2-input circuit for everyday
transactions and a 16-input circuit for consolidating many notes at once.
Files
Both instances have 20 levels and exactly 3 outputs, so every accepted transaction appends three
leaves whatever its size.
merkleProof.circom deliberately only computes a root and leaves the
comparison to the caller; that is what lets the transaction circuit skip the membership check for
dummy inputs.
A note is (amount, publicKey, blinding, asset) and the circuit derives the same four Poseidon
hashes the SDK does:
nullifierKeyDomain() is the ASCII bytes of fluton-nullifier-key read as an integer, and it must
match the SDK’s own domain constant. Binding the packed leaf index into the nullifier gives each
leaf exactly one nullifier. The nullifier depends on the private key only through nullifierKey,
a one-way derivation, which is what makes a read-only view key possible. See
notes and proofs and
keys and view keys.
Public inputs
Circom orders public signals by declaration, so the order injoinSplit.circom is the order of
publicSignals[] off-chain and of the verifier’s input[] array on-chain:
rootpublicAmountextDataHashpublicAssetinputNullifier[nIns]outputCommitment[nOuts]
publicAsset from ExtData, never from the caller.
The private inputs are the single
asset of the transaction, and per slot the amounts, private
keys, blindings, path indices and sibling hashes of the notes spent, plus the amounts, recipient
public keys and blindings of the notes created.
The constraints that matter
- Membership, skipped for dummies. Each input’s commitment is hashed, its Merkle root computed,
and the result compared to
rootthroughForceEqualIfEnabledwith the input’s own amount as the enable signal. An input of amount 0 therefore needs no real leaf, so unused slots carry freshly generated dummy notes. - Nullifier correctness. Each slot’s recomputed nullifier must equal the public
inputNullifierfor that slot, and no two nullifiers in one proof may be equal. - Output range check below 2^248. Every output amount passes
Num2Bits(248). Inputs need no check, because every real input was once a range-checked output. With amounts under 2^248, even 16 of them sum to under 2^252, well below the field order, so a sum can never wrap. - Value conservation.
sumIns + publicAmount === sumOuts, over the field. Because the public amount is bounded by the pool and every note amount is range-checked, this holds over the integers too. - The asset constraint. One private
assetsignal enters all input and output commitments, so a transaction can only spend and create notes of a single asset. On top of that,(asset - publicAsset) * publicAmount === 0: whenever value crosses the boundary the asset is pinned to the public one, and when nothing crosses the asset stays private whilepublicAssetremains bound by the proof. Together with the range check, a note of an asset that holds no value is provably worth zero. Many tokens, one pool works through the argument. - Ext-data binding.
extDataHashis squared into a dummy signal, which is enough to make the proof depend on it. Tamper with any public field on-chain and the hash changes, so the proof no longer verifies and a mempool observer cannot re-target it.
Verifiers
Each circuit has one on-chain verifier, exported from its proving key by snarkjs:transaction
into Verifier.sol as Groth16Verifier, and transaction16 into Verifier16.sol as
Groth16Verifier16. The pool holds both and picks one by the number of nullifiers in the proof
(contracts). Both circuits are compiled with Circom 2.2.3 at --O2: 13,425
constraints for the 2-input circuit and 96,018 for the 16-input one, inside the 2^17 (131,072)
limit of the powers-of-tau file the setup starts from. Because the verifiers
are exported from the proving keys, proofs made with any other key are rejected by the
deployed verifier; the relayer’s fee collection therefore needs the proving keys of the
ceremony below (Running a relayer).
Trusted setup
Each circuit’s proving and verifying keys come from a Groth16 trusted setup for that circuit. The setup bears on proof unforgeability only: the hiding properties of the commitments, the ciphertexts and the anonymity set do not depend on it. The keys of the deployed pool come from a ceremony in two phases:- Phase 1 is the Perpetual Powers of Tau after its 80th contribution, prepared for 2^17
constraints (
ppot_0080_17.ptau). - Phase 2 ran once per circuit. It took 222 contributions and was closed with a random
beacon: the hash of Ethereum block
26408500, hashed 2^20 times over.
transcript.json), which lists every contribution with its hash, the two verification keys, the
two Solidity verifiers and a verify.sh script. The final proving keys are
transaction_final.zkey and
transaction16_final.zkey.
The
verifier and verifier16 contracts of the deployment are these two
verifiers, with their sources verified on Arbiscan, so anyone can compare the verification key
inside a deployed verifier with the one the ceremony published.