The funding output's single spending condition, for any witness stack
ProvedBitcoinFunding.funding_spends_iffFor keys of at most 520 bytes and any stack st: the witness-v0 success condition for fundingScript pubkey1 pubkey2 holds iff FundingSpend f o pubkey1 pubkey2 st. The HTLC mission's multisig_two turns the loop verdict into the two signature checks in order; any other stack shape fails.
import Definitions.Def_BitcoinFunding import Definitions.Def_BitcoinScript import Definitions.Def_BitcoinVerify open BitcoinFunding BitcoinHtlc open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinFunding.funding_spends_iff (f : Flags) (o : Oracle) (pubkey1 pubkey2 : Bytes) (st : List Bytes)
(h1 : pubkey1.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (h2 : pubkey2.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) :
(∃ res, BitcoinScript.evalScript f o st (BitcoinFunding.fundingScript pubkey1 pubkey2) = some res ∧
res.length = 1 ∧ BitcoinVerify.topTrue res = true) ↔
BitcoinFunding.FundingSpend f o pubkey1 pubkey2 st := 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.funding_spends_iff
A byte is an 8-bit word; a byte string () is a finite list of bytes; a stack is a finite list of byte strings whose first entry is the top.
Statement
The theorem quantifies over:
- a flag record with exactly three boolean fields , , ;
- an oracle : a record of abstract functions ; (first argument "signature", second "public key"; value , or ); . Nothing is assumed about any of these functions;
- two byte strings (
pubkey1,pubkey2), unconstrained in content; - a stack (any finite list of byte strings: empty, or of any length, with elements of any length);
and assumes and ( = MAX_SCRIPT_ELEMENT_SIZE). No bound is placed on the number or the sizes of the elements of .
Under these, the theorem asserts the logical equivalence
The left-hand side says: the interpreter run of the funding script on the initial stack does not fail, its final main stack has exactly one element, and that element is "true" in the sense of . The right-hand side is the proposition , unfolded below.
topTrue and castToBool
is when is empty, and otherwise. for a byte string is: for ; for a single byte , true iff and ; for with non-empty, true iff or . Equivalently: some byte other than the last is non-zero, or the last byte is neither nor .
The right-hand side: FundingSpend
That is: has exactly three elements — top , then , then at the bottom (so for any of length the right-hand side is false); paired with and paired with both receive the verdict from the oracle (a verdict of or for either pair falsifies it); and if is true then is the empty byte string, while if it is false is arbitrary. No lengths of are constrained; , and the oracle's hash and lock-time fields are not consulted.
The script
where is (for or , ; otherwise a push of the script-number encoding of ), is a data push, and is OP_CHECKMULTISIG.
The left-hand side: the interpreter evalScript
is (failure) or for a stack . The machine state is (main stack, alternate stack, condition stack — a list of booleans —, opcode counter), initially . The instructions of are run in order by the one-step rule below; any failure makes the whole result . After the last instruction the run fails if is non-empty; otherwise the result is of the final main stack.
One step:
- : fail if . Otherwise, if every entry of is (vacuously so when empty), is placed on top of the main stack; else the state is unchanged. Then fail if .
- : counted iff . If counted and counter: fail; else if counted, increment the counter. Fail if is one of the fifteen disabled opcodes (–, –, , , –). Then, if every entry of is true or : apply the one-opcode executor (fail if it fails), then fail if ; otherwise skip the opcode (same size check).
The one-opcode executor on the two opcodes occurring in the funding script (other branches not reproduced):
- (branch for or ; not counted): push , where is for and otherwise the little-endian bytes of without trailing zeros, plus an extra byte / (negative/positive) if the top bit of the last magnitude byte is set, or else the top bit of the last byte set when . For this pushes .
- (
OP_CHECKMULTISIG; counted). With main stack and the already-incremented counter :- Fail if . Else .
- : fail if ; otherwise the signed little-endian value of (sign = top bit of last byte, magnitude = little-endian value with that bit cleared; empty string ). Fail if or .
- ; fail if .
- first entries of , rest; fail if fewer than were available.
- Fail if ; else . (fail if ); fail if or .
- first entries of , rest; fail if fewer than were available.
- (below): fail if ; else let be its boolean.
- Fail if ; else . Fail if and .
- New main stack with , ; counter .
, both lists top-first:
- : (whatever is).
- , : .
- , : evaluate . . if then else (both consumed). if then else (only the key consumed; the same signature is retried against the next key). The top signature is thus tried against the top key first.
What the quantification silently includes
- ranges over all stacks, including the empty stack, stacks with fewer or more than three elements, and stacks whose elements exceed bytes (the interpreter checks the -byte bound only on data pushed by the script, i.e. , not on the initial stack; the -element bound applies to the whole stack at every step).
- are arbitrary byte strings of length at most ; no public-key format is required.
- The oracle is arbitrary; in particular may return on any pair, and the theorem's two sides refer to the same .
- The flags and are quantified over but are not consulted by either side.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.