Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A received HTLC cannot be timed out before its expiry at the consensus level

Proved
BitcoinHtlcLocks.received_spend_height

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

bip65bitcoinbitcoin-mainnetbolt3consensusfinalityformal-verificationhtlclightninglocktime

For a context ccc with the WITNESS and CHECKLOCKTIMEVERIFY flags, keys and hashes of at most 520 bytes, 0<expiry<500,000,0000 < {\rm expiry} < 500{,}000{,}0000<expiry<500,000,000, and ccc's input index in range: if verifyScript accepts the two-element witness [sig, pk] for the pay-to-witness-script-hash output of receivedBytes revHash remoteKey localKey payHash expiry, and ccc's transaction is final at height (isFinalTx c.tx height blockTime = true, which ContextualCheckBlock requires of every transaction in a block at that height), then either RevocationSpend c (receivedBytes …) revHash pk sig, or expiry < height. The HTLC mission's script conditions and the block mission's finality rule compose: besides the revocation key, the only two-element witness is the timeout path, whose OP_CHECKLOCKTIMEVERIFY forces nLockTime ≥ expiry and a non-final input, and finality then forces nLockTime < height.

Preamble
import Definitions.Def_BitcoinHtlcLocks
import Definitions.Def_BitcoinVerify
import Definitions.Def_BitcoinSer
import Definitions.Def_BitcoinScript
import Definitions.Def_BitcoinHtlc
open BitcoinHtlcLocks BitcoinVerify BitcoinHtlc
open BitcoinScript hiding Bytes Byte
Formal statement
theorem BitcoinHtlcLocks.received_spend_height (tap : BitcoinVerify.TaprootHandler) (c : BitcoinVerify.Ctx)
    (hf : c.flags.witness = true) (hcltv : c.flags.cltv = true)
    (revHash remoteKey localKey payHash : BitcoinSer.Bytes) (expiry : Int) (sig pk : BitcoinSer.Bytes)
    (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)
    (hexp : 0 < expiry ∧ expiry < BitcoinBlockV2.LOCKTIME_THRESHOLD) (hnIn : c.nIn < c.tx.vin.length)
    (hv : BitcoinVerify.verifyScript tap c []
        (BitcoinVerify.witnessBytes 0 (BitcoinSer.sha256 (BitcoinHtlc.receivedBytes revHash remoteKey localKey payHash expiry)))
        ([sig, pk] ++ [BitcoinHtlc.receivedBytes revHash remoteKey localKey payHash expiry]) = true)
    (height : Nat) (blockTime : Int) (hfinal : BitcoinBlockV2.isFinalTx c.tx height blockTime = true) :
    BitcoinHtlcLocks.RevocationSpend c (BitcoinHtlc.receivedBytes revHash remoteKey localKey payHash expiry) revHash pk sig ∨
      expiry < height := by sorry
Source
BOLT #3, HTLC-Timeout and HTLC-Success Transactions (locktime = cltv_expiry), Received HTLC Outputs: https://github.com/lightning/bolts/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions; Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: IsFinalTx (src/consensus/tx_verify.cpp) as the block mission's `isFinalTx`, ContextualCheckBlock (src/validation.cpp), GenericTransactionSignatureChecker::CheckLockTime (src/script/interpreter.cpp); BIP65
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: BitcoinHtlcLocks.received_spend_height

Declaration shape. A theorem universally quantified over a Taproot handler, a verification context, four byte strings, an integer expiry, two further byte strings, a height and a block time, with eleven hypotheses; the conclusion is a disjunction of a "revocation spend" proposition and a strict integer inequality.

Objects involved

Byte strings. A byte is an 8-bit vector; a byte string is a finite list of bytes. Lengths are natural numbers.

Transactions. A transaction txtxtx has a version ∈N\in \mathbb{N}∈N, a list of inputs vin(tx)\mathrm{vin}(tx)vin(tx), a list of outputs vout(tx)\mathrm{vout}(tx)vout(tx) and a lock time nLockTime(tx)∈N\mathrm{nLockTime}(tx) \in \mathbb{N}nLockTime(tx)∈N. An input has a previous outpoint (byte string, index), a scriptSig byte string, a sequence number nSequence∈N\mathrm{nSequence} \in \mathbb{N}nSequence∈N and a witness stack (list of byte strings). "The kkk-th input of txtxtx with default" is the zero-based kkk-th input when k<∣vin(tx)∣k < |\mathrm{vin}(tx)|k<∣vin(tx)∣, else the default input with outpoint (empty, 000), empty scriptSig, nSequence=0\mathrm{nSequence} = 0nSequence=0, empty witness.

