Sybilla
A Rust/Leptos Starknet DEX prototype where SurrealDB relations model users, markets, intents, trades, event chains, wallet sessions, proof input, and withdrawal execution.
Signed trading state, replayable withdrawals
Hard part: preserving signatures, consumed intents, balance changes, and ordered events that prove withdrawals.
Argent signs a SessionAuth for a temporary key, SurrealDB links addresses, users, markets, intents, trades, notes, and events, then Cairo replays the event chain to compute withdrawable collateral.
- Boundary note
- The relation graph is the interesting artifact: users, wallet addresses, intents, markets, trades, notes, SessionAuth records, and proof events all carry meaning.The session-key model is explicit prototype custody: a browser temporary key improves UX, but sessionStorage is not a production-grade key store.
- Evidence path
- SurrealDB relation graph / SessionAuth key handoff / Deterministic matching loopProof path: SurrealDB relations, SessionAuth, matching transitions, event-chain serialization, Cairo replay, prover output, vault withdrawal.
- What it proves
- Shows ownership across product UI, wallet authorization, database state, proof generation, and on-chain withdrawal execution
- Turns a normal trading action into a replayable proof path from signed intent to withdrawal limit
How the data moves through the system
First read the data path. Then use the code hooks as pointers to the mechanisms that make the claim inspectable.
address_user, intent_user, intent_market, and trades keep wallets, users, orders, markets, and fills connected as graph records.
Argent signs SessionAuth; Cairo accepts the session event before checking later intent and withdrawal signatures under the temporary key.
events_chain links each proof-facing record to the previous one, so traversal rebuilds ordered withdrawal proof input.
The Cairo apply function replays notes, trades, settlements, and signed withdrawal to verify requested amount against collateral.
A live intent belongs to user and market and is absent from the consumed side of trades.
SurrealDB filters opposite-side makers by sign, price, market relation, and prior trade relation before Rust computes fills.
SessionAuth moves verification from wallet key to temporary key for later trade and withdrawal signatures.
Withdrawal serializes event chain, streams proof generation, registers verifier output, calls vault, and records the next note.
How the system progresses
A short staged view of the system from start to final output.
Authorize a trading session
Argent signs typed session data, the backend verifies nonce and signature, and signed_message enters the event chain as SessionAuth.
Match through the relation graph
The taker intent signs price and quantity, SurrealDB selects compatible makers, Rust computes full or partial fills, and relations recreate residual maker/taker state.
Replay events into a proof-backed withdrawal
The app traverses post-Withdraw events, serializes Cairo input, proves the Cairo replay, verifies calldata on-chain, then calls the vault.
Proof path: SurrealDB relations, SessionAuth, matching transitions, event-chain serialization, Cairo replay, prover output, vault withdrawal.
This chapter is architecture-focused; the public proof is the system model.
Finish the evidence first. The full-screen environment is the closing section.
Open the full-screen environment for this project
One project mechanism, isolated from the article.
Order Matching And Settlement Flow
SurrealDB relations, session-key signatures, matching transitions, event-chain replay, and withdrawal proof prep in one flow.
Trading flow over Sybilla records: notes, users, wallet sessions, intents, markets, trades, event-chain links, and proof input.
Open environment