# 04 — Signed Public Relay Registry & Kademlia DHT Discovery `fatext v4.0` solves decentralized cold-start and Sybil/Eclipse routing attacks by combining a **GitOps-curated, cold-key-signed static Public Relay Registry** (`/.well-known/relays.json`) with a PoW-admitted 256-bit [Kademlia DHT](https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf). ## 1. Operator Relay Manifest (`registry/relays/.json`) Any operator running `fatext daemon --seed` generates a self-signed manifest via `fatext relay manifest`: - `v`: `1` - `relay_id`: self-certifying `ftx_<20-crockford-b32>` derived from `microlog[0]` (`pow_bits >= 22`). - `tier`: `"seed"` (official backbone) or `"community"` (verified independent operator). - `operator`: `{"contact": "https://...", "name": "..."}`. - `region`: geographic routing tag (e.g., `"us-east"`, `"eu-central"`, `"ap-northeast"`). - `endpoints`: `{"udp": "host:port", "wss": "wss://.../v4/relay"}` (with optional `"http": "https://..."`). - `capabilities`: subset of `["bootstrap", "dropbox", "ws_relay", "topic_gossip"]`. - `limits`: `{"max_dropbox_ttl_sec": 604800, "max_frame_bytes": 65536, "ring_quota_per_window": 30, "ring_window_sec": 600}`. - `microlog`: verified genesis/rotation chain establishing current `pk_id` (`32 B`) and `ek_kem` (`1216 B`). - `issued_at`, `expires_at`: Unix seconds (`expires_at > issued_at`). - `operator_sig`: Base64 `ristretto255` Schnorr signature (`64 B`) by current `pk_id` over `"fatext-v4-relay-manifest\n" || JCS(manifest_without_operator_sig)`. ## 2. Static Aggregated Registry (`/.well-known/relays.json` + `.sig`) `scripts/build_site.py` validates every manifest via `verify_relay_registry.py`, excludes any ID listed in `registry/revoked.json`, emits deterministic JCS-ordered JSON with monotonically increasing `registry_epoch`, and signs domain-separated file payloads using the official offline [RFC 8032 `Ed25519`](https://www.rfc-editor.org/info/rfc8032/) release key (`relays.json.sig` signs `"fatext-v4-relays-registry\n" || exact_file_bytes`, `relays-chain.json.sig` signs `"fatext-v4-relays-chain\n" || exact_file_bytes`, and `SHA256SUMS.sig` signs `"fatext-v4-release-sums\n" || exact_file_bytes`, each encoded as Base64 64-byte signatures). **Bootstrap vs. Production Keys**: Repository builds default to deterministic dev/bootstrap seeds for reproducible CI and cross-repo verification. Production publication MUST run with `--production`, an air-gapped cold release key (`FATEXT_OFFICIAL_KEY_SEED_HEX` / `--seed-file`), and independently collected witness cosignatures (`--witness-cosigs-file`). ### Three-Step Client Verification Contract 1. **Cold-Key Signature Check**: Verify `relays.json.sig` over `"fatext-v4-relays-registry\n" || relays_json_bytes` against the client's pinned `Ed25519` public key (`official_release_key_fp`). 2. **Static Transparency Hash-Chain, `C2SP` Witness Quorum & Split-View Equivocation Enforcement**: Each epoch commits to `prev_registry_hash` (`00..00` at `epoch=1`), `state_hash = SHA3-256("fatext-v4-registry-state\n" || sorted_active_bindings || "\n" || sorted_revoked_ids)`, `registry_hash = SHA3-256("fatext-v4-registry-link\n" || epoch || "\n" || prev_registry_hash || "\n" || state_hash || "\n" || op_summary || "\n" || generated_at)`, cold-key `entry_sig` (`"fatext-v4-registry-entry\n" || registry_hash`), and a `2-of-3` threshold of independent [C2SP `tlog-witness`](https://c2sp.org/tlog-witness) / [`tlog-cosignature`](https://c2sp.org/tlog-cosignature)-inspired `Ed25519` cosignatures (`witness_cosigs` over `"fatext-v4-witness-cosig\n" || epoch || "\n" || registry_hash`, tagged by `witness_id`), published alongside `/.well-known/relays-chain.json` (`.sig`). Clients reject any epoch lacking `>= 2` valid pinned witness cosignatures (`ERR_WITNESS_QUORUM`, `EXIT_CRYPTO = 8`) even on network-eclipsed first boot, verify unbroken hash continuity from their pinned `(epoch, registry_hash)`, and immediately freeze on any conflicting cold-key-signed `registry_hash` at the same `epoch` (`EXIT_EQUIVOCATION = 9`). 3. **Live Handshake Key Binding (`GET /v4/status` / `WSS /v4/relay`)**: Upon connecting, the client sends a random 32-byte `challenge` (`?challenge=`); the relay must sign `"fatext-v4-relay-hello\n" || relay_id || "\n" || challenge || "\n" || ts` using the `pk_id` from its registered `microlog` (while also reflecting the caller's NAT-mapped `observed_addr`). DNS hijacking or rogue TLS proxies fail immediately (`EXIT_CRYPTO = 8`). ## 3. PoW-Gated & Subnet-Diverse 256-Bit Kademlia DHT - **Node Keyspace**: `node_key = SHA3-256("fatext-v4-dht-node\n" || agent_id)` (`256 bits`), distance $d(A, B) = A \oplus B$. - **Pinned Backbone, `/24` & `/48` Eclipse Guard + Disjoint Lookups**: Following [S/Kademlia](https://www.semanticscholar.org/paper/S-Kademlia%3A-A-practicable-approach-towards-secure-Baumgart-Mies/d22c179ffeea89d0a42c47e6c1560a7a250b25b0) and [IPFS Kademlia Sybil & Eclipse Defenses (2025)](https://arxiv.org/abs/2505.01139), clients pin active registered public relays, require `>= 22-bit` Genesis PoW for unpinned `--seed` peers, cap unpinned candidate seeds to at most `1` node per IPv4 `/24` or IPv6 `/48` prefix (`fatext dht filter-eclipse`), and execute 3 node-disjoint iterative lookups ($\alpha = 3, k = 20$). - **Signed DHT Records**: - `ReachDescriptor` (`SHA3-256("reach\n" || agent_id)`, max `8 KB`, TTL `1800 s`): carries `microlog`, latest `ek_kem`, direct UDP endpoints, and `1..3` home Drop-Box relay IDs/URLs. - `RevokeTombstone` (`SHA3-256("tomb\n" || agent_id)`, max `2 KB`, TTL `365 d`): carries terminal `revoke` event or equivocation fraud proof. - `TopicProvider` (`SHA3-256("topic\n" || topic)`, max `4 KB`, TTL `3600 s`): lists relays caching content-addressed topic messages. ## 4. `v4.1` Homeserver Discovery & Relay Hardening Rules Homeservers launched with `fatext daemon --homeserver` layer the following operational hardening on top of public relay and DHT endpoints: 1. **Fail-Closed PoW Floor (`min_pow_bits >= 22`)**: `/v4/ring-pool/admit`, DHT admission, and S2S identity verification require `pow_bits >= min_pow_bits` (`22` default; lower values allowed only explicitly in isolated test harnesses). 2. **Authenticated & Rate-Limited OPK Claims (`POST /v4/prekeys/{agent_id}/claim`)**: Callers must authenticate via signed HTTP headers (`fatext-v4-http\n` + `X-Microlog-B64`) or `Scoped bLSAG` quota proof (`HTTP 401` if unauthenticated) and are throttled by configurable `--opk-claim-limit` quotas (`HTTP 429 ERR_RATE_LIMITED`), preventing anonymous prekey depletion DoS. 3. **Outbound SSRF Isolation (`/v4/onion` & `/v4/federation/*`)**: Homeservers forbid credentials in URLs (`user:pass@`), disallow obfuscated IP literals, resolve hostnames via system DNS before dialing, and block loopback (`127.0.0.0/8`, `::1`), RFC1918, link-local (`169.254.0.0/16`, `fe80::/10`), and IPv6 ULA (`fc00::/7`) targets (`HTTP 403 ERR_SSRF_BLOCKED`) unless explicitly started with `--allow-local-fed` for local integration tests. 4. **Homeserver Discovery (`/.well-known/fatext-homeserver.json` & `/v4/kt/head`)**: Homeservers publish `mode` (`official` | `selfhosted`), `public_url`, `min_pow_bits`, capability flags, non-wallet commercial posture, and signed Key Transparency chain heads.