Consensus flag set. A record FFF of seven Booleans: F.p2sh,F.witness,F.taproot,F.dersig,F.cltv,F.csv,F.nulldummyF.\mathrm{p2sh}, F.\mathrm{witness}, F.\mathrm{taproot}, F.\mathrm{dersig}, F.\mathrm{cltv}, F.\mathrm{csv}, F.\mathrm{nulldummy}F.p2sh,F.witness,F.taproot,F.dersig,F.cltv,F.csv,F.nulldummy. Two projections:

  • interpreter flags scriptFlagsOf(F)=(F.cltv,F.csv,F.nulldummy)\mathrm{scriptFlagsOf}(F) = (F.\mathrm{cltv}, F.\mathrm{csv}, F.\mathrm{nulldummy})scriptFlagsOf(F)=(F.cltv,F.csv,F.nulldummy);
  • signature flags sigFlagsOf(F)=(dersig=F.dersig, lowS=false, strictenc=false, witnessPubkeyType=false)\mathrm{sigFlagsOf}(F) = (\mathrm{dersig} = F.\mathrm{dersig},\ \mathrm{lowS} = \mathbf{false},\ \mathrm{strictenc} = \mathbf{false},\ \mathrm{witnessPubkeyType} = \mathbf{false})sigFlagsOf(F)=(dersig=F.dersig, lowS=false, strictenc=false, witnessPubkeyType=false).

Verification context. ccc is a record (c.flags,c.tx,c.nIn,c.amount)(c.\mathrm{flags}, c.\mathrm{tx}, c.\mathrm{nIn}, c.\mathrm{amount})(c.flags,c.tx,c.nIn,c.amount): a flag set, a transaction, an input index ∈N\in \mathbb{N}∈N and an amount ∈Z\in \mathbb{Z}∈Z (the statement places no sign constraint on the amount).

Taproot handler. tap\mathit{tap}tap is an arbitrary function from (context, list of byte strings, byte string) to Booleans. It is unconstrained by any hypothesis.

Constants. LOCKTIME_THRESHOLD=500 000 000\mathrm{LOCKTIME\_THRESHOLD} = 500\,000\,000LOCKTIME_THRESHOLD=500000000; SEQUENCE_FINAL=0xffffffff\mathrm{SEQUENCE\_FINAL} = \mathtt{0xffffffff}SEQUENCE_FINAL=0xffffffff; MAX_SCRIPT_ELEMENT_SIZE=520\mathrm{MAX\_SCRIPT\_ELEMENT\_SIZE} = 520MAX_SCRIPT_ELEMENT_SIZE=520; MAX_SCRIPT_SIZE=10 000\mathrm{MAX\_SCRIPT\_SIZE} = 10\,000MAX_SCRIPT_SIZE=10000.

Hashes. sha256\mathrm{sha256}sha256 is a concrete SHA-256 implementation on byte strings (32-byte output); hash160(m)=ripemd160(sha256(m))\mathrm{hash160}(m) = \mathrm{ripemd160}(\mathrm{sha256}(m))hash160(m)=ripemd160(sha256(m)) with a concrete RIPEMD-160.

The received-HTLC script bytes SSS

Write push(d)\mathrm{push}(d)push(d) for the canonical push of byte string ddd: if ∣d∣<76|d| < 76∣d∣<76 it is the single length byte followed by ddd; if ∣d∣≤255|d| \le 255∣d∣≤255 it is 0x4c\mathtt{0x4c}0x4c, one length byte, ddd; if ∣d∣≤65535|d| \le 65535∣d∣≤65535 it is 0x4d\mathtt{0x4d}0x4d, two little-endian length bytes, ddd; otherwise 0x4e\mathtt{0x4e}0x4e, four little-endian length bytes, ddd.

