Appearance
Relay Server
Rust application serving as Association Set Provider (ASP) for Privacy Pools.
Architecture
relay_server_rs/
├── src/
│ ├── main.rs
│ ├── server/routes.rs # API endpoints
│ ├── merkle/ # Tree implementation
│ ├── indexer/ # Event sync
│ └── starknet/relayer.rs # Tx submission
└── Cargo.tomlResponsibilities
| Function | Description |
|---|---|
| Event Indexing | Sync deposits from Starknet |
| Merkle Trees | Maintain deposit + association trees |
| Merkle Paths | Provide proofs for frontend |
| Tx Relay | Submit transactions (gas abstraction) |
API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/api/merkle/path/:index | GET | Get Merkle proof |
/api/merkle/root | GET | Current root |
/api/commitment/:hash | GET | Check if indexed |
/api/swap | POST | Submit swap tx |
Privacy Pools
Dual Merkle tree for compliance:
rust
struct DualMerkleTree {
deposit_tree: MerkleTree, // All deposits
association_tree: MerkleTree, // Curated "clean" deposits
}- Deposit Tree: Every commitment, no filtering
- Association Tree: Curated by ASP policy, excludes flagged deposits
Users can prove against either tree.
Event Indexing
Syncs LeafInsertedBN254 events:
rust
async fn sync_deposits(&mut self) -> Result<()> {
let events = self.starknet
.get_events(self.contract, "LeafInsertedBN254", self.last_block)
.await?;
for event in events {
let leaf = parse_leaf(&event);
self.deposit_tree.insert(leaf);
if self.is_clean(&leaf) {
self.association_tree.insert(leaf);
}
}
Ok(())
}Transaction Relay
Gas abstraction—relay pays gas, user pays fee from shielded amount:
rust
async fn relay_swap(&self, request: SwapRequest) -> Result<TxHash> {
let tx = self.build_swap_tx(&request);
let hash = self.starknet.send_transaction(tx).await?;
Ok(hash)
}Trust Model
| Can Do | Cannot Do |
|---|---|
| Censor transactions | Steal funds |
| Exclude from association set | Forge proofs |
| See public data | See private inputs |
Semi-trusted: affects availability, not security.
Stack
| Component | Technology |
|---|---|
| Runtime | Tokio |
| HTTP | Axum |
| Database | SQLite |
| Starknet | starknet-rs |
| Hashing | light-poseidon |