The byte form parses to the instruction form
ProvedBitcoinToLocal.parseScript_toLocalFor keys of at most 520 bytes and : parseScript (toLocalBytes rev delay dpk) = some (toLocalScript rev delay dpk), through GetOp on the canonical pushes and CScript's small-integer encoding.
import Definitions.Def_BitcoinToLocal import Definitions.Def_BitcoinScript import Definitions.Def_BitcoinSig open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinToLocal.parseScript_toLocal (rev dpk : Bytes) (delay : Int)
(hrev : rev.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (hdpk : dpk.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hd : delay.natAbs < 2 ^ 32) :
BitcoinSig.parseScript (BitcoinToLocal.toLocalBytes rev delay dpk) = some (BitcoinToLocal.toLocalScript rev delay dpk) := 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: BitcoinToLocal.parseScript_toLocal
Statement. For all byte strings (named rev) and (named dpk) and every integer (named delay), under the hypotheses
( is the preamble's MAX_SCRIPT_ELEMENT_SIZE; is the absolute value as a natural),
That is, byte-level parsing of the serialized script succeeds (does not return "none") and yields exactly the nine-instruction parsed script.
The two sides.
is the byte string
where is: for , the byte then ; for , bytes then ; for , byte , the 2-byte little-endian , then ; otherwise , the 4-byte little-endian , then . And is the single byte (i.e. for , for ) when or , and otherwise, with the script-number encoding (, so ; for the little-endian magnitude bytes of without trailing zeros, with an appended / byte if the top bit of the last byte is set, else the top bit set on the last byte when ).
is the instruction list
where is the opcode with byte when or , and the data push of otherwise (the empty push for ).
The parser. runs a fuel-bounded loop (fuel ) that repeatedly applies and collects the instructions: on the empty string it returns ; if the fuel is exhausted on a non-empty string it returns ; if fails it returns ; otherwise it prepends the instruction and continues on the remainder. on the empty string is ; on with read as a natural: if () it is a push whose size is itself when ; the next byte when ( if is empty); the little-endian value of the next two bytes when ( if fewer than two); the little-endian value of the next four bytes when ( if fewer than four); then, with the size bytes consumed, if fewer than that many bytes remain the result is , else the instruction is the push of exactly that many bytes and the remainder follows. If the instruction is the opcode with remainder (any such byte, including and –, is returned as an opcode instruction).
Hypotheses. The size bounds on and and the magnitude bound on are the only assumptions; nothing else about the contents of , is assumed, and may be negative or zero.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.