Docs / How it works
How it works
A deposit becomes a leaf in a tree. A withdrawal proves it owns some leaf, and that the leaf's label sits in an approved set, without saying which leaf.
1. Deposit
Your browser picks two random field elements, a nullifier and a secret, and sends the program only their hash:
precommitment = Poseidon(nullifier, secret)
The program takes its fee from the deposit, gives the deposit a label, and builds the commitment itself, so the value and the label are exactly what the chain recorded:
label = hash_to_field(2, scope, depositor, nonce)
commitment = Poseidon(value - fee, label, precommitment)
The commitment is appended to the state tree, and the program keeps the last 64 tree roots. No account is created per deposit: the tree lives inside the pool account.
Keep the nullifier and the secret. They are the note, and the only way to spend it.
2. The association set
A set provider reads every deposit label, removes the ones that came from flagged addresses, builds a Merkle tree of the rest and publishes its root with publish_root. The rule is public and the inputs are public, so anyone can rebuild the tree and check that the published root matches.
The program accepts a provider's current root, and its previous root for 150 more slots, so a proof built just before a new root lands still works.
3. Withdraw
To withdraw, you prove with Groth16 that:
- your commitment is a leaf of a recent state root;
- its label is a leaf of the provider's association-set root;
- you know the nullifier and secret behind it;
- the remaining value goes into a new commitment, so a note can be spent in parts.
The proof is also bound to a context hash of the pool, the submitter, the recipient, the fee recipient and the relayer fee. A relayer who changes any of them breaks the proof.
The program checks the roots, verifies the proof, creates a nullifier account (a second spend of the same note fails right there), inserts the new commitment and pays out.
4. Ragequit
If no provider includes your deposit, you can still leave. Ragequit reuses the same circuit with a one-leaf set: your own label. Only the key that made the deposit can reproduce that label, and the money goes back to that key, in the open. The exit is public, which is the price of skipping the set, and it is always available.
User deposit(value, precommitment) -> Pool program
Pool program Deposited(label, commitment, leaf, root) -> everyone
Set provider publish_root(root, set_hash) -> Pool program
User withdraw(nullifier_hash, proof, roots) -> Pool program
Pool program lamports -> recipient