Write num(n)\mathrm{num}(n)num(n) for n∈Zn \in \mathbb{Z}n∈Z: if n=−1n = -1n=−1 or 1≤n≤161 \le n \le 161≤n≤16, the single byte 0x50+n\mathtt{0x50} + n0x50+n (so num(2)=[0x52]\mathrm{num}(2) = [\mathtt{0x52}]num(2)=[0x52]); otherwise push(ser(n))\mathrm{push}(\mathrm{ser}(n))push(ser(n)) where ser\mathrm{ser}ser is the script-number encoding (empty for 000; otherwise the minimal little-endian magnitude bytes, with an extra sign byte 0x80\mathtt{0x80}0x80/0x00\mathtt{0x00}0x00 appended if the top bit of the last magnitude byte is set, else the sign folded into that top bit). In particular num(32)=[0x01,0x20]\mathrm{num}(32) = [\mathtt{0x01}, \mathtt{0x20}]num(32)=[0x01,0x20].

Then, for byte strings rrr (revHash), KrK_rKr​ (remoteKey), KlK_lKl​ (localKey), ppp (payHash) and integer eee (expiry),

S=receivedBytes(r,Kr,Kl,p,e)=[0x76,0xa9]+ ⁣ ⁣+push(r)+ ⁣ ⁣+[0x87,0x63,0xac,0x67]+ ⁣ ⁣+push(Kr)+ ⁣ ⁣+[0x7c,0x82]+ ⁣ ⁣+num(32)+ ⁣ ⁣+[0x87,0x63,0xa9]+ ⁣ ⁣+push(p)+ ⁣ ⁣+[0x88]+ ⁣ ⁣+num(2)+ ⁣ ⁣+[0x7c]+ ⁣ ⁣+push(Kl)+ ⁣ ⁣+num(2)+ ⁣ ⁣+[0xae,0x67,0x75]+ ⁣ ⁣+num(e)+ ⁣ ⁣+[0xb1,0x75,0xac,0x68,0x68].\begin{aligned} S = \mathrm{receivedBytes}(r, K_r, K_l, p, e) ={}& [\mathtt{0x76}, \mathtt{0xa9}] \mathbin{+\!\!+} \mathrm{push}(r) \mathbin{+\!\!+} [\mathtt{0x87}, \mathtt{0x63}, \mathtt{0xac}, \mathtt{0x67}] \mathbin{+\!\!+} \mathrm{push}(K_r) \mathbin{+\!\!+} [\mathtt{0x7c}, \mathtt{0x82}] \mathbin{+\!\!+} \mathrm{num}(32) \\ &\mathbin{+\!\!+} [\mathtt{0x87}, \mathtt{0x63}, \mathtt{0xa9}] \mathbin{+\!\!+} \mathrm{push}(p) \mathbin{+\!\!+} [\mathtt{0x88}] \mathbin{+\!\!+} \mathrm{num}(2) \mathbin{+\!\!+} [\mathtt{0x7c}] \mathbin{+\!\!+} \mathrm{push}(K_l) \mathbin{+\!\!+} \mathrm{num}(2) \\ &\mathbin{+\!\!+} [\mathtt{0xae}, \mathtt{0x67}, \mathtt{0x75}] \mathbin{+\!\!+} \mathrm{num}(e) \mathbin{+\!\!+} [\mathtt{0xb1}, \mathtt{0x75}, \mathtt{0xac}, \mathtt{0x68}, \mathtt{0x68}] . \end{aligned}S=receivedBytes(r,Kr​,Kl​,p,e)=​[0x76,0xa9]++push(r)++[0x87,0x63,0xac,0x67]++push(Kr​)++[0x7c,0x82]++num(32)++[0x87,0x63,0xa9]++push(p)++[0x88]++num(2)++[0x7c]++push(Kl​)++num(2)++[0xae,0x67,0x75]++num(e)++[0xb1,0x75,0xac,0x68,0x68].​

(The opcode bytes are: 0x76 DUP, 0xa9 HASH160, 0x87 EQUAL, 0x63 IF, 0xac CHECKSIG, 0x67 ELSE, 0x7c SWAP, 0x82 SIZE, 0x88 EQUALVERIFY, 0xae CHECKMULTISIG, 0x75 DROP, 0xb1 CHECKLOCKTIMEVERIFY, 0x68 ENDIF.) The parsed-instruction form receivedScript is not used by this statement; only the byte form SSS is.

