# Mutual Witness Protocol (MWP) **Version:** 1.0.0 **Status:** Prototype **Created:** February 2026 --- ## Overview The Mutual Witness Protocol (MWP) is a novel NAT traversal and peer discovery protocol that requires **zero external infrastructure** beyond a DHT. ``` ┌─────────────────────────────────────────────────────────────┐ │ MUTUAL WITNESS PROTOCOL │ │ │ │ Two parties who know each other's public keys can │ │ establish a direct P2P connection with: │ │ │ │ - No STUN servers │ │ - No relay servers │ │ - No signaling servers │ │ - No beacon chain │ │ - Only DHT (which P2P networks already have) │ │ │ │ Each party contributes randomness and timing. │ │ Neither can cheat. Neither needs to trust third parties. │ └─────────────────────────────────────────────────────────────┘ ``` ## Key Innovation Traditional NAT traversal requires: - **STUN**: External server to discover your public IP - **Signaling**: Server to exchange connection offers - **Relay**: Fallback when direct connection fails MWP eliminates all three by having peers **witness each other**: 1. Both peers publish to a deterministic DHT meeting point 2. Each contributes randomness (nonce) and timing (timestamp) 3. Shared parameters computed from both contributions 4. Simultaneous connection attempt at computed rendezvous time ### Bundled STUN (IP Reflection) MWP includes a novel **Bundled STUN** mechanism: every DHT response includes the requester's observed source address. This eliminates STUN servers entirely - peers discover their public IP from normal DHT traffic: ``` Alice ── DHT_REQUEST ──> DHT Node (src: 192.0.2.1:54321) Alice <── DHT_RESPONSE ── DHT Node (observed_addr: 192.0.2.1:54321) Now Alice knows her public IP without any STUN server! ``` ## Quick Start ```zig const mwp = @import("mwp"); // Initialize with your DHT and keypair var witness = mwp.MutualWitness.init(allocator, dht, keypair); // Connect to peer by their public key const connection = try witness.connect(target_pubkey, .{ .timeout_ms = 5000, }); // Use connection... defer connection.close(); ``` ## Protocol Flow ``` Alice DHT Bob │ │ │ │ 1. meeting_key = hash(sort(A_pk, B_pk)) │ │ │ │ │──────── PUT(key, pub_A) ────>│<──── PUT(key, pub_B) ───────│ │ │ │ │<─────── GET(key) ───────────>│<──────── GET(key) ──────────│ │ returns [pub_A, pub_B] │ │ │ │ │ 2. shared_randomness = hash(sort(nonce_A, nonce_B)) │ │ 3. rendezvous_time = computed from timestamps │ │ │ │ │ 4. Wait until rendezvous_time │ │ │ │ │<──────────── simultaneous connection attempt ──────────────>│ │ │ │ ▼ ▼ ▼ CONNECTED (direct P2P) ``` ## Comparison | Metric | DCUtR | STUN+Signaling | **MWP** | |--------|-------|----------------|---------| | External servers | 1+ relays | 2 servers | **0** | | IP discovery | STUN servers | STUN servers | **Bundled in DHT** | | Latency (typical) | ~2s | ~1-2s | **~1-2s** | | Centralization | Relay operators | Server operators | **None** | | Infrastructure | Must run relays | Must run servers | **DHT only** | ## Documentation - [SPEC.md](./SPEC.md) - Complete protocol specification - [COMPARISON.md](./COMPARISON.md) - Detailed comparison with existing solutions - [src/](./src/) - Implementation ## Use Cases 1. **Truly decentralized P2P** - No external dependencies 2. **Censorship-resistant** - No servers to block 3. **Privacy-focused** - Only DHT sees metadata 4. **Resource-constrained** - Minimal infrastructure 5. **Offline-first** - Works when peers are online, no always-on servers needed ## Limitations - Requires both peers to know each other's public keys - Symmetric NAT success rate may be lower than relay-based approaches - DHT latency affects connection setup time - Novel/unproven (needs real-world testing) ## License Same as parent zig-p2p project.