Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Received HTLC (anchors), timeout path

Proved
BitcoinAnchors.received_timeout

by pitimespi · Oct 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

anchorsbip112bitcoinbitcoin-mainnetbolt3csvformal-verificationhtlclightningp2wshscript

For pushed strings of at most 520 bytes, hash160 x ≠ revHash, x not 32 bytes: if CltvPasses f o expiry ∧ CsvPasses f o 1 then (checkSig sig remoteKey).map … else none.

Preamble
import Definitions.Def_BitcoinAnchors
import Definitions.Def_BitcoinScript
import Definitions.Def_BitcoinHtlc
import Definitions.Def_BitcoinToLocal
open BitcoinToLocal BitcoinSig BitcoinVerify
open BitcoinScript
Formal statement
theorem BitcoinAnchors.received_timeout (f : Flags) (o : Oracle) (revHash remoteKey localKey payHash x sig : Bytes) (expiry : Int)
    (hrev : revHash.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (hrem : remoteKey.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
    (hloc : localKey.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (hpay : payHash.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
    (hd : expiry.natAbs < 2 ^ 32) (hb : o.hash160 x ≠ revHash) (h32 : x.length ≠ 32) :
    BitcoinScript.evalScript f o [x, sig] (BitcoinAnchors.receivedScript revHash remoteKey localKey payHash expiry) =
      if BitcoinHtlc.CltvPasses f o expiry ∧ BitcoinToLocal.CsvPasses f o 1 then
        (o.checkSig sig remoteKey).map (fun ok => [BitcoinScript.boolBytes ok])
      else none := by sorry
Source
BOLT #3 with option_anchors: to_remote Output, Anchor Outputs, Offered/Received HTLC Outputs: https://github.com/lightning/bolts/blob/master/03-transactions.md#to_remote-output; Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: EvalScript (OP_CHECKSIGVERIFY, OP_IFDUP, OP_NOTIF, OP_CHECKSEQUENCEVERIFY, OP_CHECKMULTISIG), GenericTransactionSignatureChecker::CheckSequence (src/script/interpreter.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/script/interpreter.cpp); BIP68, BIP112, BIP141
Read-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: BitcoinAnchors.received_timeout

Declaration. For every flag record fff (three unconstrained Booleans), every oracle ooo (arbitrary hash functions, arbitrary three-valued o.checkSigo.\mathrm{checkSig}o.checkSig, arbitrary o.checkLockTimeo.\mathrm{checkLockTime}o.checkLockTime, o.checkSequenceo.\mathrm{checkSequence}o.checkSequence), all byte strings HHH (revHash), RRR (remoteKey), LLL (localKey), PPP (payHash), xxx, σ\sigmaσ (sig), and every integer eee (expiry), under the hypotheses

  • ∣H∣≤520|H|\le 520∣H∣≤520 (hrev), ∣R∣≤520|R|\le 520∣R∣≤520 (hrem), ∣L∣≤520|L|\le 520∣L∣≤520 (hloc), ∣P∣≤520|P|\le 520∣P∣≤520 (hpay): each of the four script parameters fits in one stack element;
  • ∣e∣<232|e|<2^{32}∣e∣<232 (hd);
  • o.hash160(x)≠Ho.\mathrm{hash160}(x)\neq Ho.hash160(x)=H (hb);
  • ∣x∣≠32|x|\neq 32∣x∣=32 (h32): xxx is not exactly 32 bytes long (any other length, including 000 or more than 520520520);

the following equality of optional stacks holds:

evalScript(f,o,[x,σ],receivedScript(H,R,L,P,e))={map(ok↦[boolBytes(ok)], o.checkSig(σ,R))if CltvPasses(f,o,e) ∧ CsvPasses(f,o,1),noneotherwise.\mathrm{evalScript}\bigl(f,o,[x,\sigma],\mathrm{receivedScript}(H,R,L,P,e)\bigr)=\begin{cases}\mathrm{map}\bigl(ok\mapsto[\mathrm{boolBytes}(ok)],\ o.\mathrm{checkSig}(\sigma,R)\bigr) & \text{if } \mathrm{CltvPasses}(f,o,e)\ \land\ \mathrm{CsvPasses}(f,o,1),\\ \mathrm{none} & \text{otherwise.}\end{cases}evalScript(f,o,[x,σ],receivedScript(H,R,L,P,e))={map(ok↦[boolBytes(ok)], o.checkSig(σ,R))none​if CltvPasses(f,o,e) ∧ CsvPasses(f,o,1),otherwise.​

The initial stack [x,σ][x,\sigma][x,σ] has exactly two elements, xxx on top. receivedScript(H,R,L,P,e)\mathrm{receivedScript}(H,R,L,P,e)receivedScript(H,R,L,P,e) is the 32-instruction script listed in part A, with numInstr(e)\mathrm{numInstr}(e)numInstr(e) as its 24th instruction. CltvPasses(f,o,e)\mathrm{CltvPasses}(f,o,e)CltvPasses(f,o,e) unfolds to "f.cltv=falsef.\mathrm{cltv}=\mathrm{false}f.cltv=false, or (0≤e0\le e0≤e and o.checkLockTime(e)=trueo.\mathrm{checkLockTime}(e)=\mathrm{true}o.checkLockTime(e)=true)"; CsvPasses(f,o,1)\mathrm{CsvPasses}(f,o,1)CsvPasses(f,o,1) to "f.csv=falsef.\mathrm{csv}=\mathrm{false}f.csv=false or o.checkSequence(1)=trueo.\mathrm{checkSequence}(1)=\mathrm{true}o.checkSequence(1)=true". The map\mathrm{map}map value is none\mathrm{none}none if o.checkSig(σ,R)=noneo.\mathrm{checkSig}(\sigma,R)=\mathrm{none}o.checkSig(σ,R)=none, some [[0x01]]\mathrm{some}\,[[0x01]]some[[0x01]] if some true\mathrm{some\ true}some true, some [[ ]]\mathrm{some}\,[[\,]]some[[]] (a single empty element) if some false\mathrm{some\ false}some false. The "otherwise" case covers f.cltvf.\mathrm{cltv}f.cltv on with (e<0e<0e<0 or o.checkLockTime(e)=falseo.\mathrm{checkLockTime}(e)=\mathrm{false}o.checkLockTime(e)=false), and f.csvf.\mathrm{csv}f.csv on with o.checkSequence(1)=falseo.\mathrm{checkSequence}(1)=\mathrm{false}o.checkSequence(1)=false. The right-hand side does not mention PPP, LLL, or o.hash160(x)o.\mathrm{hash160}(x)o.hash160(x) beyond the hypothesis hb.


Common unfolded definitions, part A: the script interpreter

Everything below is a literal unfolding of the definitions the statement depends on. Nothing here is a claim about the theorem; it only says what the symbols mean.

Bytes and stacks. A byte is an 8-bit word, i.e. a value in {0,…,255}\{0,\dots,255\}{0,…,255}. A byte string is a finite list of bytes; ∣v∣|v|∣v∣ is its length and [ ][\,][] is the empty byte string. A stack is a finite list of byte strings written top first: in [a,b,c][a,b,c][a,b,c] the element aaa is on top. The constants are MAX_SCRIPT_ELEMENT_SIZE=520\mathrm{MAX\_SCRIPT\_ELEMENT\_SIZE}=520MAX_SCRIPT_ELEMENT_SIZE=520, MAX_STACK_SIZE=1000\mathrm{MAX\_STACK\_SIZE}=1000MAX_STACK_SIZE=1000, MAX_OPS_PER_SCRIPT=201\mathrm{MAX\_OPS\_PER\_SCRIPT}=201MAX_OPS_PER_SCRIPT=201, MAX_PUBKEYS_PER_MULTISIG=20\mathrm{MAX\_PUBKEYS\_PER\_MULTISIG}=20MAX_PUBKEYS_PER_MULTISIG=20.

Truth value of a byte string, castToBool(v)\mathrm{castToBool}(v)castToBool(v): [ ][\,][] is false; a one-byte string [b][b][b] is true iff b≠0b\neq 0b=0 and b≠0x80b\neq 0x80b=0x80; a string b::rb::rb::r of length at least two is true iff b≠0b\neq 0b=0 or castToBool(r)\mathrm{castToBool}(r)castToBool(r). Equivalently, vvv is true iff some byte of vvv is nonzero, except that a string consisting of zero bytes followed by a final byte 0x800x800x80 is false.

boolBytes\mathrm{boolBytes}boolBytes: boolBytes(true)=[0x01]\mathrm{boolBytes}(\mathrm{true})=[0x01]boolBytes(true)=[0x01] (the single byte 111) and boolBytes(false)=[ ]\mathrm{boolBytes}(\mathrm{false})=[\,]boolBytes(false)=[] (the empty byte string).

Stack literals used in the statements. [[1]][[1]][[1]] is the stack with exactly one element, the one-byte string 0x010x010x01; [[16]][[16]][[16]] is the stack with exactly one element, the one-byte string 0x100x100x10 (decimal 161616); [[ ]][[\,]][[]] is the stack with exactly one element, the empty byte string; [ ][\,][] is the empty stack. A stack written [σ][\sigma][σ] has exactly one element σ\sigmaσ; [x,σ][x,\sigma][x,σ] has exactly two, xxx on top.

Flags fff: a record of three Booleans f.cltvf.\mathrm{cltv}f.cltv, f.csvf.\mathrm{csv}f.csv, f.nulldummyf.\mathrm{nulldummy}f.nulldummy. No other verification flag exists in this model. Where fff is a parameter of a theorem, all three values are unconstrained.

Oracle ooo: a record of arbitrary functions with no axioms relating them to each other or to anything else: five byte-string-to-byte-string functions o.ripemd160o.\mathrm{ripemd160}o.ripemd160, o.sha1o.\mathrm{sha1}o.sha1, o.sha256o.\mathrm{sha256}o.sha256, o.hash160o.\mathrm{hash160}o.hash160, o.hash256o.\mathrm{hash256}o.hash256; a function o.checkSig(σ,k)o.\mathrm{checkSig}(\sigma,k)o.checkSig(σ,k) from pairs of byte strings (first the signature, second the key) to the three values none\mathrm{none}none, some true\mathrm{some\ true}some true, some false\mathrm{some\ false}some false; and two functions o.checkLockTime, o.checkSequence:Z→{true,false}o.\mathrm{checkLockTime},\,o.\mathrm{checkSequence}:\mathbb Z\to\{\mathrm{true},\mathrm{false}\}o.checkLockTime,o.checkSequence:Z→{true,false}. In particular, in a theorem that takes ooo as a parameter, o.hash160o.\mathrm{hash160}o.hash160 is an arbitrary function (its outputs need not be 20 bytes long, it need not be injective, and it has no relation to o.sha256o.\mathrm{sha256}o.sha256), and o.checkSigo.\mathrm{checkSig}o.checkSig is an arbitrary three-valued function.

Script numbers. serialize(v)\mathrm{serialize}(v)serialize(v) for v∈Zv\in\mathbb Zv∈Z: [ ][\,][] if v=0v=0v=0; otherwise the little-endian bytes of ∣v∣|v|∣v∣ with no trailing zero byte, after which: if the last byte has its top bit (0x800x800x80) set, one extra byte is appended (0x800x800x80 if v<0v<0v<0, 0x000x000x00 if v>0v>0v>0); otherwise, if v<0v<0v<0, the top bit of the last byte is set. Thus serialize(1)=[0x01]\mathrm{serialize}(1)=[0x01]serialize(1)=[0x01], serialize(2)=[0x02]\mathrm{serialize}(2)=[0x02]serialize(2)=[0x02], serialize(16)=[0x10]\mathrm{serialize}(16)=[0x10]serialize(16)=[0x10], serialize(32)=[0x20]\mathrm{serialize}(32)=[0x20]serialize(32)=[0x20]. The decoding setVch(v)\mathrm{setVch}(v)setVch(v) is 000 for [ ][\,][], and otherwise the little-endian value of vvv with the top bit of the last byte removed and read as a minus sign. toNum(false,m,v)\mathrm{toNum}(\mathrm{false},m,v)toNum(false,m,v) is none\mathrm{none}none if m<∣v∣m<|v|m<∣v∣ and some setVch(v)\mathrm{some}\,\mathrm{setVch}(v)somesetVch(v) otherwise (no minimal-encoding check is made).

Instructions and scripts. An instruction is either a push push(d)\mathrm{push}(d)push(d) of a byte string ddd, or an opcode op(c)\mathrm{op}(c)op(c) for a byte ccc. A script is a finite list of instructions. Opcode bytes that occur: OP_1NEGATE =0x4f=0x4f=0x4f, OP_1 =0x51=0x51=0x51, OP_2 =0x52=0x52=0x52, OP_16 =0x60=0x60=0x60, OP_IF =0x63=0x63=0x63, OP_NOTIF =0x64=0x64=0x64, OP_ELSE =0x67=0x67=0x67, OP_ENDIF =0x68=0x68=0x68, OP_IFDUP =0x73=0x73=0x73, OP_DROP =0x75=0x75=0x75, OP_DUP =0x76=0x76=0x76, OP_SWAP =0x7c=0x7c=0x7c, OP_SIZE =0x82=0x82=0x82, OP_EQUAL =0x87=0x87=0x87, OP_EQUALVERIFY =0x88=0x88=0x88, OP_HASH160 =0xa9=0xa9=0xa9, OP_CHECKSIG =0xac=0xac=0xac, OP_CHECKSIGVERIFY =0xad=0xad=0xad, OP_CHECKMULTISIG =0xae=0xae=0xae, OP_CHECKLOCKTIMEVERIFY =0xb1=0xb1=0xb1, OP_CHECKSEQUENCEVERIFY =0xb2=0xb2=0xb2.

numInstr(n)\mathrm{numInstr}(n)numInstr(n) for n∈Zn\in\mathbb Zn∈Z: if n=−1n=-1n=−1 or 1≤n≤161\le n\le 161≤n≤16, the opcode op(n+0x50)\mathrm{op}(n+0x50)op(n+0x50) (so numInstr(1)=op(OP_1)\mathrm{numInstr}(1)=\mathrm{op}(\mathrm{OP\_1})numInstr(1)=op(OP_1), numInstr(2)=op(OP_2)\mathrm{numInstr}(2)=\mathrm{op}(\mathrm{OP\_2})numInstr(2)=op(OP_2), numInstr(16)=op(OP_16)\mathrm{numInstr}(16)=\mathrm{op}(\mathrm{OP\_16})numInstr(16)=op(OP_16), numInstr(−1)=op(0x4f)\mathrm{numInstr}(-1)=\mathrm{op}(0x4f)numInstr(−1)=op(0x4f)); otherwise the push push(serialize(n))\mathrm{push}(\mathrm{serialize}(n))push(serialize(n)) (so numInstr(32)=push([0x20])\mathrm{numInstr}(32)=\mathrm{push}([0x20])numInstr(32)=push([0x20]) and numInstr(0)=push([ ])\mathrm{numInstr}(0)=\mathrm{push}([\,])numInstr(0)=push([])).

The parsed scripts of the anchors file, for arbitrary byte strings KKK (funding key), RRR (remote key), LLL (local key), HHH (revocation hash), PPP (payment hash) and an integer eee (expiry):

toRemoteScript(R)=[push(R), op(OP_CHECKSIGVERIFY), op(OP_1), op(OP_CHECKSEQUENCEVERIFY)].\mathrm{toRemoteScript}(R)=[\mathrm{push}(R),\ \mathrm{op}(\mathrm{OP\_CHECKSIGVERIFY}),\ \mathrm{op}(\mathrm{OP\_1}),\ \mathrm{op}(\mathrm{OP\_CHECKSEQUENCEVERIFY})].toRemoteScript(R)=[push(R), op(OP_CHECKSIGVERIFY), op(OP_1), op(OP_CHECKSEQUENCEVERIFY)]. anchorScript(K)=[push(K), op(OP_CHECKSIG), op(OP_IFDUP), op(OP_NOTIF), op(OP_16), op(OP_CHECKSEQUENCEVERIFY), op(OP_ENDIF)].\mathrm{anchorScript}(K)=[\mathrm{push}(K),\ \mathrm{op}(\mathrm{OP\_CHECKSIG}),\ \mathrm{op}(\mathrm{OP\_IFDUP}),\ \mathrm{op}(\mathrm{OP\_NOTIF}),\ \mathrm{op}(\mathrm{OP\_16}),\ \mathrm{op}(\mathrm{OP\_CHECKSEQUENCEVERIFY}),\ \mathrm{op}(\mathrm{OP\_ENDIF})].anchorScript(K)=[push(K), op(OP_CHECKSIG), op(OP_IFDUP), op(OP_NOTIF), op(OP_16), op(OP_CHECKSEQUENCEVERIFY), op(OP_ENDIF)].

offeredScript(H,R,L,P)\mathrm{offeredScript}(H,R,L,P)offeredScript(H,R,L,P) is the 30-instruction list: OP_DUP, OP_HASH160, push(H)\mathrm{push}(H)push(H), OP_EQUAL, OP_IF, OP_CHECKSIG, OP_ELSE, push(R)\mathrm{push}(R)push(R), OP_SWAP, OP_SIZE, push([0x20])\mathrm{push}([0x20])push([0x20]), OP_EQUAL, OP_NOTIF, OP_DROP, OP_2, OP_SWAP, push(L)\mathrm{push}(L)push(L), OP_2, OP_CHECKMULTISIG, OP_ELSE, OP_HASH160, push(P)\mathrm{push}(P)push(P), OP_EQUALVERIFY, OP_CHECKSIG, OP_ENDIF, OP_1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_ENDIF.

receivedScript(H,R,L,P,e)\mathrm{receivedScript}(H,R,L,P,e)receivedScript(H,R,L,P,e) is the 32-instruction list: OP_DUP, OP_HASH160, push(H)\mathrm{push}(H)push(H), OP_EQUAL, OP_IF, OP_CHECKSIG, OP_ELSE, push(R)\mathrm{push}(R)push(R), OP_SWAP, OP_SIZE, push([0x20])\mathrm{push}([0x20])push([0x20]), OP_EQUAL, OP_IF, OP_HASH160, push(P)\mathrm{push}(P)push(P), OP_EQUALVERIFY, OP_2, OP_SWAP, push(L)\mathrm{push}(L)push(L), OP_2, OP_CHECKMULTISIG, OP_ELSE, OP_DROP, numInstr(e)\mathrm{numInstr}(e)numInstr(e), OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_CHECKSIG, OP_ENDIF, OP_1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_ENDIF.

Execution state: a main stack, an alt stack, a condition stack vfExec\mathrm{vfExec}vfExec (a list of Booleans) and an op counter. The initial state for a stack ststst has main stack ststst, empty alt stack, empty vfExec\mathrm{vfExec}vfExec, counter 000. The machine is executing when every entry of vfExec\mathrm{vfExec}vfExec is true (vacuously, when vfExec\mathrm{vfExec}vfExec is empty).

evalScript(f,o,st,S)\mathrm{evalScript}(f,o,st,S)evalScript(f,o,st,S): starting from the initial state of ststst, apply step\mathrm{step}step to the instructions of SSS in order; if any step returns none\mathrm{none}none the result is none\mathrm{none}none; after the last instruction the result is none\mathrm{none}none if vfExec\mathrm{vfExec}vfExec is non-empty and otherwise some\mathrm{some}some of the final main stack. So the value is either none\mathrm{none}none (script failure) or some st′\mathrm{some}\,st'somest′ for a stack st′st'st′ (the alt stack and the counter are discarded).

step\mathrm{step}step on push(d)\mathrm{push}(d)push(d): none\mathrm{none}none if 520<∣d∣520<|d|520<∣d∣; otherwise, if executing, ddd is placed on top of the main stack (if not executing, nothing changes); then none\mathrm{none}none if the main-stack size plus the alt-stack size exceeds 100010001000, else the new state.

step\mathrm{step}step on op(c)\mathrm{op}(c)op(c): ccc is counted when 0x60<c0x60<c0x60<c; if counted and the counter plus one exceeds 201201201, none\mathrm{none}none; otherwise the counter is incremented when counted; none\mathrm{none}none if ccc is one of the fifteen disabled opcodes (none of the opcodes listed above is disabled); otherwise, if executing or 0x63≤c≤0x680x63\le c\le 0x680x63≤c≤0x68 (the conditionals), execOp\mathrm{execOp}execOp is applied and the result is none\mathrm{none}none if it is none\mathrm{none}none or if the stack-size sum then exceeds 100010001000; otherwise (not executing, not a conditional) the state is unchanged, again subject to the size check.

execOp(f,o,fExec,c,s)\mathrm{execOp}(f,o,\mathrm{fExec},c,s)execOp(f,o,fExec,c,s) for the opcodes that occur ("none\mathrm{none}none" means script failure; "no change" means the state is returned unchanged):

  • OP_1NEGATE, OP_1, …, OP_16: push serialize(c−0x50)\mathrm{serialize}(c-0x50)serialize(c−0x50); so OP_1 pushes [0x01][0x01][0x01], OP_2 pushes [0x02][0x02][0x02], OP_16 pushes [0x10][0x10][0x10]. These bytes are ≤0x60\le 0x60≤0x60, so they are not counted.
  • OP_CHECKLOCKTIMEVERIFY: if f.cltv=falsef.\mathrm{cltv}=\mathrm{false}f.cltv=false, no change. Otherwise none\mathrm{none}none on an empty stack; else with top ttt (not popped): none\mathrm{none}none if ∣t∣>5|t|>5∣t∣>5; with n=setVch(t)n=\mathrm{setVch}(t)n=setVch(t), none\mathrm{none}none if n<0n<0n<0, none\mathrm{none}none if o.checkLockTime(n)=falseo.\mathrm{checkLockTime}(n)=\mathrm{false}o.checkLockTime(n)=false, else no change.
  • OP_CHECKSEQUENCEVERIFY: if f.csv=falsef.\mathrm{csv}=\mathrm{false}f.csv=false, no change. Otherwise none\mathrm{none}none on an empty stack; else with top ttt (not popped): none\mathrm{none}none if ∣t∣>5|t|>5∣t∣>5; with n=setVch(t)n=\mathrm{setVch}(t)n=setVch(t), none\mathrm{none}none if n<0n<0n<0; no change if bit 313131 of nnn is set (precisely: max⁡(n,0) & 231≠0\max(n,0)\,\&\,2^{31}\neq 0max(n,0)&231=0); else none\mathrm{none}none if o.checkSequence(n)=falseo.\mathrm{checkSequence}(n)=\mathrm{false}o.checkSequence(n)=false, else no change.
  • OP_IF / OP_NOTIF: if executing, none\mathrm{none}none on an empty stack; else the top ttt is popped, v=castToBool(t)v=\mathrm{castToBool}(t)v=castToBool(t) (negated for OP_NOTIF) and vvv is pushed onto vfExec\mathrm{vfExec}vfExec. If not executing, false\mathrm{false}false is pushed onto vfExec\mathrm{vfExec}vfExec and the stack is untouched.
  • OP_ELSE: none\mathrm{none}none if vfExec\mathrm{vfExec}vfExec is empty; else its top entry is negated.
  • OP_ENDIF: none\mathrm{none}none if vfExec\mathrm{vfExec}vfExec is empty; else its top entry is removed.
  • OP_IFDUP: none\mathrm{none}none on an empty stack; else if castToBool\mathrm{castToBool}castToBool of the top is true the top is duplicated, otherwise no change.
  • OP_DROP: none\mathrm{none}none on an empty stack; else the top is removed. OP_DUP: none\mathrm{none}none on an empty stack; else the top is duplicated. OP_SWAP: none\mathrm{none}none with fewer than two elements; else the top two are exchanged. OP_SIZE: none\mathrm{none}none on an empty stack; else serialize(∣t∣)\mathrm{serialize}(|t|)serialize(∣t∣) is pushed above the top ttt, which stays.
  • OP_EQUAL / OP_EQUALVERIFY: none\mathrm{none}none with fewer than two elements; else the top aaa and the next bbb are popped and eqeqeq is the proposition "aaa and bbb are the same byte string"; OP_EQUAL pushes boolBytes(eq)\mathrm{boolBytes}(eq)boolBytes(eq); OP_EQUALVERIFY pushes nothing and is none\mathrm{none}none when eqeqeq is false.
  • OP_HASH160: none\mathrm{none}none on an empty stack; else the top ttt is replaced by o.hash160(t)o.\mathrm{hash160}(t)o.hash160(t).
  • OP_CHECKSIG / OP_CHECKSIGVERIFY: none\mathrm{none}none with fewer than two elements; else the top kkk (the key) and the next σ\sigmaσ (the signature) are popped and o.checkSig(σ,k)o.\mathrm{checkSig}(\sigma,k)o.checkSig(σ,k) is consulted: none\mathrm{none}none gives none\mathrm{none}none; some ok\mathrm{some}\,oksomeok: OP_CHECKSIG pushes boolBytes(ok)\mathrm{boolBytes}(ok)boolBytes(ok), while OP_CHECKSIGVERIFY pushes nothing and is none\mathrm{none}none when ok=falseok=\mathrm{false}ok=false.
  • OP_CHECKMULTISIG: none\mathrm{none}none on an empty stack; the top nkn_knk​ is popped and decoded by toNum(false,4,⋅)\mathrm{toNum}(\mathrm{false},4,\cdot)toNum(false,4,⋅) (none\mathrm{none}none if longer than 4 bytes); none\mathrm{none}none if nk<0n_k<0nk​<0 or 20<nk20<n_k20<nk​; the counter becomes counter + nk+\,n_k+nk​, none\mathrm{none}none if that exceeds 201201201; the next nkn_knk​ elements are the keys (none\mathrm{none}none if fewer remain); the next element nsn_sns​ is popped (none\mathrm{none}none if none remains) and decoded likewise, none\mathrm{none}none if ns<0n_s<0ns​<0 or nk<nsn_k<n_snk​<ns​; the next nsn_sns​ elements are the signatures (none\mathrm{none}none if fewer remain); multisigLoop(o,sigs,keys)\mathrm{multisigLoop}(o,\text{sigs},\text{keys})multisigLoop(o,sigs,keys) is computed: none\mathrm{none}none gives none\mathrm{none}none; some ok\mathrm{some}\,oksomeok: none\mathrm{none}none if no element remains, else one more element dummydummydummy is popped, none\mathrm{none}none if f.nulldummy=truef.\mathrm{nulldummy}=\mathrm{true}f.nulldummy=true and dummy≠[ ]dummy\neq[\,]dummy=[], else boolBytes(ok)\mathrm{boolBytes}(ok)boolBytes(ok) is pushed.

multisigLoop(o,sigs,keys)\mathrm{multisigLoop}(o,\text{sigs},\text{keys})multisigLoop(o,sigs,keys) (both lists top first): some true\mathrm{some\ true}some true if sigs is empty; some false\mathrm{some\ false}some false if sigs is non-empty and keys is empty; otherwise, with σ\sigmaσ the first signature and kkk the first key, o.checkSig(σ,k)o.\mathrm{checkSig}(\sigma,k)o.checkSig(σ,k): none\mathrm{none}none gives none\mathrm{none}none; some true\mathrm{some\ true}some true gives some false\mathrm{some\ false}some false if fewer keys than signatures remain after removing both, else the loop on the remaining signatures and remaining keys; some false\mathrm{some\ false}some false gives some false\mathrm{some\ false}some false if the remaining keys are fewer than all the current signatures, else the loop on the same signatures and the remaining keys. For the only instance that occurs, multisigLoop(o,[σL,σR],[L,R])\mathrm{multisigLoop}(o,[\sigma_L,\sigma_R],[L,R])multisigLoop(o,[σL​,σR​],[L,R]) unfolds to: none\mathrm{none}none if o.checkSig(σL,L)=noneo.\mathrm{checkSig}(\sigma_L,L)=\mathrm{none}o.checkSig(σL​,L)=none; some false\mathrm{some\ false}some false if o.checkSig(σL,L)=some falseo.\mathrm{checkSig}(\sigma_L,L)=\mathrm{some\ false}o.checkSig(σL​,L)=some false; and, if o.checkSig(σL,L)=some trueo.\mathrm{checkSig}(\sigma_L,L)=\mathrm{some\ true}o.checkSig(σL​,L)=some true, the value o.checkSig(σR,R)o.\mathrm{checkSig}(\sigma_R,R)o.checkSig(σR​,R) itself. Hence it equals some true\mathrm{some\ true}some true iff o.checkSig(σL,L)=some trueo.\mathrm{checkSig}(\sigma_L,L)=\mathrm{some\ true}o.checkSig(σL​,L)=some true and o.checkSig(σR,R)=some trueo.\mathrm{checkSig}(\sigma_R,R)=\mathrm{some\ true}o.checkSig(σR​,R)=some true; the signature σR\sigma_RσR​ is never checked against LLL, nor σL\sigma_LσL​ against RRR.

CsvPasses(f,o,d)\mathrm{CsvPasses}(f,o,d)CsvPasses(f,o,d) for d∈Zd\in\mathbb Zd∈Z:

f.csv=false  ∨  (0≤d ∧ (max⁡(d,0) & 231≠0 ∨ o.checkSequence(d)=true)).f.\mathrm{csv}=\mathrm{false}\ \ \lor\ \ \bigl(0\le d\ \land\ (\max(d,0)\,\&\,2^{31}\neq 0\ \lor\ o.\mathrm{checkSequence}(d)=\mathrm{true})\bigr).f.csv=false  ∨  (0≤d ∧ (max(d,0)&231=0 ∨ o.checkSequence(d)=true)).

For d=1d=1d=1 and d=16d=16d=16 the bit-31 disjunct is false (1 & 231=01\,\&\,2^{31}=01&231=0 and 16 & 231=016\,\&\,2^{31}=016&231=0), so CsvPasses(f,o,1)  ⟺  f.csv=false∨o.checkSequence(1)=true\mathrm{CsvPasses}(f,o,1)\iff f.\mathrm{csv}=\mathrm{false}\lor o.\mathrm{checkSequence}(1)=\mathrm{true}CsvPasses(f,o,1)⟺f.csv=false∨o.checkSequence(1)=true and CsvPasses(f,o,16)  ⟺  f.csv=false∨o.checkSequence(16)=true\mathrm{CsvPasses}(f,o,16)\iff f.\mathrm{csv}=\mathrm{false}\lor o.\mathrm{checkSequence}(16)=\mathrm{true}CsvPasses(f,o,16)⟺f.csv=false∨o.checkSequence(16)=true. When fff and ooo are arbitrary parameters, o.checkSequenceo.\mathrm{checkSequence}o.checkSequence is an arbitrary function of an integer.

CltvPasses(f,o,e)\mathrm{CltvPasses}(f,o,e)CltvPasses(f,o,e) for e∈Ze\in\mathbb Ze∈Z: f.cltv=false ∨ (0≤e ∧ o.checkLockTime(e)=true)f.\mathrm{cltv}=\mathrm{false}\ \lor\ (0\le e\ \land\ o.\mathrm{checkLockTime}(e)=\mathrm{true})f.cltv=false ∨ (0≤e ∧ o.checkLockTime(e)=true).

topTrue(st)\mathrm{topTrue}(st)topTrue(st): false\mathrm{false}false for the empty stack; castToBool\mathrm{castToBool}castToBool of the top element otherwise.

The spend predicates of the anchors file (all stacks top first; σ,σL,σR,pk,x,d\sigma,\sigma_L,\sigma_R,pk,x,dσ,σL​,σR​,pk,x,d range over byte strings):

ToRemoteSpend(f,o,R,st)\mathrm{ToRemoteSpend}(f,o,R,st)ToRemoteSpend(f,o,R,st): there is σ\sigmaσ with st=[σ]st=[\sigma]st=[σ], o.checkSig(σ,R)=some trueo.\mathrm{checkSig}(\sigma,R)=\mathrm{some\ true}o.checkSig(σ,R)=some true and CsvPasses(f,o,1)\mathrm{CsvPasses}(f,o,1)CsvPasses(f,o,1).

AnchorSpend(f,o,K,st)\mathrm{AnchorSpend}(f,o,K,st)AnchorSpend(f,o,K,st): there is σ\sigmaσ with st=[σ]st=[\sigma]st=[σ] and either o.checkSig(σ,K)=some trueo.\mathrm{checkSig}(\sigma,K)=\mathrm{some\ true}o.checkSig(σ,K)=some true, or both o.checkSig(σ,K)=some falseo.\mathrm{checkSig}(\sigma,K)=\mathrm{some\ false}o.checkSig(σ,K)=some false and CsvPasses(f,o,16)\mathrm{CsvPasses}(f,o,16)CsvPasses(f,o,16).

OfferedSpend(f,o,H,R,L,P,st)\mathrm{OfferedSpend}(f,o,H,R,L,P,st)OfferedSpend(f,o,H,R,L,P,st) is the disjunction of

  1. there are pk,σpk,\sigmapk,σ with st=[pk,σ]st=[pk,\sigma]st=[pk,σ], o.hash160(pk)=Ho.\mathrm{hash160}(pk)=Ho.hash160(pk)=H and o.checkSig(σ,pk)=some trueo.\mathrm{checkSig}(\sigma,pk)=\mathrm{some\ true}o.checkSig(σ,pk)=some true;
  2. there are x,σx,\sigmax,σ with st=[x,σ]st=[x,\sigma]st=[x,σ], o.hash160(x)≠Ho.\mathrm{hash160}(x)\neq Ho.hash160(x)=H, ∣x∣=32|x|=32∣x∣=32, o.hash160(x)=Po.\mathrm{hash160}(x)=Po.hash160(x)=P, o.checkSig(σ,R)=some trueo.\mathrm{checkSig}(\sigma,R)=\mathrm{some\ true}o.checkSig(σ,R)=some true and CsvPasses(f,o,1)\mathrm{CsvPasses}(f,o,1)CsvPasses(f,o,1);
  3. there are x,σL,σR,dx,\sigma_L,\sigma_R,dx,σL​,σR​,d with st=[x,σL,σR,d]st=[x,\sigma_L,\sigma_R,d]st=[x,σL​,σR​,d], o.hash160(x)≠Ho.\mathrm{hash160}(x)\neq Ho.hash160(x)=H, ∣x∣≠32|x|\neq 32∣x∣=32, multisigLoop(o,[σL,σR],[L,R])=some true\mathrm{multisigLoop}(o,[\sigma_L,\sigma_R],[L,R])=\mathrm{some\ true}multisigLoop(o,[σL​,σR​],[L,R])=some true, (f.nulldummy=true⇒d=[ ]f.\mathrm{nulldummy}=\mathrm{true}\Rightarrow d=[\,]f.nulldummy=true⇒d=[]) and CsvPasses(f,o,1)\mathrm{CsvPasses}(f,o,1)CsvPasses(f,o,1).

ReceivedSpend(f,o,H,R,L,P,e,st)\mathrm{ReceivedSpend}(f,o,H,R,L,P,e,st)ReceivedSpend(f,o,H,R,L,P,e,st) is the disjunction of

  1. there are pk,σpk,\sigmapk,σ with st=[pk,σ]st=[pk,\sigma]st=[pk,σ], o.hash160(pk)=Ho.\mathrm{hash160}(pk)=Ho.hash160(pk)=H and o.checkSig(σ,pk)=some trueo.\mathrm{checkSig}(\sigma,pk)=\mathrm{some\ true}o.checkSig(σ,pk)=some true;
  2. there are x,σL,σR,dx,\sigma_L,\sigma_R,dx,σL​,σR​,d with st=[x,σL,σR,d]st=[x,\sigma_L,\sigma_R,d]st=[x,σL​,σR​,d], o.hash160(x)≠Ho.\mathrm{hash160}(x)\neq Ho.hash160(x)=H, ∣x∣=32|x|=32∣x∣=32, o.hash160(x)=Po.\mathrm{hash160}(x)=Po.hash160(x)=P, multisigLoop(o,[σL,σR],[L,R])=some true\mathrm{multisigLoop}(o,[\sigma_L,\sigma_R],[L,R])=\mathrm{some\ true}multisigLoop(o,[σL​,σR​],[L,R])=some true, (f.nulldummy=true⇒d=[ ]f.\mathrm{nulldummy}=\mathrm{true}\Rightarrow d=[\,]f.nulldummy=true⇒d=[]) and CsvPasses(f,o,1)\mathrm{CsvPasses}(f,o,1)CsvPasses(f,o,1);
  3. there are x,σx,\sigmax,σ with st=[x,σ]st=[x,\sigma]st=[x,σ], o.hash160(x)≠Ho.\mathrm{hash160}(x)\neq Ho.hash160(x)=H, ∣x∣≠32|x|\neq 32∣x∣=32, CltvPasses(f,o,e)\mathrm{CltvPasses}(f,o,e)CltvPasses(f,o,e), o.checkSig(σ,R)=some trueo.\mathrm{checkSig}(\sigma,R)=\mathrm{some\ true}o.checkSig(σ,R)=some true and CsvPasses(f,o,1)\mathrm{CsvPasses}(f,o,1)CsvPasses(f,o,1).
Human review
  • Endorsed by Shuze Chen · Oct 29, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 29, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me