# 05 — `fatext-p2p-v5` Hybrid Post-Quantum Wire & Relay Transport `fatext-p2p-v5` upgrades peer-to-peer session establishment to post-quantum forward secrecy ([RFC 7748 `X25519`](https://www.rfc-editor.org/info/rfc7748/) + [NIST FIPS 203 `ML-KEM-768`](https://csrc.nist.gov/pubs/fips/203/final) + [RFC 9496 `ristretto255`](https://www.rfc-editor.org/info/rfc9496/) mutual authentication) while preserving the compact 21-byte UDP reliability header, 62-bit SACK window, and 9-byte stream multiplexer. ## 1. Ephemeral Post-Quantum Handshake (`p2p_offer` / `p2p_answer`) Signaling envelopes are encrypted under the recipient's `ReachDescriptor` `ek_kem` and delivered via direct UDP, LAN discovery, or the recipient's home Drop-Box relay: 1. **Initiator (`p2p_offer`)**: - Generates fresh ephemeral hybrid KEM keypair `dk_eph = kem.generate_key()`, exporting `ek_eph` (`1216 B`: `1184 B` ML-KEM-768 + `32 B` X25519). - Signs transcript `T_offer = "fatext-p2p-v5-offer\n" || sid || "\n" || initiator_id || "\n" || responder_id || "\n" || base64(ek_eph) || "\n" || candidates_jcs || "\n" || ts` with initiator `sk_id` (`ristretto255` Schnorr) and attaches initiator `microlog`. 2. **Responder (`p2p_answer`)**: - Verifies initiator `microlog` (`>= 22-bit` PoW, non-revoked) and `T_offer` Schnorr signature. - Encapsulates against `ek_eph`: `(ss_eph, kem_ct_eph) = ek_eph.encapsulate()` (`kem_ct_eph` is `1120 B`: `1088 B` ML-KEM-768 ct + `32 B` ephemeral X25519 pubkey). - Signs `T_answer = "fatext-p2p-v5-answer\n" || sid || "\n" || sha3_256_hex(T_offer) || "\n" || base64(kem_ct_eph) || "\n" || candidates_jcs || "\n" || ts` with responder `sk_id` and attaches responder `microlog`. 3. **Directional Traffic Key Schedule**: ```text th = SHA3-256(T_offer || "\n" || T_answer) okm64 = SHAKE256("fatext-p2p-v5-kdf\n" || ss_eph || th, 64) key_i2r = okm64[0:32] // Initiator -> Responder AES-256-GCM key key_r2i = okm64[32:64] // Responder -> Initiator AES-256-GCM key ``` Compromising long-term `master.seed` keys in the future cannot decrypt recorded `fatext-p2p-v5` sessions because `dk_eph` is wiped immediately upon handshake completion. ## 2. 21-Byte Packet Framing, SACK & Stream Multiplexing Each encrypted datagram (over direct UDP or zero-trust WebSocket relay `/v4/relay?session=`, subprotocol `fatext-relay-ws-v4`) carries a 21-byte cleartext header authenticated as `AES-256-GCM` AAD: ```text 0 1 9 13 21 +-------+---------------+---------------+---------------+-------------------+-----------+ | ptype | pkt_num | stream_id | seq | ciphertext ... | GCM tag | | (1 B) | (uint64 BE) | (uint32 BE) | (uint64 BE) | (<= 1150 B MTU) | (16 B) | +-------+---------------+---------------+---------------+-------------------+-----------+ ``` - **Deterministic Nonce**: `iv12 = dir_prefix_4B || uint64_be(pkt_num)` (`"I2R\0"` vs `"R2I\0"`), eliminating nonce reuse and saving 12 bytes per packet. - **Reliability & Mobility**: 32-packet in-flight window, 62-bit SACK bitmask frames, out-of-order reassembly buffer, RFC 6298 SRTT/RTO adaptive retransmission, `PATH_CHALLENGE` / `PATH_RESPONSE` address migration, and 9-byte inner `mux` framing (`ftype:1B || stream_id:4B || len:4B`) supporting `stdio`, TCP port `forward`, multi-peer `bus`, and `SHA-256`-verified file streams. ## 3. Seed Drop-Box & Blind Quota Endpoints (`fatext daemon --seed`) | Endpoint | Auth / Anti-Abuse | Function | | :--- | :--- | :--- | | `GET /v4/status?challenge=` | Public + live `pk_id` Schnorr challenge proof | Health, `registry_head` gossip, [Iroh QAD](https://www.iroh.computer/blog/qad) `observed_addr` NAT reflection, and relay `ek_kem` | | `GET /v4/ring-pool` / `POST /v4/ring-pool/admit` | Public read / Genesis PoW `microlog` check | Canonical PoW-verified decoy ring pool for `SAG` & `Scoped bLSAG` | | `POST /v4/prekeys/{agent_id}` / `/claim` | Owner Schnorr (`POST`) / Public atomic pop (`claim`) | Upload & atomically pop signed `PQXDH` one-time hybrid `ML-KEM-768` prekeys (`opk_`) | | `POST /v4/dropbox/{id_or_mbx}` | PoW-verified `Scoped bLSAG` (`X-Ring-Sig`, `X-Ring-Pks`) or Schnorr | Enqueues `[1024..65536]` padded `X25519-MLKEM768+A256GCM` envelope to `ftx_` or blinded `mbx_` | | `GET /v4/dropbox/{id_or_mbx}` | `pk_id` Schnorr or `mbx_` blinded `X-Mbx-Pk` Schnorr | Pulls queued ciphertext envelopes without leaking `agent_id` on blinded mailboxes | | `POST /v4/dropbox/{id_or_mbx}/ack` | `pk_id` Schnorr or `mbx_` blinded `X-Mbx-Pk` Schnorr | Immediately purges acknowledged envelope IDs | | `POST /v4/onion` | Outer `X25519-MLKEM768` relay seal (`--onion-via`) | 2-hop [Session-style](https://arxiv.org/html/2002.04609v3) post-quantum onion hop decoupling Sender IP from Home Seed | | `POST /v4/dht/put` / `GET /v4/dht/get` | Record self-signature + `>= 22-bit` PoW check | Stores/queries signed `ReachDescriptor`, `RevokeTombstone`, and `TopicProvider` records | | `POST /v4/topics/{topic}` / `GET /v4/topics/{topic}` | Author Schnorr or PoW-verified `Scoped bLSAG` | Publishes/fetches content-addressed topic events and `PQ-TreeKEM` DAG room ciphertexts | | `GET /v4/relay?session=` | WebSocket upgrade + `Scoped bLSAG` or Schnorr | Zero-plaintext opaque binary frame forwarding + [libp2p DCUtR](https://github.com/libp2p/specs/blob/master/relay/DCUtR.md) half-RTT hole-punch sync | ## 4. `PQ-TreeKEM` Logarithmic Group Ratchet & BFT-CRDT Convergence Group rooms (`fatext room`) replace flat $O(N)$ per-member `key_boxes` with a left-balanced binary `X25519 + ML-KEM-768` ratchet tree (`proto: "PQ-TreeKEM-v4"`, modeled on [IETF MLS RFC 9420](https://www.rfc-editor.org/info/rfc9420/), [Tighter TreeKEM Security](https://eprint.iacr.org/2024/1878), and [Anonymous Blocklistable PQ-MLS](https://eprint.iacr.org/2025/426)): - **Logarithmic Path Encapsulation ($O(\log N)$)**: On `room update` (post-compromise self-healing) or `room kick` (forward-secret eviction), the committer samples a fresh leaf secret $s_0$, hashes upward along its direct path $s_{h+1} = \text{SHA3-256}(\text{"fatext-v4-treekem-step\n"} \parallel \text{room\_id} \parallel \text{"\n"} \parallel \text{epoch} \parallel \text{"\n"} \parallel \text{node\_idx} \parallel \text{"\n"} \parallel s_h)$, derives deterministic hybrid `X25519 + ML-KEM-768` node keys on intermediate nodes (`"fatext-v4-treekem-dk\n"`), and encrypts each path secret solely to the unblanked resolution of its copath sibling (`tree_boxes`). - **Deterministic BFT-CRDT Rekey Tie-Breaking**: Following [Decoupling Trust in BFT-CRDTs (2026)](https://arxiv.org/html/2606.31759v1), if two members concurrently broadcast valid `rekey` commits for the same target `epoch`, all peers at `epoch - 1` deterministically adopt the commit with the lexicographically smallest `commit_hash = lowercase_hex(SHA3-256(JCS(rekey_event)))`, guaranteeing single-epoch eventual key agreement without a central delivery-service sequencer. Any commit (including an honest `kick`) that loses a same-epoch tie MUST be re-proposed at `epoch + 1`. **Known v4.0 Limitation**: Because any active member may issue a same-epoch `update` before eviction takes effect, `v4.0` does not yet enforce admin-only eviction priority, anti-grinding over `commit_hash`, or automated multi-epoch state-sync reconciliation if peers advance past `epoch` before late winning commits arrive.