Topi is a post-quantum private payment system built on Ethereum. It allows users to deposit, hold, and privately withdraw ETH without exposing their transaction history, their physical network location, or their wallet identity.
The Problem
Existing on-chain privacy protocols (such as Tornado Cash and Railgun) suffer from three critical vulnerabilities:
- The Quantum Threat: They rely on elliptic-curve pairings (BN254/Groth16) and classical ECDSA signatures. When quantum computers arrive, every historical and active note in these pools can be unmasked and drained.
- Network Layer Leakage: Transactions are sent directly to RPC nodes and public mempools, broadcasting the user's IP address, ISP, and timing metadata.
- The Relayer & Gas Bootstrapping Dilemma: To withdraw to a fresh address without linking identity, users need a way to pay gas. Traditional relayer networks are fragile, centralized, and constantly targeted for censorship.
What Topi Delivers
Topi eliminates all elliptic curves, pairings, and trusted setups across the entire transaction path—replacing them with hash-based, lattice-based, and symmetric constructions from packet transmission to on-chain execution.
How the System Works
- Shielded Deposit: A user deposits ETH into the pool alongside a blinded precommitment. The smart contract assigns an index, computes the note commitment, and appends it to an incremental Poseidon2 Merkle tree (the pool tree) and an association tree.
- Zero-Knowledge Spend Proof: To withdraw, the user’s wallet syncs Merkle roots from on-chain event logs and generates a zero-knowledge withdrawal proof locally. Using Spartan-WHIR over the 31-bit KoalaBear field, proving completes in ~1 second (450 MB RAM) on consumer hardware, proving ownership of an unspent note without revealing which note it is.
- Post-Quantum Mixnet Routing: Instead of sending the ~1.3 MB proof to an RPC node, the wallet breaks it into ~280 fixed-size 8 KB onion packets. These packets are routed across a 4-node mixnet (Gateway → Mix → Exit) encrypted with X-Wing (ML-KEM-768 + X25519). Packets are mixed, shuffled in batches every 1.5 seconds, and padded with dummy cover traffic to defeat traffic analysis.
- Anonymous Rate-Limiting: To prevent DDoS attacks without requiring accounts, the gateway verifies a Binius64 zero-knowledge ticket over SHA-256 once per 10-minute epoch. A single 164-byte token on the first packet unlocks a 512-packet continuation budget.
- NAT-Friendly Replies: The first packet embeds a Single-Use Reply Block (SURB). The exit sends an acknowledgment back through a reply relay to a mailbox on the gateway. The client polls the gateway, so withdrawals work seamlessly behind firewalls and mobile cellular uplinks without opening inbound ports.
- Exit Aggregation & Recursion: An exit operator pulls two pending spends from its queue and runs leanVM recursion. It folds both client proofs into one compact terminal proof (~100 KB), amortizing the verification gas on-chain.
- EIP-8141 Settle & Alternative Mempool: The exit submits a frame transaction where the pool contract itself is the sender. Gas is sponsored by a post-quantum paymaster verified via a 5.6 KB stateless leanSPHINCS signature. Because verifying this signature requires 160,100 validation gas (exceeding standard public mempool limits), transactions route through a dedicated ERC-8421 alternative mempool that gossips transactions over libp2p.
- Mathematical Assurance: The state transition rules are modeled in Lean 4 with machine-checked proofs guaranteeing that no nullifier can ever be double-spent and the pool balance invariant is strictly preserved.
Topi was engineered across four distinct technological environments: Rust for network and cryptographic transport, Yul/Solidity for EVM smart contracts, Python/Rust for recursive proving pipelines, and Lean 4 for formal verification.
1. Cryptographic Proving Pipeline
- Client Prover: Implemented with ethereum/spartan-whir over the KoalaBear field (p = 2^31 - 2^24 + 1). It proves the Privacy Pools withdrawal relation against 82 public fields, producing a compact transaction digest in about 1 second.
- Exit Prover: Uses Client-Side-Proving/leanVM. The exit operator verifies two client proofs in the VM and executes a grouped root recursion into a single Keccak-based WHIR terminal proof. Proving takes about 2.5 minutes on a 32-vCPU AWS c7i.8xlarge spot instance.
- On-Chain Verifier: Generated using ethereum/sol-whir-p3 (LeanVmGroupedTerminal_KeccakPow28T6Lean, 59 KB bytecode). StatementBinding.sol uses unrolled Poseidon1 and Poseidon2 permutations to cryptographically bind the terminal proof's applicationRoot to both spends' 82 fields inside the EVM.
2. Network Transport and Rate-Limiting Stack (Rust)
- crates/sphinx: Implements KEM-Sphinx packet serialization using the hybrid X-Wing cipher (NIST ML-KEM-768 lattice KEM combined with X25519). Packets are strictly 8,192 bytes. Per-hop keys (MAC, payload, and header stream) are derived using BLAKE3.
- crates/mixnet: Implements four node roles (gateway, mix, exit, reply-relay). Mix nodes batch packets over 1,500 ms windows and shuffle them. Gateways emit Poisson-distributed cover traffic (mean 700 ms) and run an internal key-value reply store for SURBs.
- crates/ratelimit: Implements anonymous epoch tickets using binius64 (Binius ZK proofs over SHA-256).
3. EVM Smart Contracts and EIP-8141 Frames (Yul / Solidity)
- Yul Account Abstraction: PoolAccount.yul and PQPaymaster.yul enforce EIP-8141 frame validation policies.
- Hash-Based Signatures: We integrated the leanSPHINCS verifier from nconsigny/SPHINCS-. The paymaster reads a 5,684-byte witness from an ARBITRARY signature entry and validates it on-chain using Keccak-based SPHINCS+.
- ShieldedPool.sol: Manages dual depth-32 incremental Merkle trees, checks historical roots, updates nullifier registries, and processes dual-recipient balance payouts.
4. Alternative Mempool (ERC-8421)
- Built by extending the open-source ERC-8421 sidecar (forshtat/mempool-workshop-sidecar, a Skandha fork for frame transactions).
- We wrote a custom admission engine (mempool/src/policy.ts) that verifies nullifier freshness, Merkle root validity, fee recipient commitments, and leanSPHINCS signatures before gossiping over libp2p.
5. Formal Verification (Lean 4)
- Modeled in lean/PoolModel/. We proved theorems (only_settle_runs_as_pool, run_distinct, settle_preserves_inv, pq_pool_tx_has_no_ecdsa) directly against Lean's kernel axioms (propext, Quot.sound). We paired this with differential testing scripts comparing Lean's pool-policy engine against ethrex_simulateFrameTransaction over 500+ mutated transaction vectors.
Notable Hacks and Engineering Challenges
- Emitting Unreleased Opcodes via Yul verbatim: EIP-8141 introduces brand-new EVM opcodes (TXPARAM 0xB0, APPROVE 0xAA, FRAMEDATALOAD 0xB1, SIGDATACOPY 0xB5). Because solc has no native syntax for these opcodes, we hand-crafted the validation accounts in strict Yul assembly and injected raw opcode byte sequences using the verbatim builtin with pinned solc 0.8.28 compiler steps.
- Preventing Griefing via Storage-Based Nullifiers: Under EIP-8141, transactions can declare nonce keys. Initially, we considered setting the spend nullifier directly as an EIP-8250 nonce key. However, this introduced a severe denial-of-service vector: an attacker could copy a victim's nullifier from the mempool and submit it inside a transaction with a garbage proof. Frame validation would pass, consuming the nonce key, but the transaction would revert, permanently bricking the victim's note. We resolved this by keeping nullifiers strictly in contract storage inside ShieldedPool.settle. If a settlement fails, zero nullifiers are consumed.
- Patching Skandha's P2P Gossip Frame Cap: Settle transactions carrying the recursive terminal proof are about 104 KB in calldata. The upstream Skandha sidecar had a hardcoded 64,000-byte frame-data ceiling and dropped our transactions silently on the gossip network. We patched the sidecar to expand the gossip frame buffer to 128 KiB and increased the validation budget parameter maxVerifyGas from 100k to 200k.
- Bypassing the Devnet Code Deposit Gas Limit: On the public ERC-8421 devnet (chain 1337), state gas rules impose about 1,530 gas per byte of code, creating a ~37 KB contract deployment cap under the 60M block gas limit. Our terminal verifier is 59 KB and the pool logic is 50 KB. To deploy on chain 1337 without breaking up the verifier, we deployed the contracts on a local Anvil instance, extracted the contract state dumps, and injected them directly into the devnet's genesis allocation (deployments/1337/genesis/).
- Self-Contained Ratatui Terminal UI: We built crates/console (topi), which embeds the prover bash scripts, the Bun sidecar patches, and contract bytecodes directly into the compiled Rust binary. On non-repo machines, it automatically unpacks the environment into ~/.topi, controls background AWS spot instances, and renders a live ASCII world map tracking packet propagation across Mumbai, Frankfurt, N. Virginia, and Singapore.