Run a solver
Proving
The prover modes a solver chooses between, the proof window, what prove_batch verifies, and the measured cost of each step.
A cleared batch is settled on the solver's bond. The proof is what releases that bond and pays the fee, and the node makes one for every batch its solver clears.
What is proven
The proof says that the guest program ran on this batch's input records, the state the solver cleared against and the result it posted, and accepted them. The guest runs check, the function the node already ran before posting, and commits 104 bytes: the batch id, the input hash, the state hash and the result hash.
The clearing conditions has what check requires. The guest program and verifying a batch yourself has the guest and how to run it.
The node writes the same three values to the prover that it used to clear: the records it read from the API and checked against the on-chain input hash, the state it read from the chain before the clearing, and the result solve returned. It saves the state and the result before it sends the clearing, so a node that restarts proves from those and never solves a cleared batch again. Run the node has where they are kept. The guest ELF comes from the file at GUEST_ELF_PATH. The program accepts a proof only from the guest whose verifying key hash is stored in its Config account as sp1_vkey_hash.
Prover modes
PROVER chooses where the proof is made. It has no default: una-solver run stops at start unless it is set to one of the two. Both modes produce an SP1 Groth16 proof with sp1-sdk 5.2.4. Each has its build feature.
| Mode | Where the proof is made | Build | What it needs |
|---|---|---|---|
PROVER=cpu | On the node's own machine, by the SP1 CPU prover with native gnark for the Groth16 step. | --features native-gnark | The guest ELF. |
PROVER=network | On the Succinct prover network. | --features prove | The guest ELF and NETWORK_PRIVATE_KEY. |
prove compiles sp1-sdk into the node. native-gnark turns on prove and links gnark into the binary for the Groth16 step, and its build needs Go installed. The node's Dockerfile builds with --features prove, the build for the prover network.
cargo build --release --features native-gnark # PROVER=cpu
cargo build --release --features prove # PROVER=networkWith PROVER=network and no key, or an empty one, the node reports NETWORK_PRIVATE_KEY is required when PROVER=network for the batch and sends nothing.
In either mode the node sets up the proving and verifying keys from the ELF, requests a Groth16 proof, and verifies the proof locally against the verifying key before it builds the transaction. A proof that fails that check is never sent.
PROVER=cpu GUEST_ELF_PATH=./guest/elf/una-guest una-solver runPROVER=network NETWORK_PRIVATE_KEY=your-prover-network-key GUEST_ELF_PATH=./guest/elf/una-guest una-solver runBoth lines also need SOLVER_KEYPAIR, RPC_URL and API_URL, as on Run the node.
The proof window
When clear_batch is accepted the program sets the batch's deadline:
proof_deadline_slot = clear slot + proof_window_slots
prove_batch is accepted while the current slot is at or before proof_deadline_slot. The default proof window is 300 slots, about 60 seconds at 200 ms a slot. The live value is proofWindowSlots from una.protocol(), and each cleared batch shows its own deadline at /batches/[id] as Proof due in, with the slot.
Once the slot is past the deadline, prove_batch raises ProofWindowExpired and anyone may send slash_batch. The bond locked behind the batch moves out of the solver's stake into the batch's cover, the solver's slash_count rises by one, and the batch's status becomes Slashed. The batch pays the solver no fee. Slashing and cover has how the slash is shared across the stake and who claims the cover.
What prove_batch verifies
prove_batch
proofbytesrequired- The SP1 Groth16 proof, 260 bytes.
Any key may sign it. The fee and the bond release go to the batch's solver whoever sends the proof. The node signs with the operator's key.
The program does not take the public values from the sender. It builds them from the batch account:
- The batch is Cleared, and the slot is at or before its deadline.
- It recomputes the result hash from the tokens, prices, fees and fill fractions stored at clearing.
- It joins the batch id, the stored input hash, the stored state hash and that result hash into the 104 bytes of public values.
- It checks that the proof is 260 bytes and that its first 4 bytes are the first 4 bytes of the SHA-256 of the Groth16 verifying key in
Config. - It verifies the Groth16 proof with two public inputs:
sp1_vkey_hashfromConfig, and the SHA-256 of the public values with its top 3 bits cleared. The pairing check runs on Solana's alt_bn128 syscalls.
A proof for another input, another state, another result or another guest fails step 5.
When the proof verifies, the same instruction:
- sets the last proven price of every batch token other than wSOL to the batch's price for it,
- splits each token's clearing fee (Commission and payouts),
- lowers the solver's
bond_locked_lamportsby the batch's locked bond and raisesbatches_provenby one, - sets the batch Proven with its
proven_slot, and emitsBatchProvenwith the bond released.
| Error | Raised when |
|---|---|
BatchNotCleared | The batch is open, sealed or rolled. |
BatchAlreadyProven | The batch is already proven. |
BatchAlreadySlashed | The batch is slashed. |
ProofWindowExpired | The slot is past proof_deadline_slot. |
InvalidProof | The proof is not 260 bytes, its first 4 bytes do not match the verifying key, a point in it does not decode, or the pairing check fails. |
InvalidBatchAccounts | The batch's Token accounts are not all passed, in the batch's order. |
InvalidFeeRecipientAta | The four accounts that pay a token's protocol share are missing or wrong. |
Measured figures
Each figure is a measurement, with what it was measured on. The fixture batch is the batch the program's own test proves and verifies: 2 tokens and 1 pair.
| Step | Measured | On |
|---|---|---|
clear_batch | 157,092 compute units | A batch of 2 tokens and 1 pair, in the program's test. |
prove_batch | 180,087 compute units | The fixture batch with its real Groth16 proof, in the program's test. |
| The guest's check | 140,942 cycles | The fixture batch, executed in the SP1 zkVM. |
| Making the proof | 141 seconds | The fixture batch, SP1 5.2.4 Groth16 with native gnark on a 32-core CPU. |
| A batch through the node | 157 seconds | A batch of one order, cleared and proven on chain by the node with PROVER=cpu on the same CPU. |
| The proof | 260 bytes | Every batch. |
| The public values | 104 bytes | Every batch. |
The node measures each transaction before it sends it and sets the compute limit from that measurement, so it needs no figure configured. How a transaction is sent has the steps.