Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The cheater's to_local spend needs version 2 and nSequence ≥ to_self_delay

Proved
BitcoinPenalty.cheater_delay_in_tx_terms

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

bitcoinbitcoin-mainnetbolt3bolt5channel-safetycsvformal-verificationlightningpenaltyrevocation

Under NoRevocationSig, the CSV flag and flag-free nSequence: any accepted spend has 2 ≤ version and toSelfDelay ≤ nSequence.

Preamble
import Definitions.Def_BitcoinPenalty
import Definitions.Def_BitcoinVerify
import Definitions.Def_BitcoinSer
import Definitions.Def_BitcoinToLocal
open BitcoinPenalty BitcoinToLocal BitcoinHtlc BitcoinAnchors BitcoinScript BitcoinSig BitcoinVerify
Formal statement
theorem BitcoinPenalty.cheater_delay_in_tx_terms (tap : BitcoinVerify.TaprootHandler) (c : BitcoinVerify.Ctx)
    (hf : c.flags.witness = true) (hcsv : c.flags.csv = true) (K : BitcoinPenalty.CommitmentKeys)
    (hK : BitcoinPenalty.WellFormed K)
    (hN : BitcoinPenalty.NoRevocationSig (BitcoinPenalty.oracleOf c (BitcoinPenalty.toLocalBytes K)) K)
    (ws : List BitcoinSer.Bytes)
    (hv : BitcoinVerify.verifyScript tap c [] (BitcoinPenalty.p2wshOf (BitcoinPenalty.toLocalBytes K))
      (ws ++ [BitcoinPenalty.toLocalBytes K]) = true)
    (hseq : BitcoinToLocal.inputSequence c.tx c.nIn < 2 ^ 16) :
    2 ≤ c.tx.version ∧ K.toSelfDelay.toNat ≤ BitcoinToLocal.inputSequence c.tx c.nIn := by sorry
Source
BOLT #3 (commitment transaction outputs, revocation) and BOLT #5 (penalty transactions): https://github.com/lightning/bolts/blob/master/03-transactions.md, https://github.com/lightning/bolts/blob/master/05-onchain.md#revoked-transaction-close-handling; Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: VerifyScript, EvalScript, CheckSequence, IsFinalTx (src/script/interpreter.cpp, src/consensus/tx_verify.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: BitcoinPenalty.cheater_delay_in_tx_terms

What the declaration literally asserts

For every Taproot handler taptaptap, every verification context ccc with c.flags.witness=truec.\mathrm{flags}.\mathrm{witness} = \mathrm{true}c.flags.witness=true and c.flags.csv=truec.\mathrm{flags}.\mathrm{csv} = \mathrm{true}c.flags.csv=true, every commitment-key record KKK with WellFormed(K)\mathrm{WellFormed}(K)WellFormed(K), every list of byte strings wswsws, under the hypotheses

  • NoRevocationSig(otoLocal,K)\mathrm{NoRevocationSig}(o_{\mathrm{toLocal}}, K)NoRevocationSig(otoLocal​,K) with otoLocal:=oracleOf(c,StoLocal(K))o_{\mathrm{toLocal}} := \mathrm{oracleOf}(c, \mathcal S_{\mathrm{toLocal}}(K))otoLocal​:=oracleOf(c,StoLocal​(K)): for every byte string sigsigsig, otoLocal.checkSig(sig,K.revPk)≠some trueo_{\mathrm{toLocal}}.\mathrm{checkSig}(sig, K.\mathrm{revPk}) \ne \mathrm{some\ true}otoLocal​.checkSig(sig,K.revPk)=some true;
  • V(StoLocal(K), ws+ ⁣ ⁣+[StoLocal(K)])=trueV\bigl(\mathcal S_{\mathrm{toLocal}}(K),\ ws \mathbin{+\!\!+} [\mathcal S_{\mathrm{toLocal}}(K)]\bigr) = \mathrm{true}V(StoLocal​(K), ws++[StoLocal​(K)])=true;
  • σ<216\sigma < 2^{16}σ<216, where σ=inputSequence(c.tx,c.nIn)\sigma = \mathrm{inputSequence}(c.tx, c.\mathrm{nIn})σ=inputSequence(c.tx,c.nIn) (sequence of input c.nInc.\mathrm{nIn}c.nIn, or 000 if out of range),

the conclusion is

2≤c.tx.version ∧ toNat(K.toSelfDelay)≤σ.2 \le c.tx.\mathrm{version} \ \land\ \mathrm{toNat}(K.\mathrm{toSelfDelay}) \le \sigma.2≤c.tx.version ∧ toNat(K.toSelfDelay)≤σ.

Notes on the binders and edge cases

  • The extra hypothesis σ<216\sigma < 2^{16}σ<216 bounds the sequence number of the spending input; under it the disable bit (2312^{31}231) and type flag (2222^{22}222) of σ\sigmaσ are necessarily clear, but the conclusion itself does not mention them.
  • toNat(K.toSelfDelay)=K.toSelfDelay\mathrm{toNat}(K.\mathrm{toSelfDelay}) = K.\mathrm{toSelfDelay}toNat(K.toSelfDelay)=K.toSelfDelay since WellFormed(K)\mathrm{WellFormed}(K)WellFormed(K) gives 0≤K.toSelfDelay<2160 \le K.\mathrm{toSelfDelay} < 2^{16}0≤K.toSelfDelay<216.
  • c.flags.csv=truec.\mathrm{flags}.\mathrm{csv} = \mathrm{true}c.flags.csv=true is assumed; the other flags apart from witness\mathrm{witness}witness are unconstrained; c.amountc.\mathrm{amount}c.amount, c.txc.txc.tx's other fields are unconstrained.
  • Vacuous when no wswsws passes verification under the hypotheses.

Shared setting and unfolded definitions

Everything below is the literal content of the definitions the statement uses, unfolded from the preamble files. It is identical across the read-backs of this bundle; nothing in it is specific to one theorem except where a theorem's own section says so.

