An opcode's annotation is the bytes after its position
ProvedBitcoinScriptV2.annotate_op_suffixIf annotate s = some l and (.op c, r) ∈ l then there is a position with s[p]? = some c and r = s.drop (p+1).
import Definitions.Def_BitcoinScriptV2 import Definitions.Def_BitcoinScript open BitcoinScriptV2 BitcoinScript BitcoinSig BitcoinVerify
theorem BitcoinScriptV2.annotate_op_suffix (s : BitcoinScript.Bytes) (l : List (BitcoinScript.Instr × BitcoinScript.Bytes))
(h : BitcoinScriptV2.annotate s = some l) (c : BitcoinScript.Byte) (r : BitcoinScript.Bytes) (hm : (.op c, r) ∈ l) :
∃ p, s[p]? = some c ∧ r = s.drop (p + 1) := 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_op_suffix
Statement. For every byte string , every list of pairs (instruction, byte string), every byte and every byte string : if
then there exists a natural number such that
i.e. , the byte of at 0-based index is , and consists exactly of the bytes of after index .
Notes on the literal content:
- Membership of in is plain list membership; the statement does not mention the position of that pair in , and it does not say that is the offset at which the instruction was read — only that some index holding the byte has as the bytes following it. (Since determines , such a is unique if it exists.)
- If (malformed push) the statement says nothing. For , is empty and the statement is vacuous. Since only yields with , the hypothesis can only hold for such .
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.