The output script and the witness

witnessBytes(0,P)=[0x00]+ ⁣ ⁣+push(P)\mathrm{witnessBytes}(0, P) = [\mathtt{0x00}] \mathbin{+\!\!+} \mathrm{push}(P)witnessBytes(0,P)=[0x00]++push(P). With P=sha256(S)P = \mathrm{sha256}(S)P=sha256(S) (32 bytes) this is the 34-byte string 0x00 0x20 P\mathtt{0x00}\ \mathtt{0x20}\ P0x00 0x20 P.

The witness list is [sig,pk]+ ⁣ ⁣+[S]=[sig,pk,S][\mathit{sig}, \mathit{pk}] \mathbin{+\!\!+} [S] = [\mathit{sig}, \mathit{pk}, S][sig,pk]++[S]=[sig,pk,S], in "last element on top" order.

The verification predicate verifyScript(tap,c,σ,π,w)\mathrm{verifyScript}(\mathit{tap}, c, \sigma, \pi, w)verifyScript(tap,c,σ,π,w)

With scriptSig σ\sigmaσ, scriptPubKey π\piπ and witness list www, the Boolean is computed as follows. Let evalBytes(c,v,st,s)\mathrm{evalBytes}(c, v, st, s)evalBytes(c,v,st,s) be: failure if 10 000<∣s∣10\,000 < |s|10000<∣s∣; failure if sss does not parse into instructions; otherwise the result of running the parsed script on top-first stack ststst under interpreter flags scriptFlagsOf(c.flags)\mathrm{scriptFlagsOf}(c.\mathrm{flags})scriptFlagsOf(c.flags) and the legacy oracle for signature version vvv and script code sss, which supplies the concrete hashes, checkSig(sg,k)=checkSigPreTapscript(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,v,s,sg,k)\mathrm{checkSig}(\mathit{sg}, \mathit{k}) = \mathrm{checkSigPreTapscript}(\mathrm{sigFlagsOf}(c.\mathrm{flags}), c.\mathrm{tx}, c.\mathrm{nIn}, c.\mathrm{amount}, v, s, \mathit{sg}, \mathit{k})checkSig(sg,k)=checkSigPreTapscript(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,v,s,sg,k), checkLockTime=checkLockTime(c.tx,c.nIn,⋅)\mathrm{checkLockTime} = \mathrm{checkLockTime}(c.\mathrm{tx}, c.\mathrm{nIn}, \cdot)checkLockTime=checkLockTime(c.tx,c.nIn,⋅) and checkSequence=checkSequence(c.tx,c.nIn,⋅)\mathrm{checkSequence} = \mathrm{checkSequence}(c.\mathrm{tx}, c.\mathrm{nIn}, \cdot)checkSequence=checkSequence(c.tx,c.nIn,⋅). A stack's top is "true" (topTrue\mathrm{topTrue}topTrue) when the stack is non-empty and its top element is non-zero in the script sense: a byte string is true unless it is empty or every byte is 0x00\mathtt{0x00}0x00 except possibly a final 0x80\mathtt{0x80}0x80.

  1. Run σ\sigmaσ (base version) on the empty stack; failure gives false; call the result stσst_\sigmastσ​.
  2. Run π\piπ (base version) on stσst_\sigmastσ​; failure gives false; if the top is not true, false.
  3. If c.flags.witnessc.\mathrm{flags}.\mathrm{witness}c.flags.witness holds and π\piπ is a witness program (length between 4 and 42, first byte either 0x00\mathtt{0x00}0x00 or in 0x51\mathtt{0x51}0x51..0x60\mathtt{0x60}0x60, and second byte +2+ 2+2 equal to the length; the version is 000 for first byte 0x00\mathtt{0x00}0x00 else first byte −0x50- \mathtt{0x50}−0x50, the program is the bytes after the second): if σ≠[]\sigma \neq []σ=[] the answer is false; otherwise the answer is verifyWitnessProgram(tap,c,w,version,program,false)\mathrm{verifyWitnessProgram}(\mathit{tap}, c, w, \mathrm{version}, \mathrm{program}, \mathbf{false})verifyWitnessProgram(tap,c,w,version,program,false).
  4. Otherwise (witness flag off, or π\piπ not a witness program) a pay-to-script-hash branch is tried when c.flags.p2shc.\mathrm{flags}.\mathrm{p2sh}c.flags.p2sh holds and π\piπ is the 23-byte pattern 0xa9 0x14 ⟨20 bytes⟩ 0x87\mathtt{0xa9}\ \mathtt{0x14}\ \langle 20 \text{ bytes}\rangle\ \mathtt{0x87}0xa9 0x14 ⟨20 bytes⟩ 0x87; failing that, the answer is false if the witness flag is on and www is non-empty, else true.

