Every annotation is a suffix of the script
ProvedBitcoinScriptV2.annotate_suffixIf annotate s = some l and (i, r) ∈ l then s = pre ++ r for some pre.
import Definitions.Def_BitcoinScriptV2 import Definitions.Def_BitcoinScript open BitcoinScriptV2 BitcoinScript BitcoinSig BitcoinVerify
theorem BitcoinScriptV2.annotate_suffix (s : BitcoinScript.Bytes) (l : List (BitcoinScript.Instr × BitcoinScript.Bytes))
(h : BitcoinScriptV2.annotate s = some l) (i : BitcoinScript.Instr) (r : BitcoinScript.Bytes) (hm : (i, r) ∈ l) :
∃ pre, s = pre ++ r := 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: BitcoinScriptV2.annotate_suffix
Statement. For every byte string , every list of pairs (instruction, byte string), every instruction and every byte string : if
then there exists a byte string with
i.e. is a suffix of . Nothing is asserted about (it may be empty, and it is not stated to end with the encoding of ). The instruction may be a push or an opcode. If or is empty (e.g. ), the statement is vacuous.
Unfolded definitions used above
Basic objects and notation
- A byte is an 8-bit word, identified with its value in and written in hexadecimal (e.g. ). is the set of finite byte strings (lists of bytes); is the length, concatenation, the empty string.
- is the first entries of a list ; is what is left after removing the first entries, which is the empty list when .
- For a 0-based index , the statement "" means: and the entry of at index is . Indexing out of range yields no value, so such an equation can only hold with .
- A partial result is either or . Applying a function "under " () sends and .
- An instruction is either , carrying a data string , or , carrying an opcode byte . A script (parsed) is a finite list of instructions.
- Opcode bytes named below: , , , , , , , .
- A signature version is one of exactly two values: (legacy) or .
Reading one instruction from bytes:
returns either or with an instruction and the remaining bytes:
- : .
- Otherwise let be the first byte and the rest.
- If (a push opcode), a data length and a position are determined: if , and the data starts right after ; if , is the next byte ( if there is none); if , is the little-endian value of the next 2 bytes ( if fewer than 2 remain); if , is the little-endian value of the next 4 bytes ( if fewer than 4 remain). Then, if fewer than bytes remain, ; otherwise . (So gives .)
- If : .
On success the remainder is a suffix of that is at least one byte shorter than . never returns with .
The annotated parse:
, where, with a fuel counter :
- for every ;
- for ;
- for : if then ; if then, if the result is , and if it is the result is .
So on success , where is read from leaving , is read from leaving , and : each instruction is paired with the bytes that follow it in . . Since every successful consumes at least one byte, the fuel never runs out while input remains; hence exactly when fails at some instruction boundary, i.e. on a malformed push (a truncated length field, or fewer data bytes than announced).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.