This repo implements an offchain orderbook (CLOB) that produces an SP1 proof for each batch of matching and state transition; the onchain verifier accepts the new canonical state root only if the proof verifies.
crates/core: shared serialization, keccak hashing, sparse Merkle map, matching engine, rounding, state modelcrates/guest/src/main.rs: SP1 guest that verifies a batch and commits public inputscrates/host/src/main.rs: host runner that assembles inputs/witnesses/proofs (JSON-driven, auto-sign)contracts/src/ClobVerifier.sol: Solidity verifier that updates canonical state rootcontracts/test/ClobVerifier.t.sol: Solidity unit testscontracts/test/ClobVerifierFixture.t.sol: Solidity fixture testspec/SPEC.md: normative protocol specexamples/input.json: example batch + state inputscripts/run_clob_example.sh: end-to-end host executioncontracts/testdata/proof.json: fixture public inputs for Solidity tests
cargo test -p clob-coresh scripts/run_clob_example.shcd contracts && forge test -v- Spot-only continuous CLOB (limit orders only, GTC/IOC)
- Deterministic price-time FIFO at each tick; maker-price execution; partial fills allowed
- Taker fee charged in quote; deterministic rounding (see
spec/SPEC.md)
All commitments use Keccak-256. State is a 256-bit sparse Merkle map with:
- leaf hash
keccak256(0x00 || key32 || valueHash32)for non-empty values - node hash
keccak256(0x01 || left32 || right32) - empty leaf =
0x00..00
Public input schema (fixed-width, big-endian):
struct PublicInputs {
bytes32 prevRoot;
bytes32 newRoot;
bytes32 batchDigest;
bytes32 rulesHash;
bytes32 domainSeparator;
uint64 batchSeq;
uint64 batchTimestamp;
bytes32 daCommitment;
bytes32 tradesRoot;
bytes32 feesRoot;
}See spec/SPEC.md for the exact encoding and hashing rules.
- Offchain: build batch + membership proofs; compute
batchDigestand witness data - SP1 guest: verify signatures/nonces, execute deterministic matching, update sparse Merkle root
- Onchain: Solidity verifier checks proof and updates canonical root
- Signature verification and strict nonce sequencing per account
- Batch sequencing enforced by
batchSeq - Omission resistance via best-tick pointers + linked-list invariants for ticks/orders
- Checked arithmetic with balance caps; deterministic rounding rules
- Byte-precise encoding and hashing;
spec/SPEC.mdis the normative reference
See spec/SPEC.md.