Here π=0x00 0x20 P\pi = \mathtt{0x00}\ \mathtt{0x20}\ Pπ=0x00 0x20 P has length 34, first byte 0x00\mathtt{0x00}0x00, second byte 32=34−232 = 34 - 232=34−2, so step 3 applies with version 000 and program PPP, and σ=[]\sigma = []σ=[], so the hypothesis reduces to verifyWitnessProgram(tap,c,[sig,pk,S],0,P,false)=true\mathrm{verifyWitnessProgram}(\mathit{tap}, c, [\mathit{sig}, \mathit{pk}, S], 0, P, \mathbf{false}) = \mathbf{true}verifyWitnessProgram(tap,c,[sig,pk,S],0,P,false)=true provided steps 1–2 pass (running the empty script, then running "push 32 bytes" and testing the pushed PPP for truth).

verifyWitnessProgram\mathrm{verifyWitnessProgram}verifyWitnessProgram with version 000 and a 32-byte program: take the last witness element (SSS); if sha256\mathrm{sha256}sha256 of it differs from the program, false (here the program is sha256(S)\mathrm{sha256}(S)sha256(S) itself); otherwise executeWitnessScriptV0(c,reverse of the remaining elements,S)\mathrm{executeWitnessScriptV0}(c, \text{reverse of the remaining elements}, S)executeWitnessScriptV0(c,reverse of the remaining elements,S), i.e. with top-first stack [pk,sig][\mathit{pk}, \mathit{sig}][pk,sig] (pk\mathit{pk}pk on top). That is: false if some stack element exceeds 520520520 bytes; else evalBytes(c,witnessV0,[pk,sig],S)\mathrm{evalBytes}(c, \mathrm{witnessV0}, [\mathit{pk}, \mathit{sig}], S)evalBytes(c,witnessV0,[pk,sig],S) must succeed with a stack of exactly one element whose value is true. (So the 10 000-byte bound and the parsability of SSS, and the 520-byte bounds on pk\mathit{pk}pk and sig\mathit{sig}sig, are enforced inside the hypothesis, not by separate hypotheses.) The Taproot handler tap\mathit{tap}tap would only be consulted for version 1 programs and is not reached on this path.

The lock-time checker used by CHECKLOCKTIMEVERIFY. checkLockTime(tx,k,L)\mathrm{checkLockTime}(tx, k, L)checkLockTime(tx,k,L) for L∈ZL \in \mathbb{Z}L∈Z is false unless either (nLockTime(tx)<500 000 000\mathrm{nLockTime}(tx) < 500\,000\,000nLockTime(tx)<500000000 and L<500 000 000L < 500\,000\,000L<500000000) or (500 000 000≤nLockTime(tx)500\,000\,000 \le \mathrm{nLockTime}(tx)500000000≤nLockTime(tx) and 500 000 000≤L500\,000\,000 \le L500000000≤L); then false if nLockTime(tx)<L\mathrm{nLockTime}(tx) < LnLockTime(tx)<L (integer comparison with the lock time cast); then false if the kkk-th input of txtxtx (with default) has nSequence=0xffffffff\mathrm{nSequence} = \mathtt{0xffffffff}nSequence=0xffffffff; else true. Whether the interpreter calls it at all is governed by the cltv\mathrm{cltv}cltv interpreter flag, which hypothesis (hcltv) sets to true.

The revocation-spend proposition

