The funding script's byte form parses to its instruction form
ProvedBitcoinFunding.parseScript_fundingFor keys of at most 520 bytes: parseScript (fundingBytes pubkey1 pubkey2) = some (fundingScript pubkey1 pubkey2).
import Definitions.Def_BitcoinFunding import Definitions.Def_BitcoinScript import Definitions.Def_BitcoinSig open BitcoinFunding BitcoinHtlc open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinFunding.parseScript_funding (pubkey1 pubkey2 : Bytes)
(h1 : pubkey1.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (h2 : pubkey2.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) :
BitcoinSig.parseScript (BitcoinFunding.fundingBytes pubkey1 pubkey2) = some (BitcoinFunding.fundingScript pubkey1 pubkey2) := 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: BitcoinFunding.parseScript_funding
A byte is an 8-bit word; a byte string is a finite list of bytes.
Statement
For all byte strings (named pubkey1, pubkey2; otherwise unconstrained in content), under the two hypotheses
( is the constant MAX_SCRIPT_ELEMENT_SIZE; is the length in bytes), the theorem asserts the equality
an equality of values in , where a script is a list of parsed instructions. In words: the byte-level parser, applied to the serialized funding script, does not fail and returns exactly the five-instruction parsed funding script. Both sides are unfolded below.
The right-hand side: fundingScript
An instruction is either , a data push carrying a byte string , or , a non-push opcode with byte . By definition
where is when or , and otherwise the push of the script-number encoding of . For this gives . So the right-hand side is
Equality of scripts is entrywise equality of instruction lists; iff .
The argument of the left-hand side: fundingBytes
with when or (so ), otherwise of the script-number encoding of ; and , for :
- : the single byte , then ;
- : bytes , then ;
- : byte , then as 2 little-endian bytes, then ;
- otherwise: byte , then as 4 little-endian bytes (modulo ), then .
Under the hypotheses, each of is at most , so only the first three cases can arise for the two pushes (in particular when a key is empty).
The parser: parseScript
runs an auxiliary parser with a fuel equal to :
- on the empty byte string, it returns (regardless of fuel);
- on a non-empty string with fuel , it returns ;
- otherwise it calls ; if that is the result is ; if it is (one instruction and the remaining bytes), the remainder is parsed recursively with one unit less fuel, and propagates, otherwise is prepended to the recursively parsed list.
(one instruction) is:
- : .
- with the numeric value of :
-
if (), a push: the size and remainder are
- : size , remainder (so the byte is a push of the empty string);
- : size = the next byte, remainder after it; if is empty;
- : size = little-endian value of the next 2 bytes; if fewer than 2 remain;
- : size = little-endian value of the next 4 bytes; if fewer than 4 remain;
then if fewer than size bytes remain, else ;
-
if : — every byte from to , including and , is returned as a non-push opcode with no further check.
-
What is and is not constrained
- The only hypotheses are the two length bounds on and ; the theorem makes no claim when either key exceeds bytes.
- and are arbitrary byte strings within that bound (they may be empty, equal to each other, or of any content; no public-key format is required).
- The conclusion is a statement about parsing only: it asserts that parsing succeeds (is not ) and that the resulting instruction list is exactly the five-entry list above, with the pushed data equal to and respectively.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.