Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

SequenceLocks is the BIP68 specification

Proved
BitcoinBlock.sequenceLocks_iff

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

bip30bip34bitcoinbitcoin-mainnetblock-validationconnectblockconsensusformal-verificationundo

sequenceLocksOk u height mtp ltf tx = true iff the BIP68 mission's satisfiesBIP68 holds for the transaction's version, the lock-time flags, the context (height, median times) and the inputs' sequences and coin heights — with no admissibility hypothesis, through the published fold_acceptance.

Deprecated. Superseded by BitcoinBlockV2.sequenceLocks_iff (revision 2 of the block mission): the p2shSigOpCount of this revision counted every push of scriptSig instead of only the redeem script, over-counting P2SH sigops; the V2 declarations carry the corrected definition.

Preamble
import Definitions.Def_BitcoinBlock
import Definitions.Def_BitcoinSer
Formal statement
theorem BitcoinBlock.sequenceLocks_iff (u : Ledger) (height : Nat) (mtp : Nat → Nat) (ltf : Nat) (tx : BitcoinSer.Tx) :
    BitcoinBlock.sequenceLocksOk u height mtp ltf tx = true ↔
      BitcoinBIP68.satisfiesBIP68 (BitVec.ofNat 32 tx.version) (BitVec.ofNat 32 ltf) ⟨height, mtp⟩
        (tx.vin.map fun i => ⟨BitVec.ofNat 32 i.nSequence, (BitcoinBlock.accessCoin u i.prevout).height⟩) := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: AcceptBlockHeader, CheckBlockHeader, ContextualCheckBlockHeader, CheckBlock, CheckMerkleRoot, CheckWitnessMalleation, ContextualCheckBlock, ConnectBlock, GetBlockScriptFlags, IsBIP30Repeat, IsBIP30Unspendable, UpdateCoins, DisconnectBlock, ApplyTxInUndo, src/validation.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp; CheckTransaction (consensus/tx_check.cpp); IsFinalTx, GetLegacySigOpCount, GetP2SHSigOpCount, GetTransactionSigOpCost, CheckTxInputs (consensus/tx_verify.cpp); CScript::GetSigOpCount, IsUnspendable (script/script.cpp, script.h); CountWitnessSigOps (script/interpreter.cpp); AddCoin, SpendCoin, AddCoins (coins.cpp); GetBlockProof (chain.cpp); GetWitnessCommitmentIndex, GetBlockWeight (consensus/validation.h); CMainParams (kernel/chainparams.cpp)
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: BitcoinBlock.sequenceLocks_iff

Binders

  • uuu : a ledger (association list from outpoints to coins ⟨out,height,isCoinbase⟩\langle\mathrm{out}, \mathrm{height}, \mathrm{isCoinbase}\rangle⟨out,height,isCoinbase⟩).
  • height∈N\mathit{height} \in \mathbb{N}height∈N.
  • mtp:N→N\mathit{mtp} : \mathbb{N} \to \mathbb{N}mtp:N→N : an arbitrary function (median time past by height).
  • ltf∈N\mathit{ltf} \in \mathbb{N}ltf∈N : the lock-time flags word.
  • txtxtx : a serialized transaction (version ∈N\in\mathbb{N}∈N, inputs with sequence ∈N\in \mathbb{N}∈N and prevout, outputs, lock time).

There are no hypotheses.

Conclusion

sequenceLocksOk(u,height,mtp,ltf,tx)=true  ⟺  satisfiesBIP68(V,F,⟨height,mtp⟩,I),\mathrm{sequenceLocksOk}(u, \mathit{height}, \mathit{mtp}, \mathit{ltf}, tx) = \mathrm{true} \iff \mathrm{satisfiesBIP68}\big(V, F, \langle\mathit{height}, \mathit{mtp}\rangle, I\big),sequenceLocksOk(u,height,mtp,ltf,tx)=true⟺satisfiesBIP68(V,F,⟨height,mtp⟩,I),

where V=tx.version mod 232V = tx.\mathrm{version} \bmod 2^{32}V=tx.versionmod232, F=ltf mod 232F = \mathit{ltf} \bmod 2^{32}F=ltfmod232 (both as 32-bit words), and III is the list, in input order, of pairs ⟨i.nSequence mod 232, accessCoin(u,i.prevout).height⟩\langle i.\mathrm{nSequence} \bmod 2^{32},\ \mathrm{accessCoin}(u, i.\mathrm{prevout}).\mathrm{height}\rangle⟨i.nSequencemod232, accessCoin(u,i.prevout).height⟩; accessCoin\mathrm{accessCoin}accessCoin returns the coin of the first ledger entry with that key, or the dummy coin (height 000, value −1-1−1) if there is none.