RevocationSpend(c,S,r,pk,sig)\mathrm{RevocationSpend}(c, S, r, \mathit{pk}, \mathit{sig})RevocationSpend(c,S,r,pk,sig) is the conjunction

hash160(pk)=r  ∧  checkSigPreTapscript(sigFlagsOf(c.flags), c.tx, c.nIn, c.amount, witnessV0, S, sig, pk)=some true.\mathrm{hash160}(\mathit{pk}) = r \;\wedge\; \mathrm{checkSigPreTapscript}\big(\mathrm{sigFlagsOf}(c.\mathrm{flags}),\ c.\mathrm{tx},\ c.\mathrm{nIn},\ c.\mathrm{amount},\ \mathrm{witnessV0},\ S,\ \mathit{sig},\ \mathit{pk}\big) = \mathrm{some}\ \mathbf{true} .hash160(pk)=r∧checkSigPreTapscript(sigFlagsOf(c.flags), c.tx, c.nIn, c.amount, witnessV0, S, sig, pk)=some true.

checkSigPreTapscript\mathrm{checkSigPreTapscript}checkSigPreTapscript with version witnessV0\mathrm{witnessV0}witnessV0 uses the script code SSS unchanged (no find-and-delete). It returns no value (hence not some true\mathrm{some}\ \mathbf{true}some true) if the signature-encoding check fails or the public-key-encoding check fails, and otherwise some\mathrm{some}some of the ECDSA verdict. With signature flags (F.dersig,false,false,false)(F.\mathrm{dersig}, \mathbf{false}, \mathbf{false}, \mathbf{false})(F.dersig,false,false,false): the signature-encoding check passes for an empty sig\mathit{sig}sig, fails when F.dersigF.\mathrm{dersig}F.dersig holds and sig\mathit{sig}sig is not a valid DER encoding, and passes otherwise; the public-key-encoding check always passes (both relevant flags are off). The ECDSA verdict checkECDSASignature(c.tx,c.nIn,c.amount,witnessV0,sig,pk,S)\mathrm{checkECDSASignature}(c.\mathrm{tx}, c.\mathrm{nIn}, c.\mathrm{amount}, \mathrm{witnessV0}, \mathit{sig}, \mathit{pk}, S)checkECDSASignature(c.tx,c.nIn,c.amount,witnessV0,sig,pk,S) is false if pk\mathit{pk}pk is not a valid public key; false if sig\mathit{sig}sig is empty; otherwise, with the last byte of sig\mathit{sig}sig as hash type and the rest as the raw signature, false if c.amount<0c.\mathrm{amount} < 0c.amount<0, else the outcome of verifying the raw signature with pk\mathit{pk}pk against the witness-v0 signature hash of (S,c.tx,c.nIn,hash type,c.amount)(S, c.\mathrm{tx}, c.\mathrm{nIn}, \text{hash type}, c.\mathrm{amount})(S,c.tx,c.nIn,hash type,c.amount).

Statement