Basic objects

  • A byte is an 8-bit word; a byte string (Bytes\mathrm{Bytes}Bytes) is a finite list of bytes. Byte strings are the only kind of value scripts push and keys, hashes, signatures, witness elements are all byte strings with no length or format constraint unless a hypothesis states one.
  • A transaction txtxtx has a version tx.version∈Ntx.\mathrm{version} \in \mathbb Ntx.version∈N, a list of inputs tx.vintx.\mathrm{vin}tx.vin (each input has a previous outpoint, a scriptSig\mathrm{scriptSig}scriptSig, a sequence number nSequence∈N\mathrm{nSequence} \in \mathbb NnSequence∈N and a witness stack), a list of outputs tx.vouttx.\mathrm{vout}tx.vout (each with an amount ∈Z\in \mathbb Z∈Z and an output script) and a lock time tx.nLockTime∈Ntx.\mathrm{nLockTime} \in \mathbb Ntx.nLockTime∈N. In these statements none of these fields is range-restricted: version, sequence numbers and lock time are arbitrary natural numbers (not bounded by 2322^{32}232) unless a hypothesis says otherwise.
  • A consensus flag set FFF consists of seven booleans: F.p2shF.\mathrm{p2sh}F.p2sh, F.witnessF.\mathrm{witness}F.witness, F.taprootF.\mathrm{taproot}F.taproot, F.dersigF.\mathrm{dersig}F.dersig, F.cltvF.\mathrm{cltv}F.cltv, F.csvF.\mathrm{csv}F.csv, F.nulldummyF.\mathrm{nulldummy}F.nulldummy. Every flag not fixed by a hypothesis is arbitrary (the statement is asserted for both values).
  • A verification context ccc is a quadruple: flags c.flagsc.\mathrm{flags}c.flags, a transaction c.txc.txc.tx, an input index c.nIn∈Nc.\mathrm{nIn} \in \mathbb Nc.nIn∈N (not required to be a valid index into c.tx.vinc.tx.\mathrm{vin}c.tx.vin unless a hypothesis says so) and an amount c.amount∈Zc.\mathrm{amount} \in \mathbb Zc.amount∈Z (may be negative).
  • A Taproot handler taptaptap is any function from (context, witness stack, 32-byte program) to booleans. It is universally quantified; in the unfolding below the version-0 witness branch never calls it, so the asserted statement is the same for every taptaptap.
  • f:=scriptFlagsOf(c.flags)f := \mathrm{scriptFlagsOf}(c.\mathrm{flags})f:=scriptFlagsOf(c.flags) is the interpreter flag triple (f.cltv,f.csv,f.nulldummy):=(c.flags.cltv, c.flags.csv, c.flags.nulldummy)(f.\mathrm{cltv}, f.\mathrm{csv}, f.\mathrm{nulldummy}) := (c.\mathrm{flags}.\mathrm{cltv},\ c.\mathrm{flags}.\mathrm{csv},\ c.\mathrm{flags}.\mathrm{nulldummy})(f.cltv,f.csv,f.nulldummy):=(c.flags.cltv, c.flags.csv, c.flags.nulldummy).
  • sigFlagsOf(c.flags):=(dersig=c.flags.dersig, lowS=false, strictenc=false, witnessPubkeyType=false)\mathrm{sigFlagsOf}(c.\mathrm{flags}) := (\mathrm{dersig} = c.\mathrm{flags}.\mathrm{dersig},\ \mathrm{lowS} = \mathrm{false},\ \mathrm{strictenc} = \mathrm{false},\ \mathrm{witnessPubkeyType} = \mathrm{false})sigFlagsOf(c.flags):=(dersig=c.flags.dersig, lowS=false, strictenc=false, witnessPubkeyType=false).
  • MAX_SCRIPT_ELEMENT_SIZE=520\mathrm{MAX\_SCRIPT\_ELEMENT\_SIZE} = 520MAX_SCRIPT_ELEMENT_SIZE=520, MAX_SCRIPT_SIZE=10000\mathrm{MAX\_SCRIPT\_SIZE} = 10000MAX_SCRIPT_SIZE=10000, 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.
  • SEQUENCE_LOCKTIME_DISABLE_FLAG=231=2147483648\mathrm{SEQUENCE\_LOCKTIME\_DISABLE\_FLAG} = 2^{31} = 2147483648SEQUENCE_LOCKTIME_DISABLE_FLAG=231=2147483648 (the same value is defined both in the script file and in the signature file; the theorems name the signature file's copy). LOCKTIME_THRESHOLD=500000000\mathrm{LOCKTIME\_THRESHOLD} = 500000000LOCKTIME_THRESHOLD=500000000. SEQUENCE_FINAL=232−1=0xffffffff\mathrm{SEQUENCE\_FINAL} = 2^{32}-1 = \mathtt{0xffffffff}SEQUENCE_FINAL=232−1=0xffffffff. SEQUENCE_LOCKTIME_TYPE_FLAG=222\mathrm{SEQUENCE\_LOCKTIME\_TYPE\_FLAG} = 2^{22}SEQUENCE_LOCKTIME_TYPE_FLAG=222, SEQUENCE_LOCKTIME_MASK=0xffff\mathrm{SEQUENCE\_LOCKTIME\_MASK} = \mathtt{0xffff}SEQUENCE_LOCKTIME_MASK=0xffff.

castToBool

For a byte string vvv, castToBool(v)=true\mathrm{castToBool}(v) = \mathrm{true}castToBool(v)=true iff some byte of vvv is nonzero, except that a string whose bytes are all zero apart from a last byte equal to 0x80\mathtt{0x80}0x80 ("negative zero") is false\mathrm{false}false. The empty string is false\mathrm{false}false. Hence for a 32-byte hash HHH, "castToBool(H)=true\mathrm{castToBool}(H) = \mathrm{true}castToBool(H)=true" means HHH is neither the all-zero string nor 313131 zero bytes followed by 0x80\mathtt{0x80}0x80.

Commitment keys and the size hypotheses

A CommitmentKeys record KKK has nine fields: byte strings K.revPkK.\mathrm{revPk}K.revPk, K.revHashK.\mathrm{revHash}K.revHash, K.localDelayedPkK.\mathrm{localDelayedPk}K.localDelayedPk, K.remoteKeyK.\mathrm{remoteKey}K.remoteKey, K.localHtlcKeyK.\mathrm{localHtlcKey}K.localHtlcKey, K.remoteHtlcKeyK.\mathrm{remoteHtlcKey}K.remoteHtlcKey, K.fundingKeyLocalK.\mathrm{fundingKeyLocal}K.fundingKeyLocal, K.fundingKeyRemoteK.\mathrm{fundingKeyRemote}K.fundingKeyRemote, and an integer K.toSelfDelay∈ZK.\mathrm{toSelfDelay} \in \mathbb ZK.toSelfDelay∈Z.

WellFormed(K)(K)(K) is the conjunction of ten facts: each of the eight byte-string fields has length ≤520\le 520≤520, and 0≤K.toSelfDelay<2160 \le K.\mathrm{toSelfDelay} < 2^{16}0≤K.toSelfDelay<216. Nothing else is required: the "keys" need not be valid public keys, K.revHashK.\mathrm{revHash}K.revHash need not be 20 bytes, and no relation between K.revHashK.\mathrm{revHash}K.revHash and K.revPkK.\mathrm{revPk}K.revPk is imposed here.

An Htlc record hhh has two fields: a byte string h.payHashh.\mathrm{payHash}h.payHash and an integer h.expiry∈Zh.\mathrm{expiry} \in \mathbb Zh.expiry∈Z. HtlcWellFormed(h)(h)(h) is: ∣h.payHash∣≤520|h.\mathrm{payHash}| \le 520∣h.payHash∣≤520 and ∣h.expiry∣<232|h.\mathrm{expiry}| < 2^{32}∣h.expiry∣<232 (absolute value; h.expiryh.\mathrm{expiry}h.expiry may be negative or zero).

Script serialization primitives

  • pushBytes(d)\mathrm{pushBytes}(d)pushBytes(d): if ∣d∣<76|d| < 76∣d∣<76, the byte ∣d∣|d|∣d∣ followed by ddd; if ∣d∣≤255|d| \le 255∣d∣≤255, 0x4c,∣d∣\mathtt{0x4c}, |d|0x4c,∣d∣ then ddd; if ∣d∣≤65535|d| \le 65535∣d∣≤65535, 0x4d\mathtt{0x4d}0x4d, two little-endian length bytes, then ddd; otherwise 0x4e\mathtt{0x4e}0x4e, four little-endian length bytes, then ddd. (For the empty string this is the single byte 0x00\mathtt{0x00}0x00.)
  • serialize(v)\mathrm{serialize}(v)serialize(v) for v∈Zv \in \mathbb Zv∈Z is the CScriptNum encoding: empty for 000; otherwise the little-endian magnitude bytes with the sign carried in bit 7 of the last byte (an extra byte 0x00\mathtt{0x00}0x00/0x80\mathtt{0x80}0x80 appended when the top bit of the magnitude is set).
  • numBytes(n)\mathrm{numBytes}(n)numBytes(n) for n∈Zn \in \mathbb Zn∈Z: if n=−1n = -1n=−1 or 1≤n≤161 \le n \le 161≤n≤16, the single opcode byte 0x50+n\mathtt{0x50} + n0x50+n (so 0x4f\mathtt{0x4f}0x4f for −1-1−1, 0x51\mathtt{0x51}0x51 = OP_1 for 111, 0x52\mathtt{0x52}0x52 = OP_2 for 222, 0x60\mathtt{0x60}0x60 = OP_16 for 161616); otherwise pushBytes(serialize(n))\mathrm{pushBytes}(\mathrm{serialize}(n))pushBytes(serialize(n)) (so 0x00\mathtt{0x00}0x00 for 000, and 0x01 0x20\mathtt{0x01}\,\mathtt{0x20}0x010x20 for 323232).

Opcode bytes used: OP_IF =0x63=\mathtt{0x63}=0x63, OP_NOTIF =0x64=\mathtt{0x64}=0x64, OP_ELSE =0x67=\mathtt{0x67}=0x67, OP_ENDIF =0x68=\mathtt{0x68}=0x68, OP_IFDUP =0x73=\mathtt{0x73}=0x73, OP_DROP =0x75=\mathtt{0x75}=0x75, OP_DUP =0x76=\mathtt{0x76}=0x76, OP_SWAP =0x7c=\mathtt{0x7c}=0x7c, OP_SIZE =0x82=\mathtt{0x82}=0x82, OP_EQUAL =0x87=\mathtt{0x87}=0x87, OP_EQUALVERIFY =0x88=\mathtt{0x88}=0x88, OP_HASH160 =0xa9=\mathtt{0xa9}=0xa9, OP_CHECKSIG =0xac=\mathtt{0xac}=0xac, OP_CHECKSIGVERIFY =0xad=\mathtt{0xad}=0xad, OP_CHECKMULTISIG =0xae=\mathtt{0xae}=0xae, OP_CHECKLOCKTIMEVERIFY =0xb1=\mathtt{0xb1}=0xb1, OP_CHECKSEQUENCEVERIFY =0xb2=\mathtt{0xb2}=0xb2.

The witness scripts (byte strings)

Writing ⟨d⟩\langle d \rangle⟨d⟩ for pushBytes(d)\mathrm{pushBytes}(d)pushBytes(d) and [n][n][n] for numBytes(n)\mathrm{numBytes}(n)numBytes(n):

  • StoLocal(K):=\mathcal S_{\mathrm{toLocal}}(K) := StoLocal​(K):= OP_IF ⟨K.revPk⟩\langle K.\mathrm{revPk}\rangle⟨K.revPk⟩ OP_ELSE [K.toSelfDelay][K.\mathrm{toSelfDelay}][K.toSelfDelay] OP_CHECKSEQUENCEVERIFY OP_DROP ⟨K.localDelayedPk⟩\langle K.\mathrm{localDelayedPk}\rangle⟨K.localDelayedPk⟩ OP_ENDIF OP_CHECKSIG.
  • Soff(K,h):=\mathcal S_{\mathrm{off}}(K,h) := Soff​(K,h):= OP_DUP OP_HASH160 ⟨K.revHash⟩\langle K.\mathrm{revHash}\rangle⟨K.revHash⟩ OP_EQUAL OP_IF OP_CHECKSIG OP_ELSE ⟨K.remoteHtlcKey⟩\langle K.\mathrm{remoteHtlcKey}\rangle⟨K.remoteHtlcKey⟩ OP_SWAP OP_SIZE [32][32][32] OP_EQUAL OP_NOTIF OP_DROP [2][2][2] OP_SWAP ⟨K.localHtlcKey⟩\langle K.\mathrm{localHtlcKey}\rangle⟨K.localHtlcKey⟩ [2][2][2] OP_CHECKMULTISIG OP_ELSE OP_HASH160 ⟨h.payHash⟩\langle h.\mathrm{payHash}\rangle⟨h.payHash⟩ OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF OP_ENDIF.
  • Srec(K,h):=\mathcal S_{\mathrm{rec}}(K,h) := Srec​(K,h):= OP_DUP OP_HASH160 ⟨K.revHash⟩\langle K.\mathrm{revHash}\rangle⟨K.revHash⟩ OP_EQUAL OP_IF OP_CHECKSIG OP_ELSE ⟨K.remoteHtlcKey⟩\langle K.\mathrm{remoteHtlcKey}\rangle⟨K.remoteHtlcKey⟩ OP_SWAP OP_SIZE [32][32][32] OP_EQUAL OP_IF OP_HASH160 ⟨h.payHash⟩\langle h.\mathrm{payHash}\rangle⟨h.payHash⟩ OP_EQUALVERIFY [2][2][2] OP_SWAP ⟨K.localHtlcKey⟩\langle K.\mathrm{localHtlcKey}\rangle⟨K.localHtlcKey⟩ [2][2][2] OP_CHECKMULTISIG OP_ELSE OP_DROP [h.expiry][h.\mathrm{expiry}][h.expiry] OP_CHECKLOCKTIMEVERIFY OP_DROP OP_CHECKSIG OP_ENDIF OP_ENDIF.
  • SoffA(K,h)\mathcal S_{\mathrm{offA}}(K,h)SoffA​(K,h) (anchors): as Soff(K,h)\mathcal S_{\mathrm{off}}(K,h)Soff​(K,h) but with [1][1][1] OP_CHECKSEQUENCEVERIFY OP_DROP inserted between the inner OP_ENDIF and the outer OP_ENDIF.
  • SrecA(K,h)\mathcal S_{\mathrm{recA}}(K,h)SrecA​(K,h) (anchors): as Srec(K,h)\mathcal S_{\mathrm{rec}}(K,h)Srec​(K,h) with the same insertion.
  • StoRemote(K):=⟨K.remoteKey⟩\mathcal S_{\mathrm{toRemote}}(K) := \langle K.\mathrm{remoteKey}\rangleStoRemote​(K):=⟨K.remoteKey⟩ OP_CHECKSIGVERIFY [1][1][1] OP_CHECKSEQUENCEVERIFY.
  • Sanchor(fk):=⟨fk⟩\mathcal S_{\mathrm{anchor}}(fk) := \langle fk\rangleSanchor​(fk):=⟨fk⟩ OP_CHECKSIG OP_IFDUP OP_NOTIF [16][16][16] OP_CHECKSEQUENCEVERIFY OP_ENDIF; SanchorLocal(K):=Sanchor(K.fundingKeyLocal)\mathcal S_{\mathrm{anchorLocal}}(K) := \mathcal S_{\mathrm{anchor}}(K.\mathrm{fundingKeyLocal})SanchorLocal​(K):=Sanchor​(K.fundingKeyLocal), SanchorRemote(K):=Sanchor(K.fundingKeyRemote)\mathcal S_{\mathrm{anchorRemote}}(K) := \mathcal S_{\mathrm{anchor}}(K.\mathrm{fundingKeyRemote})SanchorRemote​(K):=Sanchor​(K.fundingKeyRemote).

In the hash-and-key slots the scripts push whatever byte strings KKK and hhh hold; the file does not compute K.revHashK.\mathrm{revHash}K.revHash or h.payHashh.\mathrm{payHash}h.payHash from anything.

p2wshOf

p2wshOf(S):=witnessBytes(0,sha256(S))=0x00 ∥ pushBytes(sha256(S))=0x00 0x20 ∥ sha256(S)\mathrm{p2wshOf}(\mathcal S) := \mathrm{witnessBytes}(0, \mathrm{sha256}(\mathcal S)) = \mathtt{0x00} \,\Vert\, \mathrm{pushBytes}(\mathrm{sha256}(\mathcal S)) = \mathtt{0x00}\,\mathtt{0x20}\,\Vert\,\mathrm{sha256}(\mathcal S)p2wshOf(S):=witnessBytes(0,sha256(S))=0x00∥pushBytes(sha256(S))=0x000x20∥sha256(S), a 34-byte output script, where sha256\mathrm{sha256}sha256 is the concrete SHA-256 of the serialization file (a transcription of crypto/sha256.cpp).

oracleOf — the concrete oracle

oS:=oracleOf(c,S):=legacyOracle(sigFlagsOf(c.flags), c.tx, c.nIn, c.amount, witnessV0, S)o_{\mathcal S} := \mathrm{oracleOf}(c, \mathcal S) := \mathrm{legacyOracle}(\mathrm{sigFlagsOf}(c.\mathrm{flags}),\ c.tx,\ c.\mathrm{nIn},\ c.\mathrm{amount},\ \mathrm{witnessV0},\ \mathcal S)oS​:=oracleOf(c,S):=legacyOracle(sigFlagsOf(c.flags), c.tx, c.nIn, c.amount, witnessV0, S). Its eight components are concrete:

  • oS.sha256o_{\mathcal S}.\mathrm{sha256}oS​.sha256, oS.ripemd160o_{\mathcal S}.\mathrm{ripemd160}oS​.ripemd160, oS.sha1o_{\mathcal S}.\mathrm{sha1}oS​.sha1, oS.hash256=sha256∘sha256o_{\mathcal S}.\mathrm{hash256} = \mathrm{sha256}\circ\mathrm{sha256}oS​.hash256=sha256∘sha256 and oS.hash160=ripemd160∘sha256o_{\mathcal S}.\mathrm{hash160} = \mathrm{ripemd160}\circ\mathrm{sha256}oS​.hash160=ripemd160∘sha256 are the transcribed hash functions of the serialization file (so "oS.hash160(x)o_{\mathcal S}.\mathrm{hash160}(x)oS​.hash160(x)" is the concrete RIPEMD160(SHA256(x))\mathrm{RIPEMD160}(\mathrm{SHA256}(x))RIPEMD160(SHA256(x)), independent of S\mathcal SS and ccc).
  • oS.checkSig(sig,pk):=checkSigPreTapscript(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,witnessV0,S,sig,pk)∈{none,some true,some false}o_{\mathcal S}.\mathrm{checkSig}(sig, pk) := \mathrm{checkSigPreTapscript}(\mathrm{sigFlagsOf}(c.\mathrm{flags}), c.tx, c.\mathrm{nIn}, c.\mathrm{amount}, \mathrm{witnessV0}, \mathcal S, sig, pk) \in \{\mathrm{none}, \mathrm{some\ true}, \mathrm{some\ false}\}oS​.checkSig(sig,pk):=checkSigPreTapscript(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,witnessV0,S,sig,pk)∈{none,some true,some false}, which is:
    • none\mathrm{none}none (script failure) iff the encoding check fails. With the signature flags above (only dersig\mathrm{dersig}dersig possibly on), the public-key encoding check always passes, and the signature encoding check fails exactly when c.flags.dersig=truec.\mathrm{flags}.\mathrm{dersig} = \mathrm{true}c.flags.dersig=true, sig≠[]sig \ne []sig=[] and sigsigsig is not a strict-DER encoding (IsValidSignatureEncoding: length between 9 and 73, the 30 len 02 |r| r 02 |s| s hashtype layout with the checks of that function). An empty sigsigsig always passes the encoding check.
    • otherwise some(checkECDSASignature(c.tx,c.nIn,c.amount,witnessV0,sig,pk,S))\mathrm{some}(\mathrm{checkECDSASignature}(c.tx, c.\mathrm{nIn}, c.\mathrm{amount}, \mathrm{witnessV0}, sig, pk, \mathcal S))some(checkECDSASignature(c.tx,c.nIn,c.amount,witnessV0,sig,pk,S)), which is true\mathrm{true}true iff: pkpkpk is non-empty and its first byte announces its length (first byte 222 or 333 and ∣pk∣=33|pk| = 33∣pk∣=33, or first byte 444, 666 or 777 and ∣pk∣=65|pk| = 65∣pk∣=65); sigsigsig is non-empty, its last byte hththt being the hash type; c.amount≥0c.\mathrm{amount} \ge 0c.amount≥0; and CPubKey::Verify succeeds on pkpkpk, the BIP143 signature hash sigHashWitnessV0(S,c.tx,c.nIn,ht,c.amount)\mathrm{sigHashWitnessV0}(\mathcal S, c.tx, c.\mathrm{nIn}, ht, c.\mathrm{amount})sigHashWitnessV0(S,c.tx,c.nIn,ht,c.amount) (a double-SHA256 of version, hashPrevouts, hashSequence, the outpoint of input c.nInc.\mathrm{nIn}c.nIn — the default empty input if c.nInc.\mathrm{nIn}c.nIn is out of range —, the length-prefixed S\mathcal SS, the amount, the input's sequence, hashOutputs, lock time and hash type) and sigsigsig without its last byte: the key parses as a secp256k1 point, the signature parses under the lax DER parser, its sss is normalized to low-sss, and the ECDSA verification equation holds with the message reduced modulo the group order. (No FindAndDelete is applied in the witness-v0 case.)
  • oS.checkLockTime(L):=checkLockTime(c.tx,c.nIn,L)o_{\mathcal S}.\mathrm{checkLockTime}(L) := \mathrm{checkLockTime}(c.tx, c.\mathrm{nIn}, L)oS​.checkLockTime(L):=checkLockTime(c.tx,c.nIn,L) for L∈ZL \in \mathbb ZL∈Z: true\mathrm{true}true iff c.tx.nLockTimec.tx.\mathrm{nLockTime}c.tx.nLockTime and LLL are on the same side of 500000000500000000500000000 (both below, or both ≥\ge≥), L≤c.tx.nLockTimeL \le c.tx.\mathrm{nLockTime}L≤c.tx.nLockTime, and the sequence number of input c.nInc.\mathrm{nIn}c.nIn (see σ\sigmaσ below) is ≠0xffffffff\ne \mathtt{0xffffffff}=0xffffffff.
  • oS.checkSequence(S):=checkSequence(c.tx,c.nIn,S)o_{\mathcal S}.\mathrm{checkSequence}(S) := \mathrm{checkSequence}(c.tx, c.\mathrm{nIn}, S)oS​.checkSequence(S):=checkSequence(c.tx,c.nIn,S) for S∈ZS \in \mathbb ZS∈Z: with σ\sigmaσ the sequence number of input c.nInc.\mathrm{nIn}c.nIn, true\mathrm{true}true iff c.tx.version≥2c.tx.\mathrm{version} \ge 2c.tx.version≥2, σ&231=0\sigma \mathbin{\&} 2^{31} = 0σ&231=0, and, with m:=222∣0xffffm := 2^{22} \mathbin{|} \mathtt{0xffff}m:=222∣0xffff, σm:=σ&m\sigma_m := \sigma \mathbin{\&} mσm​:=σ&m and Sm:=(max⁡(S,0))&mS_m := (\max(S,0)) \mathbin{\&} mSm​:=(max(S,0))&m: σm\sigma_mσm​ and SmS_mSm​ are either both <222< 2^{22}<222 or both ≥222\ge 2^{22}≥222, and Sm≤σmS_m \le \sigma_mSm​≤σm​.

inputSequence

σ:=inputSequence(c.tx,c.nIn)\sigma := \mathrm{inputSequence}(c.tx, c.\mathrm{nIn})σ:=inputSequence(c.tx,c.nIn) is the nSequence\mathrm{nSequence}nSequence field of the input at index c.nInc.\mathrm{nIn}c.nIn of c.txc.txc.tx; if c.nIn≥∣c.tx.vin∣c.\mathrm{nIn} \ge |c.tx.\mathrm{vin}|c.nIn≥∣c.tx.vin∣ it is the sequence of the default input, i.e. σ=0\sigma = 0σ=0. The same getD default is used inside checkLockTime\mathrm{checkLockTime}checkLockTime, checkSequence\mathrm{checkSequence}checkSequence and the BIP143 hash.

CsvPasses and CltvPasses

CsvPasses(f,o,d)  ⟺  f.csv=false ∨ (0≤d ∧ ((max⁡(d,0))&231≠0 ∨ o.checkSequence(d)=true)).\mathrm{CsvPasses}(f, o, d) \iff f.\mathrm{csv} = \mathrm{false} \ \lor\ \bigl(0 \le d \ \land\ ((\max(d,0)) \mathbin{\&} 2^{31} \ne 0 \ \lor\ o.\mathrm{checkSequence}(d) = \mathrm{true})\bigr).CsvPasses(f,o,d)⟺f.csv=false ∨ (0≤d ∧ ((max(d,0))&231=0 ∨ o.checkSequence(d)=true)). CltvPasses(f,o,e)  ⟺  f.cltv=false ∨ (0≤e ∧ o.checkLockTime(e)=true).\mathrm{CltvPasses}(f, o, e) \iff f.\mathrm{cltv} = \mathrm{false} \ \lor\ \bigl(0 \le e \ \land\ o.\mathrm{checkLockTime}(e) = \mathrm{true}\bigr).CltvPasses(f,o,e)⟺f.cltv=false ∨ (0≤e ∧ o.checkLockTime(e)=true).

With o=oSo = o_{\mathcal S}o=oS​ these are the concrete checks above on c.txc.txc.tx and c.nInc.\mathrm{nIn}c.nIn.

isFinalTx

isFinalTx(tx,height,blockTime)\mathrm{isFinalTx}(tx, \mathrm{height}, \mathrm{blockTime})isFinalTx(tx,height,blockTime) for height∈N\mathrm{height} \in \mathbb Nheight∈N, blockTime∈Z\mathrm{blockTime} \in \mathbb ZblockTime∈Z is true\mathrm{true}true iff: tx.nLockTime=0tx.\mathrm{nLockTime} = 0tx.nLockTime=0; or tx.nLockTime<heighttx.\mathrm{nLockTime} < \mathrm{height}tx.nLockTime<height when tx.nLockTime<500000000tx.\mathrm{nLockTime} < 500000000tx.nLockTime<500000000, resp. tx.nLockTime<blockTimetx.\mathrm{nLockTime} < \mathrm{blockTime}tx.nLockTime<blockTime when tx.nLockTime≥500000000tx.\mathrm{nLockTime} \ge 500000000tx.nLockTime≥500000000; or every input of txtxtx has nSequence=0xffffffff\mathrm{nSequence} = \mathtt{0xffffffff}nSequence=0xffffffff (vacuously true when txtxtx has no inputs).

verifyScript on a P2WSH output with an empty scriptSig

For a witness script S\mathcal SS and a witness list www (in CScriptWitness order: the last element is on top of the stack), write

V(S,w):  ⟺  verifyScript(tap,c,[ ],p2wshOf(S),w)=true.V(\mathcal S, w) :\iff \mathrm{verifyScript}(tap, c, [\,], \mathrm{p2wshOf}(\mathcal S), w) = \mathrm{true}.V(S,w):⟺verifyScript(tap,c,[],p2wshOf(S),w)=true.

Unfolding verifyScript with the empty scriptSig and the 34-byte output script 00 20 ∥ sha256(S)\mathtt{00}\,\mathtt{20}\,\Vert\,\mathrm{sha256}(\mathcal S)0020∥sha256(S):

  1. The empty scriptSig evaluates to the empty stack; the output script evaluates (as a legacy script) to the one-element stack [sha256(S)][\mathrm{sha256}(\mathcal S)][sha256(S)]; the top must be true: castToBool(sha256(S))=true\mathrm{castToBool}(\mathrm{sha256}(\mathcal S)) = \mathrm{true}castToBool(sha256(S))=true is required.
  2. If c.flags.witness=truec.\mathrm{flags}.\mathrm{witness} = \mathrm{true}c.flags.witness=true (all theorems assume this), the output script is recognised as a witness program of version 000 with program sha256(S)\mathrm{sha256}(\mathcal S)sha256(S) (32 bytes); the scriptSig is empty as required; the P2SH flag and the P2SH branch are then irrelevant.
  3. Version 0 with a 32-byte program: www must be non-empty; its last element S′\mathcal S'S′ must satisfy sha256(S′)=sha256(S)\mathrm{sha256}(\mathcal S') = \mathrm{sha256}(\mathcal S)sha256(S′)=sha256(S); then executeWitnessScriptV0 runs on the stack reverse(w without its last element)\mathrm{reverse}(w \text{ without its last element})reverse(w without its last element) and the script S′\mathcal S'S′. For w=ws+ ⁣ ⁣+[S]w = ws \mathbin{+\!\!+} [\mathcal S]w=ws++[S] this stack is reverse(ws)\mathrm{reverse}(ws)reverse(ws) and the script is S\mathcal SS itself.
  4. executeWitnessScriptV0: every stack element has length ≤520\le 520≤520; ∣S∣≤10000|\mathcal S| \le 10000∣S∣≤10000; S\mathcal SS parses instruction by instruction (GetOp); the Script-mission interpreter evalScript runs with flags f=scriptFlagsOf(c.flags)f = \mathrm{scriptFlagsOf}(c.\mathrm{flags})f=scriptFlagsOf(c.flags) and oracle oS=oracleOf(c,S)o_{\mathcal S} = \mathrm{oracleOf}(c, \mathcal S)oS​=oracleOf(c,S) on that stack (with the usual limits: pushes ≤520\le 520≤520 bytes, stack plus altstack ≤1000\le 1000≤1000, at most 201201201 counted opcodes, balanced conditionals, disabled opcodes rejected); it must succeed, leaving exactly one element, and castToBool\mathrm{castToBool}castToBool of that element must be true\mathrm{true}true.

The Taproot handler taptaptap is not consulted on this path. So V(S,ws+ ⁣ ⁣+[S])V(\mathcal S, ws \mathbin{+\!\!+} [\mathcal S])V(S,ws++[S]) is a decidable boolean fact about ccc, KKK, hhh and wswsws only.

Interpreter facts used by the unfoldings

  • OP_CHECKSIG pops pkpkpk (top) and sigsigsig, calls o.checkSig(sig,pk)o.\mathrm{checkSig}(sig, pk)o.checkSig(sig,pk): none\mathrm{none}none fails the script; some b\mathrm{some}\ bsome b pushes [0x01][\mathtt{0x01}][0x01] if bbb else the empty string. OP_CHECKSIGVERIFY fails instead of pushing false\mathrm{false}false.
  • OP_CHECKSEQUENCEVERIFY with f.csv=falsef.\mathrm{csv} = \mathrm{false}f.csv=false does nothing; otherwise it reads the top element as a script number of at most 5 bytes nnn (without popping), fails if n<0n < 0n<0, passes if n&231≠0n \mathbin{\&} 2^{31} \ne 0n&231=0, else fails unless o.checkSequence(n)=trueo.\mathrm{checkSequence}(n) = \mathrm{true}o.checkSequence(n)=true. OP_CHECKLOCKTIMEVERIFY likewise with f.cltvf.\mathrm{cltv}f.cltv, no disable bit, and o.checkLockTimeo.\mathrm{checkLockTime}o.checkLockTime.
  • OP_CHECKMULTISIG with [2] ⟨k1⟩ ⟨k2⟩ [2][2]\ \langle k_1\rangle\ \langle k_2\rangle\ [2][2] ⟨k1​⟩ ⟨k2​⟩ [2] uses the matching loop multisigLoop(o,[s1,s2],[k1,k2])\mathrm{multisigLoop}(o, [s_1, s_2], [k_1, k_2])multisigLoop(o,[s1​,s2​],[k1​,k2​]) and then pops one extra "dummy" element, failing if f.nulldummy=truef.\mathrm{nulldummy} = \mathrm{true}f.nulldummy=true and the dummy is non-empty.
  • multisigLoop(o,sigs,keys)\mathrm{multisigLoop}(o, \mathrm{sigs}, \mathrm{keys})multisigLoop(o,sigs,keys): with no signatures left, some true\mathrm{some\ true}some true; with signatures but no keys, some false\mathrm{some\ false}some false; otherwise it checks the first signature against the first key: none\mathrm{none}none propagates as none\mathrm{none}none; on true\mathrm{true}true it drops both and continues (failing with some false\mathrm{some\ false}some false if fewer keys than signatures remain); on false\mathrm{false}false it drops only the key and continues (same count check). Instantiated on two signatures and two keys, multisigLoop(o,[s1,s2],[k1,k2])=some true\mathrm{multisigLoop}(o, [s_1, s_2], [k_1, k_2]) = \mathrm{some\ true}multisigLoop(o,[s1​,s2​],[k1​,k2​])=some true iff o.checkSig(s1,k1)=some trueo.\mathrm{checkSig}(s_1, k_1) = \mathrm{some\ true}o.checkSig(s1​,k1​)=some true and o.checkSig(s2,k2)=some trueo.\mathrm{checkSig}(s_2, k_2) = \mathrm{some\ true}o.checkSig(s2​,k2​)=some true.

The two sides of the penalty (predicates on an oracle ooo and KKK)

HoldsRevocation(o,K):  ⟺  (∃ sigR, ∣sigR∣≤520 ∧ o.checkSig(sigR,K.revPk)=some true) ∧ o.hash160(K.revPk)=K.revHash.\mathrm{HoldsRevocation}(o, K) :\iff \bigl(\exists\, sig_R,\ |sig_R| \le 520 \ \land\ o.\mathrm{checkSig}(sig_R, K.\mathrm{revPk}) = \mathrm{some\ true}\bigr) \ \land\ o.\mathrm{hash160}(K.\mathrm{revPk}) = K.\mathrm{revHash}.HoldsRevocation(o,K):⟺(∃sigR​, ∣sigR​∣≤520 ∧ o.checkSig(sigR​,K.revPk)=some true) ∧ o.hash160(K.revPk)=K.revHash. NoRevocationSig(o,K):  ⟺  ∀ sig, o.checkSig(sig,K.revPk)≠some true\mathrm{NoRevocationSig}(o, K) :\iff \forall\, sig,\ o.\mathrm{checkSig}(sig, K.\mathrm{revPk}) \ne \mathrm{some\ true}NoRevocationSig(o,K):⟺∀sig, o.checkSig(sig,K.revPk)=some true

(for every byte string sigsigsig the oracle's answer is none\mathrm{none}none or some false\mathrm{some\ false}some false).

NoRevHashPreimage(o,K):  ⟺  ∀ pk, o.hash160(pk)=K.revHash⇒pk=K.revPk.\mathrm{NoRevHashPreimage}(o, K) :\iff \forall\, pk,\ o.\mathrm{hash160}(pk) = K.\mathrm{revHash} \Rightarrow pk = K.\mathrm{revPk}.NoRevHashPreimage(o,K):⟺∀pk, o.hash160(pk)=K.revHash⇒pk=K.revPk.

When o=oS=oracleOf(c,S)o = o_{\mathcal S} = \mathrm{oracleOf}(c, \mathcal S)o=oS​=oracleOf(c,S), o.hash160o.\mathrm{hash160}o.hash160 is the concrete RIPEMD160∘SHA256\mathrm{RIPEMD160}\circ\mathrm{SHA256}RIPEMD160∘SHA256 and o.checkSigo.\mathrm{checkSig}o.checkSig is the concrete BIP143 ECDSA check on c.txc.txc.tx, c.nInc.\mathrm{nIn}c.nIn, c.amountc.\mathrm{amount}c.amount with script code S\mathcal SS described above. So NoRevHashPreimage(oS,K)\mathrm{NoRevHashPreimage}(o_{\mathcal S}, K)NoRevHashPreimage(oS​,K) asserts that K.revPkK.\mathrm{revPk}K.revPk is the only byte string in the whole of Bytes\mathrm{Bytes}Bytes whose concrete hash160 is K.revHashK.\mathrm{revHash}K.revHash (it does not by itself assert that K.revPkK.\mathrm{revPk}K.revPk hashes to K.revHashK.\mathrm{revHash}K.revHash); and NoRevocationSig(oS,K)\mathrm{NoRevocationSig}(o_{\mathcal S}, K)NoRevocationSig(oS​,K) asserts that no byte string whatsoever passes the concrete signature check for K.revPkK.\mathrm{revPk}K.revPk on this transaction, input, amount and script code.

The penalty witnesses (CScriptWitness order, script last)

  • toLocalPenaltyWitness(K,sigR):=[ sigR, [0x01], StoLocal(K) ]\mathrm{toLocalPenaltyWitness}(K, sig_R) := [\,sig_R,\ [\mathtt{0x01}],\ \mathcal S_{\mathrm{toLocal}}(K)\,]toLocalPenaltyWitness(K,sigR​):=[sigR​, [0x01], StoLocal​(K)]; the executed stack (top first) is [[0x01],sigR][[\mathtt{0x01}], sig_R][[0x01],sigR​].
  • htlcPenaltyWitness(K,sigR,S):=[ sigR, K.revPk, S ]\mathrm{htlcPenaltyWitness}(K, sig_R, \mathcal S) := [\,sig_R,\ K.\mathrm{revPk},\ \mathcal S\,]htlcPenaltyWitness(K,sigR​,S):=[sigR​, K.revPk, S]; the executed stack (top first) is [K.revPk,sigR][K.\mathrm{revPk}, sig_R][K.revPk,sigR​].

The cheater-path predicates (on flags fff, oracle ooo, keys KKK, HTLC hhh, and a top-first stack ststst)

DelayedSpend(f,o,K,b,sig):  ⟺  castToBool(b)=false ∧ CsvPasses(f,o,K.toSelfDelay) ∧ o.checkSig(sig,K.localDelayedPk)=some true.\mathrm{DelayedSpend}(f, o, K, b, sig) :\iff \mathrm{castToBool}(b) = \mathrm{false} \ \land\ \mathrm{CsvPasses}(f, o, K.\mathrm{toSelfDelay}) \ \land\ o.\mathrm{checkSig}(sig, K.\mathrm{localDelayedPk}) = \mathrm{some\ true}.DelayedSpend(f,o,K,b,sig):⟺castToBool(b)=false ∧ CsvPasses(f,o,K.toSelfDelay) ∧ o.checkSig(sig,K.localDelayedPk)=some true.

OfferedNonRevocation(f,o,K,h,st)\mathrm{OfferedNonRevocation}(f, o, K, h, st)OfferedNonRevocation(f,o,K,h,st) is the disjunction of:

  • (preimage path) ∃ pre,sig: st=[pre,sig]∧o.hash160(pre)≠K.revHash∧∣pre∣=32∧o.hash160(pre)=h.payHash∧o.checkSig(sig,K.remoteHtlcKey)=some true\exists\, \mathrm{pre}, sig:\ st = [\mathrm{pre}, sig] \land o.\mathrm{hash160}(\mathrm{pre}) \ne K.\mathrm{revHash} \land |\mathrm{pre}| = 32 \land o.\mathrm{hash160}(\mathrm{pre}) = h.\mathrm{payHash} \land o.\mathrm{checkSig}(sig, K.\mathrm{remoteHtlcKey}) = \mathrm{some\ true}∃pre,sig: st=[pre,sig]∧o.hash160(pre)=K.revHash∧∣pre∣=32∧o.hash160(pre)=h.payHash∧o.checkSig(sig,K.remoteHtlcKey)=some true;
  • (timeout path) ∃ x,sigL,sigR′,dummy: st=[x,sigL,sigR′,dummy]∧o.hash160(x)≠K.revHash∧∣x∣≠32∧multisigLoop(o,[sigL,sigR′],[K.localHtlcKey,K.remoteHtlcKey])=some true∧(f.nulldummy=true⇒dummy=[ ])\exists\, x, sig_L, sig_R', \mathrm{dummy}:\ st = [x, sig_L, sig_R', \mathrm{dummy}] \land o.\mathrm{hash160}(x) \ne K.\mathrm{revHash} \land |x| \ne 32 \land \mathrm{multisigLoop}(o, [sig_L, sig_R'], [K.\mathrm{localHtlcKey}, K.\mathrm{remoteHtlcKey}]) = \mathrm{some\ true} \land (f.\mathrm{nulldummy} = \mathrm{true} \Rightarrow \mathrm{dummy} = [\,])∃x,sigL​,sigR′​,dummy: st=[x,sigL​,sigR′​,dummy]∧o.hash160(x)=K.revHash∧∣x∣=32∧multisigLoop(o,[sigL​,sigR′​],[K.localHtlcKey,K.remoteHtlcKey])=some true∧(f.nulldummy=true⇒dummy=[]).

ReceivedNonRevocation(f,o,K,h,st)\mathrm{ReceivedNonRevocation}(f, o, K, h, st)ReceivedNonRevocation(f,o,K,h,st) is the disjunction of:

  • (success path) ∃ pre,sigL,sigR′,dummy: st=[pre,sigL,sigR′,dummy]∧o.hash160(pre)≠K.revHash∧∣pre∣=32∧o.hash160(pre)=h.payHash∧multisigLoop(o,[sigL,sigR′],[K.localHtlcKey,K.remoteHtlcKey])=some true∧(f.nulldummy=true⇒dummy=[ ])\exists\, \mathrm{pre}, sig_L, sig_R', \mathrm{dummy}:\ st = [\mathrm{pre}, sig_L, sig_R', \mathrm{dummy}] \land o.\mathrm{hash160}(\mathrm{pre}) \ne K.\mathrm{revHash} \land |\mathrm{pre}| = 32 \land o.\mathrm{hash160}(\mathrm{pre}) = h.\mathrm{payHash} \land \mathrm{multisigLoop}(o, [sig_L, sig_R'], [K.\mathrm{localHtlcKey}, K.\mathrm{remoteHtlcKey}]) = \mathrm{some\ true} \land (f.\mathrm{nulldummy} = \mathrm{true} \Rightarrow \mathrm{dummy} = [\,])∃pre,sigL​,sigR′​,dummy: st=[pre,sigL​,sigR′​,dummy]∧o.hash160(pre)=K.revHash∧∣pre∣=32∧o.hash160(pre)=h.payHash∧multisigLoop(o,[sigL​,sigR′​],[K.localHtlcKey,K.remoteHtlcKey])=some true∧(f.nulldummy=true⇒dummy=[]);
  • (timeout path) ∃ x,sig: st=[x,sig]∧o.hash160(x)≠K.revHash∧∣x∣≠32∧CltvPasses(f,o,h.expiry)∧o.checkSig(sig,K.remoteHtlcKey)=some true\exists\, x, sig:\ st = [x, sig] \land o.\mathrm{hash160}(x) \ne K.\mathrm{revHash} \land |x| \ne 32 \land \mathrm{CltvPasses}(f, o, h.\mathrm{expiry}) \land o.\mathrm{checkSig}(sig, K.\mathrm{remoteHtlcKey}) = \mathrm{some\ true}∃x,sig: st=[x,sig]∧o.hash160(x)=K.revHash∧∣x∣=32∧CltvPasses(f,o,h.expiry)∧o.checkSig(sig,K.remoteHtlcKey)=some true.

OfferedNonRevocationAnchors(f,o,K,h,st):  ⟺  OfferedNonRevocation(f,o,K,h,st)∧CsvPasses(f,o,1)\mathrm{OfferedNonRevocationAnchors}(f, o, K, h, st) :\iff \mathrm{OfferedNonRevocation}(f, o, K, h, st) \land \mathrm{CsvPasses}(f, o, 1)OfferedNonRevocationAnchors(f,o,K,h,st):⟺OfferedNonRevocation(f,o,K,h,st)∧CsvPasses(f,o,1), and ReceivedNonRevocationAnchors(f,o,K,h,st):  ⟺  ReceivedNonRevocation(f,o,K,h,st)∧CsvPasses(f,o,1)\mathrm{ReceivedNonRevocationAnchors}(f, o, K, h, st) :\iff \mathrm{ReceivedNonRevocation}(f, o, K, h, st) \land \mathrm{CsvPasses}(f, o, 1)ReceivedNonRevocationAnchors(f,o,K,h,st):⟺ReceivedNonRevocation(f,o,K,h,st)∧CsvPasses(f,o,1).

In these predicates the stack ststst is top-first; in the theorems it is instantiated with reverse(ws)\mathrm{reverse}(ws)reverse(ws), i.e. the last element of the witness list wswsws is the first element of ststst.

Human review
  • Endorsed by Shuze Chen · Oct 30, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 30, 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