Left side, unfolded

sequenceLocksOk\mathrm{sequenceLocksOk}sequenceLocksOk is sequenceLocks(V,F,⟨height,mtp⟩,I)\mathrm{sequenceLocks}(V, F, \langle\mathit{height},\mathit{mtp}\rangle, I)sequenceLocks(V,F,⟨height,mtp⟩,I) from the BIP68 core transcription: compute an accumulator ⟨minHeight,minTime,heightsRev⟩\langle \mathit{minHeight}, \mathit{minTime}, \mathit{heightsRev}\rangle⟨minHeight,minTime,heightsRev⟩ starting at ⟨−1,−1,[ ]⟩\langle -1, -1, [\,]\rangle⟨−1,−1,[]⟩ (integers):

  • if 2≤V2 \le V2≤V and bit 000 of FFF is set ("enabled"), fold over III: for an input with sequence sss and coin height ccc: if bit 313131 of sss is set, nothing changes (height 000 is recorded); else if bit 222222 of sss is set, minTime:=max⁡(minTime, mtp(c−1)+((s & 0xffff)≪9)−1)\mathit{minTime} := \max(\mathit{minTime},\ \mathit{mtp}(c - 1) + ((s \,\&\, 0xffff) \ll 9) - 1)minTime:=max(minTime, mtp(c−1)+((s&0xffff)≪9)−1) (natural subtraction in c−1c-1c−1; the shift is inside 32 bits, so it equals 512⋅(s mod 216)512\cdot(s \bmod 2^{16})512⋅(smod216)); else minHeight:=max⁡(minHeight, c+(s & 0xffff)−1)\mathit{minHeight} := \max(\mathit{minHeight},\ c + (s \,\&\, 0xffff) - 1)minHeight:=max(minHeight, c+(s&0xffff)−1);
  • if not enabled, the accumulator stays ⟨−1,−1,⋅⟩\langle -1, -1, \cdot\rangle⟨−1,−1,⋅⟩.

Then the result is minHeight<height∧minTime<mtp(height−1)\mathit{minHeight} < \mathit{height} \wedge \mathit{minTime} < \mathit{mtp}(\mathit{height} - 1)minHeight<height∧minTime<mtp(height−1) (integers; natural subtraction in height−1\mathit{height}-1height−1).

Right side, unfolded

satisfiesBIP68(V,F,ctx,I)\mathrm{satisfiesBIP68}(V,F,\mathit{ctx},I)satisfiesBIP68(V,F,ctx,I) is the proposition: ¬ specEnabled(V,F)\neg\,\mathrm{specEnabled}(V,F)¬specEnabled(V,F), or every input ⟨s,c⟩∈I\langle s, c\rangle \in I⟨s,c⟩∈I is satisfied, where specEnabled(V,F)\mathrm{specEnabled}(V,F)specEnabled(V,F) is 2≤V∧F mod 2=12 \le V \wedge F \bmod 2 = 12≤V∧Fmod2=1, and an input is satisfied when ⌊s/231⌋=1\lfloor s / 2^{31}\rfloor = 1⌊s/231⌋=1 (disabled), or — if ⌊s/222⌋\lfloor s/2^{22}\rfloor⌊s/222⌋ is odd (time-based) — mtp(c−1)+512⋅(s mod 216)≤mtp(height−1)\mathit{mtp}(c-1) + 512\cdot(s \bmod 2^{16}) \le \mathit{mtp}(\mathit{height}-1)mtp(c−1)+512⋅(smod216)≤mtp(height−1), otherwise c+(s mod 216)≤heightc + (s \bmod 2^{16}) \le \mathit{height}c+(smod216)≤height (all in N\mathbb{N}N with natural subtraction in c−1c-1c−1 and height−1\mathit{height}-1height−1).

Edge cases silently included

No admissibility or overflow hypotheses from the BIP68 model are assumed (height\mathit{height}height may be 000, coin heights may exceed height\mathit{height}height, mtp\mathit{mtp}mtp may be anything); height=0\mathit{height} = 0height=0 makes height−1=0\mathit{height}-1 = 0height−1=0 and minHeight<0\mathit{minHeight} < 0minHeight<0 false when enabled with a non-disabled input; empty tx.vintx.\mathrm{vin}tx.vin (left: −1<height-1 < \mathit{height}−1<height and −1<mtp(⋅)-1 < \mathit{mtp}(\cdot)−1<mtp(⋅), true; right: vacuous); missing coins give height 000 (so c−1=0c - 1 = 0c−1=0); tx.versiontx.\mathrm{version}tx.version, ltf\mathit{ltf}ltf and sequences are unbounded naturals truncated to 32 bits.

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

    Confirmed by the moderator at approval.

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