For every Taproot handler tap\mathit{tap}tap, every context ccc, every byte strings r,Kr,Kl,pr, K_r, K_l, pr,Kr​,Kl​,p, every integer eee, every byte strings sig,pk\mathit{sig}, \mathit{pk}sig,pk, every h∈Nh \in \mathbb{N}h∈N (height) and t∈Zt \in \mathbb{Z}t∈Z (blockTime), assuming

  • (hf) c.flags.witness=truec.\mathrm{flags}.\mathrm{witness} = \mathbf{true}c.flags.witness=true;
  • (hcltv) c.flags.cltv=truec.\mathrm{flags}.\mathrm{cltv} = \mathbf{true}c.flags.cltv=true;
  • (hrev) ∣r∣≤520|r| \le 520∣r∣≤520; (hrem) ∣Kr∣≤520|K_r| \le 520∣Kr​∣≤520; (hloc) ∣Kl∣≤520|K_l| \le 520∣Kl​∣≤520; (hpay) ∣p∣≤520|p| \le 520∣p∣≤520;
  • (hexp) 0<e0 < e0<e and e<500 000 000e < 500\,000\,000e<500000000 (integer comparisons; the constant is cast from N\mathbb{N}N);
  • (hnIn) c.nIn<∣vin(c.tx)∣c.\mathrm{nIn} < |\mathrm{vin}(c.\mathrm{tx})|c.nIn<∣vin(c.tx)∣;
  • (hv) verifyScript(tap,c,[], witnessBytes(0,sha256(S)), [sig,pk,S])=true\mathrm{verifyScript}\big(\mathit{tap}, c, [],\ \mathrm{witnessBytes}(0, \mathrm{sha256}(S)),\ [\mathit{sig}, \mathit{pk}, S]\big) = \mathbf{true}verifyScript(tap,c,[], witnessBytes(0,sha256(S)), [sig,pk,S])=true with S=receivedBytes(r,Kr,Kl,p,e)S = \mathrm{receivedBytes}(r, K_r, K_l, p, e)S=receivedBytes(r,Kr​,Kl​,p,e);
  • (hfinal) isFinalTx(c.tx,h,t)=true\mathrm{isFinalTx}(c.\mathrm{tx}, h, t) = \mathbf{true}isFinalTx(c.tx,h,t)=true, where isFinalTx\mathrm{isFinalTx}isFinalTx is: true if nLockTime(c.tx)=0\mathrm{nLockTime}(c.\mathrm{tx}) = 0nLockTime(c.tx)=0; else true if nLockTime(c.tx)\mathrm{nLockTime}(c.\mathrm{tx})nLockTime(c.tx) (cast to Z\mathbb{Z}Z) is strictly less than hhh (cast to Z\mathbb{Z}Z) when nLockTime(c.tx)<500 000 000\mathrm{nLockTime}(c.\mathrm{tx}) < 500\,000\,000nLockTime(c.tx)<500000000, or strictly less than ttt otherwise; else true exactly when every input of c.txc.\mathrm{tx}c.tx has nSequence=0xffffffff\mathrm{nSequence} = \mathtt{0xffffffff}nSequence=0xffffffff;

the conclusion is

RevocationSpend(c,S,r,pk,sig)    ∨    e<h,\mathrm{RevocationSpend}(c, S, r, \mathit{pk}, \mathit{sig}) \;\;\vee\;\; e < h ,RevocationSpend(c,S,r,pk,sig)∨e<h,

where the inequality compares the integer eee with the natural number hhh cast to Z\mathbb{Z}Z.

Edge cases made explicit

  • No hypothesis fixes ∣r∣|r|∣r∣ or ∣p∣|p|∣p∣ to 20 bytes, or ∣Kr∣,∣Kl∣|K_r|, |K_l|∣Kr​∣,∣Kl​∣ to 33 bytes; they are bounded only above by 520. No hypothesis bounds ∣sig∣|\mathit{sig}|∣sig∣ or ∣pk∣|\mathit{pk}|∣pk∣ directly; the 520-byte bound on them is enforced only inside (hv).
  • c.flags.p2shc.\mathrm{flags}.\mathrm{p2sh}c.flags.p2sh, taproot\mathrm{taproot}taproot, dersig\mathrm{dersig}dersig, csv\mathrm{csv}csv, nulldummy\mathrm{nulldummy}nulldummy are unconstrained; c.amountc.\mathrm{amount}c.amount may be negative (in which case the ECDSA verdict is false, so the first disjunct cannot hold through a verified signature).
  • nLockTime(c.tx)\mathrm{nLockTime}(c.\mathrm{tx})nLockTime(c.tx) is unconstrained by the hypotheses: it may be 000 (then (hfinal) holds automatically), below the threshold (compared with hhh), or at/above it (compared with ttt, in which case hhh is not consulted by (hfinal)). ttt is otherwise unused.
  • (hnIn) guarantees the c.nInc.\mathrm{nIn}c.nIn-th input exists, so the default input never arises in checkLockTime\mathrm{checkLockTime}checkLockTime or checkSequence\mathrm{checkSequence}checkSequence; the sequence number of that input is not constrained by any hypothesis.
  • hhh may be 000. The disjunction is inclusive: both disjuncts may hold.
  • (hexp) is on the integer eee; the conclusion's e<he < he<h is also an integer comparison. num(e)\mathrm{num}(e)num(e) in SSS is a one-byte opcode when 1≤e≤161 \le e \le 161≤e≤16 and a script-number push otherwise.
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