Building VoidDex: A Technical Deep Dive into Privacy-Preserving DEX Aggregation
Every swap you make on a decentralized exchange is public. VoidDex is my attempt at building a DEX aggregator that maintains the benefits of decentralized trading while adding a cryptographic privacy layer using zkSNARK proofs.
Every swap you make on a decentralized exchange is public. The token, the amount, the timing, your wallet address - all visible to anyone watching the blockchain. This transparency is fundamental to how blockchains work, but it comes with costs: MEV bots front-run your trades, analysts track your portfolio, and your entire financial history is one click away.
I wanted to solve this. VoidDex is my attempt at building a DEX aggregator that maintains the benefits of decentralized trading while adding a cryptographic privacy layer.
## The Core Problem
Every address you interact with, every token you hold, every trade you make - it's all permanently recorded on the blockchain. Your entire financial history is one click away on Etherscan.
This transparency is fundamental to how blockchains work, but it creates serious privacy concerns. Employers can see your salary if you're paid in crypto. Merchants can see your net worth when you make a purchase. Analysts can track your entire portfolio and trading patterns.
For individuals and institutions alike, this level of exposure is often unacceptable. Traditional finance doesn't broadcast your bank transactions to the world - why should DeFi?
As a secondary benefit, private transactions also protect against MEV extraction. Bots can't front-run what they can't see.
## The Technical Solution
VoidDex combines two technologies: DEX aggregation for optimal swap rates and zkSNARK proofs for transaction privacy.
The architecture splits responsibilities between client and server:
**Client-side (your browser):**
- Private key generation and encrypted storage
- Railgun SDK running via WebAssembly
- Zero-knowledge proof generation
- Balance decryption and merkle tree scanning
**Server-side (VoidDex API):**
- Price quotes from multiple DEXes
- Routing optimization across liquidity pools
- Token metadata and network status
The critical point: all cryptographic operations happen locally. The server never sees your keys, your balances, or your transaction details.
## How the Privacy Flow Works
The system uses a shield/unshield model:
**Step 1 - Shield:** Your public ERC-20 tokens enter Railgun's privacy pool. They're now part of an anonymity set with thousands of other shielded tokens.
**Step 2 - Private Balance:** You now have a private balance that only you can see. The blockchain shows tokens entered the privacy pool, but not whose private balance they belong to.
**Step 3 - Private Swap:** When you swap, the Railgun SDK generates a zkSNARK proof. This proof demonstrates you have sufficient balance without revealing which specific UTXOs are yours. The proof gets submitted on-chain.
**Step 4 - Execution:** Railgun's contracts verify the proof and call the VoidDex Router. The Router executes the actual swap across whichever DEX offers the best rate - Uniswap V3, SushiSwap, PancakeSwap, QuickSwap, or Camelot.
**Step 5 - Return:** Output tokens automatically shield back into your private balance.
From the blockchain's perspective, tokens moved through Railgun's contracts and a swap happened. The connection between your public address and the swap is cryptographically broken.
## The Zero-Knowledge Component
zkSNARK proofs are the core of the privacy model. When you execute a private swap, you're proving:
1. You own tokens in the privacy pool (without revealing which ones)
2. The amount is sufficient for the swap (without revealing the exact amount)
3. The transaction is authorized by you (without revealing your identity)
These proofs are generated entirely in your browser using WASM-compiled circuits. Generation takes approximately 15 seconds on modern hardware. The proof itself is small - a few hundred bytes - and verification on-chain is gas-efficient.
## Security Model
The trust assumptions are minimal:
| Component | Trust Requirement |
|-----------|-------------------|
| Private Keys | None - generated locally, never transmitted |
| ZK Proofs | None - generated locally, verified on-chain |
| Balance Data | None - encrypted, only you can decrypt |
| VoidDex Server | Limited - only provides quotes, no access to private data |
| Railgun Contracts | Smart contract security - audited, battle-tested |
If VoidDex's server was compromised, an attacker could serve bad quotes. They could not access your funds or break transaction privacy - that's enforced cryptographically.
## Why Build on Railgun?
I chose Railgun for several reasons:
1. **Proven infrastructure** - Significant volume processed without security incidents
2. **Any ERC-20 support** - Not limited to specific tokens
3. **SDK availability** - Clean integration for browser-based applications
4. **Non-custodial design** - No trusted parties, no admin keys
Building custom zkSNARK circuits would have taken months. Railgun's SDK let me focus on the aggregation layer while leveraging their proven privacy infrastructure.
## Current Status and Roadmap
VoidDex is live on Sepolia testnet. The core functionality works:
- Shielding and unshielding tokens
- Private swaps across aggregated DEXes
- Client-side proof generation
Mainnet deployment across Ethereum, Polygon, Arbitrum, and BSC is planned once testing is complete.
## Technical Challenges
Building this wasn't straightforward. Some issues I encountered:
**Proof generation performance:** Initial WASM compilation took 30+ seconds. Optimizing the SDK initialization and caching prover keys brought this down to ~15 seconds.
**Merkle tree sync:** Private balances require scanning the blockchain for your encrypted notes. This is computationally intensive. I implemented incremental sync to avoid re-scanning the entire tree.
**Multi-DEX routing with privacy:** Finding optimal routes while maintaining privacy constraints required custom logic. The router needs to handle partial fills and slippage across privacy pool interactions.
## Conclusion
Privacy in DeFi isn't about hiding illicit activity. It's about bringing the same financial privacy expectations we have in traditional finance to decentralized systems. Your bank doesn't broadcast your transactions to the world - your DEX shouldn't either.
VoidDex is my contribution to this space. A practical tool that combines the efficiency of DEX aggregation with the privacy of zero-knowledge proofs.