A read CompactSize is bounded
ProvedBitcoinSer.compactSize_rangeEvery value a successful returns is below , and below or equal to when the range check is on.
import Definitions.Def_BitcoinSer
theorem BitcoinSer.compactSize_range (rc : Bool) (b : Bytes) (n : Nat) (rest : Bytes)
(h : BitcoinSer.readCompactSize rc b = some (n, rest)) :
n < 2 ^ 64 ∧ (rc = true → n ≤ BitcoinSer.MAX_SIZE) := 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.compactSize_range
Binders and hypothesis. A Boolean , a byte string , a natural number , a byte string , and the hypothesis
i.e. the CompactSize reader with range-check flag succeeds on with value and remainder .
Conclusion. A conjunction of two statements:
where .
Unfolding. The first conjunct is unconditional in . The reader produces in one of four ways: the first byte itself (so ), or the little-endian value of the following 2, 4 or 8 bytes (so , , respectively, since of bytes is below ). Hence every successful read has . The statement asserts this strict bound; is excluded, is not.
The second conjunct is an implication: if is the Boolean true, then , with equality permitted. This reflects the reader's final test, which rejects precisely when is true and ; so is an accepted value and the bound here is non-strict, matching. When is false the implication is vacuously true and the second conjunct contributes nothing; in that case may be as large as (the reader with false does not reject large values), and the theorem gives only the first conjunct.
Note the shape of the bound: the conclusion says , not ; a reader comparing against an intent phrased with a strict bound should note this.
What is not said. The theorem does not say the reader succeeds on any particular input, nor that it fails above (it only bounds the value in the success case). It does not relate to the bytes of (that is compactSize_canonical). It does not bound or relate it to . It says nothing about canonicality of the encoding. For it does not assert any bound tighter than . It concerns only the direct reader, not / (although those call the reader with true, so a consequence would be that list and byte-string lengths obtained through them are ; this is not stated).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.