Block headers round-trip
ProvedBitcoinSer.header_roundtripFor every well-formed header and remainder : , including the signed nVersion.
import Definitions.Def_BitcoinSer
theorem BitcoinSer.header_roundtrip (h : Header) (rest : Bytes) (hw : h.wf) :
BitcoinSer.readHeader (BitcoinSer.serHeader h ++ rest) = some (h, rest) := by sorryRead-back
What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: BitcoinSer.header_roundtrip
Binders and hypothesis. A header record , a byte string (arbitrary), and , which is the conjunction
Conclusion. Parsing the serialized header followed by succeeds and returns exactly with remainder :
This is an equality of optional pairs; it asserts success, equality of every field of the parsed record with the corresponding field of (record equality is field-wise), and that the unconsumed suffix is .
Unfolding. The serialization is , where is the 4 little-endian bytes of taken in (two's complement for negative ) and is 4 little-endian bytes of a natural number mod . The parser performs, in order: (4 bytes little-endian , returned as if , else ); twice (each takes exactly 32 bytes, failing if fewer remain); then three times (unsigned). Each step fails on short input and the whole parse then fails.
The hypotheses are used as follows: the version range guarantees that the signed decode of the two's-complement bytes gives back exactly (for outside the wrap-around would produce a different integer); the two length equalities guarantee that the 32 bytes taken by each are exactly the field (if were shorter or longer, the parser would still take 32 bytes but they would straddle fields); and the three bounds guarantee that the truncating loses nothing so recovers the value. The hypothesis is therefore exactly matched to what the round trip needs — every conjunct is used.
What is not said. Nothing for headers violating : e.g. with a 31-byte the parse may still succeed but return a different record, and the theorem is silent. The converse direction ("every successful comes from of a well-formed header", or that parsed headers are well-formed) is not stated. Nothing about , about 80-byte length (that is serHeader_length), about blocks, or about failure on short input. It is the one-directional parse-after-serialize statement, under full , with an arbitrary trailing suffix.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.