zkdefi · notes

A zero-knowledge perpetual DEX in a single zkVM proof

The promise of decentralized exchanges has always been that you don't have to trust them. The reality is that for anything more complex than a simple AMM swap — perpetuals, options, leverage, liquidations, funding-rate machinery — you still trust the matching engine. On centralized exchanges you trust the operator. On most "decentralized" perp DEXs you trust the sequencer, the relayer, or the oracle. The trust never quite vanishes; it just gets renamed.

zk-perp is a proof-of-concept for moving the trust into a single zero-knowledge proof that anyone can verify locally.

The construction is straightforward in shape, hairy in detail:

The trust model collapses to this: as long as the zkVM is sound and the verifier contract is correct, you can run a local node, fetch the state, fetch the SNARK, verify it yourself, and know that the off-chain engine did exactly what it was supposed to. Order matching, margin enforcement, liquidations — all attested by a 200-byte proof.

The leverage is what makes this interesting. You move a complex stateful system off-chain without abandoning verifiability. The on-chain cost is the verifier contract's gas plus the storage for the state root — orders of magnitude less than running the matching engine in Solidity. The off-chain machinery can be ordinary code with ordinary tools.

The PoC implements the full API — submit order, query state, query position, query funding rate, query margin. Built with RISC Zero. The interesting work was in the state transition function: writing it once, in Rust, and trusting that the zkVM proof attests it executed exactly as written. The funding-rate math, in particular, is finicky enough that getting it right under proof was the central engineering puzzle.

What becomes possible: a perp DEX where the trust footprint of running it is the trust footprint of one cryptographic primitive, not "the operator promises."

#zk #risc-zero #perpetuals #dex #defi