Part IV · AI-Native Verification & Transfer Ch 15 · 35 min · ProveIt/Ch15.lean

Verified Wire Formats (TLV Framing)

Eliminating parser differentials and TCP stream-smuggling bugs with `decode (encode pkt ++ rest) = some (pkt, rest)`.

5-Line Security Bug · Single-Buffer Round-Trip vs. TCP Stream Concatenation
def encodeBad (msg : List UInt8) : List UInt8 := msg
def decodeBad (wire : List UInt8) : Option (List UInt8) := some wire
-- `decodeBad (encodeBad msg) = some msg` is TRUE (`rfl`)!
-- Yet over a socket, `encodeBad [1, 2] ++ encodeBad [3, 4]` decodes as ONE `[1, 2, 3, 4]` packet!
Socratic Gate · Commit to a Prediction Unanswered · Locks on commit

What stronger round-trip theorem forces a binary serializer (`encode`) and parser (`decode`) to self-delimit packet boundaries cleanly on an arbitrary byte stream?

Why Parser Differentials Cause Critical CVEs

HTTP request smuggling, X.509 certificate confusion, and consensus-splitting blockchain bugs happen when two parsers disagree on where Frame 1 ends and Frame 2 begins. Proving Prefix-Unambiguous Stream Round-Trip (decode (encode p ++ rest) = some (p, rest)) plus deterministic encoding guarantees every compliant node splits a byte stream identically.

⊢ ProveIt/Ch15.lean · Stream-Safe TLV Packet Framing
Step 1 / 1
Lean Infoview Open Goal
Hands-On Exercise (ProveIt/Ch15.lean):

In `ProveIt/Ch15.lean`, verify a multi-message TLV stream decoder loop (`decodeAll`) and prove truncation rejection on short buffers.

Finished the Socratic gate, Infoview trace, and playground run?
Record completion in local browser storage to track your 20-unit progress.