Blocks round-trip
ProvedBitcoinSer.block_roundtripFor every well-formed block , witness mode and remainder :
Deserialization is a left inverse of serialization on well-formed blocks in both formats: a block read back from its own bytes is the block (with witnesses, in the witness-aware reader; without, in the legacy one). This is the "interpretation of serialized data" that every hash commitment — merkle root, block hash, txid — refers to.
Formalization Note. Well-formedness is the field-range predicate of the definition (32-bit fields, 32-byte hashes, 64-bit amounts, vector lengths at most , every transaction with an input or a witness); the last condition reflects the dummy-vin reinterpretation of the source.
import Definitions.Def_BitcoinSer
theorem BitcoinSer.block_roundtrip (aw : Bool) (b : Block) (rest : Bytes) (hw : b.wf) :
BitcoinSer.readBlock aw (BitcoinSer.serBlock aw b ++ rest) =
some (⟨b.header, b.vtx.map (fun tx => if aw then tx else tx.stripWitness)⟩, 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.block_roundtrip
Binders and hypothesis. A Boolean (either value), a block record (a header and a list of transactions), a byte string (arbitrary), and the hypothesis , which unfolds to:
- is well-formed: , , , ;
- (with , equality allowed);
- for every in : (version and lock time ; input and output counts ; each input has a 32-byte outpoint hash, index and sequence , script length , at most witness items each of length ; each output has value in and script length ) and ( or ). The second disjunct implies the first (a non-empty witness lives on some input), so this says every transaction in the block has at least one input — and this is demanded for both values of .
Conclusion.
Parsing in mode the mode- serialization of , followed by arbitrary bytes, succeeds; the parsed header equals 's header exactly; the parsed transaction list has the same length and order as , with the -th parsed transaction equal to the -th original when is true and to its witness-stripped copy (all witness lists emptied, everything else unchanged) when is false; and the remainder is exactly . When is true the right side is up to the trivial identity map.
Unfolding. . parses an 80-byte header (signed version, two 32-byte hashes, three unsigned 4-byte fields), then a range-checked CompactSize count, then exactly that many transactions with , each consuming its own bytes and handing the remainder to the next. Each behaves as described for tx_roundtrip: in mode false it ignores the flags logic and returns inputs with empty witnesses; in mode true it reads the marker and the witness stacks when the transaction has a witness, and takes the direct path when the input list is non-empty. The per-transaction "at least one input" condition plays the role of in tx_roundtrip for each transaction when is true (it is assumed but unused when is false). The header bounds make the header parse exact, and makes the range-checked count readable. The degenerate block with is included: the count byte is read and zero transactions follow.
What is not said. Nothing about blocks violating , in particular blocks containing a transaction with no inputs — even in mode false, where such a block would in fact parse, the theorem makes no claim. No converse: nothing says a parsed block is well-formed or arose from . Nothing about mixed modes (serialize with one , parse with the other). Nothing about , , , merkle roots (the header's merkle-root field is parsed as 32 opaque bytes; no relation to is assumed or concluded), or lengths. It is the one-directional parse-after-serialize statement for blocks, per mode, under .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.