Skip to content
Open app

How it worksThe proof

The proof

What every message proves, the five public inputs, the daily nullifier, and where the proof is made and checked.

Every message carries one Groth16 proof over BN254, written in Circom. The program accepts the message only if the proof verifies, and the proof says only that some unexpired pass in the pool is sending within its daily limit, for this payload, through this relay. Circuit gives every signal and constraint.

What it states#

In plain termsIn the circuit
I hold a pass in the pool.leaf = Poseidon(Poseidon(secret), limit, expiry) is under root
I have not used up today's limit.counter < limit
My pass has not expired.day ≤ expiry
This is a message I have not sent before.nullifier = Poseidon(secret, day, counter)
It is this payload, through this relay.payload hash and relay are bound to the proof

The pass secret, the limit, the expiry day, the counter and the Merkle path stay on the writer's device. None of them is in the transaction.

The five public inputs#

InputWhat it says
Roota recent root of the pool
Daytoday
Nullifierfollows from the pass, the day and the counter
Payload hashthis exact payload
Relaythis relay submits it

As field elements#

The verifier sees 6 BN254 field elements, in this order, each as 32 big-endian bytes:

#ElementHow it is formed
1rootThe pool root, as given in the instruction.
2dayThe day as an unsigned 64-bit integer, padded to 32 bytes.
3nullifierAs given in the instruction.
4payloadHashSHA-256 of the payload, first 31 bytes, behind a leading zero byte: a 248-bit value.
5relayLowThe relay's 32-byte address read as one big-endian integer; its low 128 bits, the address's last 16 bytes.
6relayHighThe high 128 bits of the same integer, the address's first 16 bytes.

An address is 256 bits and a BN254 field element holds less, so the relay enters as two 128-bit limbs and keeps every bit of the address. The payload hash is cut to 248 bits for the same reason.

The program forms the last three itself: it hashes the payload it was given and splits the key of the account that signed. Only root, day and nullifier come from the instruction's arguments.

The daily nullifier#

Each message reveals one nullifier:

Text
nullifier = Poseidon(secret, day, counter)

counter is any whole number with 0 ≤ counter < limit. On a given day a pass with a limit of N can therefore produce exactly N nullifiers, one for each counter value, and no more: a counter at the limit fails the proof, and each counter value gives one fixed nullifier for that day. The next day changes day, so the same counters give N new nullifiers.

post records each nullifier as a Nullifier account at an address derived from the day and the nullifier. A second post with the same nullifier on the same day finds the account already there and fails with SpentNullifier. Because the nullifier is a hash of the secret, nothing in it says which pass made it, and two nullifiers of one pass look unrelated.

A day is the chain's Unix time divided by the configured day length, rounded down. The proof's day must equal the program's day when the post executes, or it fails with WrongDay; the expiry check day ≤ expiry_day is inclusive, and buy_pass sets expiry_day to the purchase day plus the pass's days minus one, so a pass of N days proves on N days.

What binds a proof to its payload and relay#

The payload hash and the relay limbs are public inputs, and the program computes them itself from the transaction it is executing. A proof made for one payload and one relay verifies only with those two:

  • A relay that changes any byte of the payload changes the payload hash, and the proof fails with ProofInvalid.
  • A relay that hands the proof to another relay to submit changes the signer, so the relay limbs differ and the proof fails the same way.

Inside the circuit, each of these values is copied into a private signal that must equal it and is range-checked (248 bits for the payload hash, 128 bits for each limb). The range checks keep a non-linear constraint on every binding, so the compiler's simplification cannot remove it.

A relay that receives a proof made for another relay refuses it before sending, with RELAY_MISMATCH. Relays covers what a relay checks.

Proving in the browser#

The writer's device makes the proof with snarkjs, in the browser. The SDK loads the circuit's talaria.wasm and final.zkey, builds the witness from the pass, the counter, the Merkle path and the public inputs, and runs groth16.fullProve in a single thread. It checks that the public signals the prover returns equal the ones it expected, then packs the proof into 256 bytes in the layout the on-chain verifier reads. Circuit lists the files, and send does all of this for every message.

In Node, one measured run took 1,882 ms. In a browser: 1,400 ms. /proof makes a real proof in your own browser with a demonstration pass and shows its public inputs, its size and how long it took.

Verification on chain#

post verifies the proof with groth16-solana against the verification key compiled into the program, using Solana's alt_bn128 pairing syscalls. It checks the day, the root, the payload and the nullifier first, and creates the Nullifier account only after the proof verifies.

A whole post, verification included, measured 120,879 compute units. Measured figures gives that figure with the transaction it came from.