Compute
Overview
| Benchmark | fuzz/tests/compute.rs, in the fuzzer's litesvm world |
| Program build | target/deploy/unwind.so, built with --features devnet |
| Gate | A row more than 10% over its recorded budget fails the test |
| Recorded numbers | None yet |
A Solana transaction gets at most 1.4 million compute units, and every instruction here runs inside one. The benchmark runs the compiled program, not a Rust build of it, so what it reports is what a validator would charge.
It loads the program into litesvm the way the stateful fuzzer does
(fuzz/tests/support/env.rs) and bootstraps the same main fixture: three
Pyth markets, one keeper-priced market, one folded market and two custodies.
A fixed script then walks each path below once. The count for each row is
the program's own consumed N of M compute units log line. That covers the
token transfers the instruction makes, and not the compute-budget
instruction in front of it.
Running it
anchor build -- --features devnet
cd fuzz
cargo test --release --test compute -- --nocaptureThe test prints a table with one row per path: what it consumed and its budget. The numbers are deterministic for one build of the program. Run it before and after a change, and a moved number is the change's doing.
What is measured
| Row | Path |
|---|---|
clear_batch, empty | A due batch with no orders seals and reopens |
submit_order, open | A taker's first open in a market, which creates the position |
clear_batch, 1 order | That one open against the pool's quote |
settle_order, open | Settling it into the position |
cancel_batch_order | A resting open withdrawn, its collateral returned |
submit_order, close | A reduce-only order for the whole position |
settle_order, close | Settling it at its flow's clearing price, the payout transferred |
submit_flip | A long turned short in one order: its close half and open half into the batch |
settle_order, flip | Its open half settled first, which settles the close half in the same instruction |
clear_batch, 32 orders | Half a batch of takers, buyers and sellers |
clear_batch, 64 orders | A full batch |
push_mark | A keeper's push to an observed market |
observe | A permissionless fold of a pool reading into an observed mark |
accrue_funding | One market's funding brought up to now |
checkpoint_aum, every market | A fresh AUM checkpoint across all five markets |
add_liquidity | An LP deposit |
request_withdraw | LP shares put into escrow |
cancel_withdraw | The escrow returned |
claim_withdraw | A claim after the cooldown |
step_risk_price | One step of the risk price after a 25% drop |
liquidate | A 5x long liquidated after that drop |
Recorded numbers
None yet. The SBF toolchain (cargo-build-sbf) was not available where the
benchmark was written, so the program could not be built and nothing was
measured. Nothing here is estimated.
To record them, run the benchmark, copy its table here, and copy each row's
count into BUDGET in fuzz/tests/compute.rs. From then on the test fails
when a row grows past its budget by more than 10%. A change that costs
compute on purpose records the new number in both places, in the same
commit.
Verification
Kani is a model checker for Rust. A test checks the inputs somebody wrote down. A Kani harness makes its inputs symbolic, states what they may be, and checks a property for every input inside those bounds, or produces the input that breaks it.
Fees
Fees are charged on opening, closing and liquidation. Each is set per market. Makers and takers pay the same rate: maker or taker decides which flow an order clears in (see The auction), not what it pays.