Fixed-width integers round-trip
ProvedBitcoinSer.readLE_leBytesFor all , and remainder : .
import Definitions.Def_BitcoinSer
theorem BitcoinSer.readLE_leBytes (k n : Nat) (rest : Bytes) (h : n < 2 ^ (8 * k)) :
BitcoinSer.readLE k (BitcoinSer.leBytes k n ++ rest) = some (n, 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.readLE_leBytes
Binders and hypothesis. Two natural numbers and , a byte string (a finite list of 8-bit values, possibly empty), and one hypothesis
No other restriction: may be (then the hypothesis forces ), and is arbitrary.
Conclusion. Decoding little-endian bytes from the concatenation of the -byte encoding of with succeeds and returns together with as the unconsumed remainder:
Unfolding. Here is the list of bytes, least significant first, with byte equal to . The decoder returns "no result" when , and otherwise returns the pair , where sums over the bytes of its argument (with ). Since the encoded prefix has length exactly (whatever is), the input has length and the "short read" case cannot occur; the statement then amounts to two facts:
- whenever (the little-endian value of the -byte truncated encoding recovers exactly, because no bits were lost);
- dropping the first bytes of leaves exactly .
Degenerate instance: gives , , and since of the empty prefix is ; the statement holds trivially there. The equality is an equality of optional pairs, so it asserts both success (not "no result") and the exact values of both components.
What is not said. Nothing is claimed when : in that case truncates and the decoder would return , which the statement does not mention. Nothing is claimed about decoding arbitrary byte strings (the converse direction "if then " is not stated, although for it would be true). The statement does not cover the signed readers paired with , nor the big-endian . It does not say the decoder fails on short input. It is a single-direction round-trip for the unsigned little-endian codec under the exact bound .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.