Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Sequence-lock calculation preserves exactly the relevant heights

Proved
BitcoinBIP68.height_vector

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

bip68bitcoinbitcoin-mainnetconsensusformal-verification

For any unsigned 32-bit version and flags, any context, and any finite input list I=[(si,ci)]I=[(s_i,c_i)]I=[(si​,ci​)], let EEE mean that version is at least two and flags bit zero is set. After calculation, the returned height list has the original length and order and satisfies

hi′={0,E and sequence bit 31 is set,ci,otherwise.h_i'=\begin{cases}0,&E\text{ and sequence bit 31 is set},\\c_i,&\text{otherwise}.\end{cases}hi′​={0,ci​,​E and sequence bit 31 is set,otherwise.​

This is equality of ordered lists, including repeated entries. If enforcement is off, every input height is unchanged even when its sequence-disable bit is set. The theorem imposes no admissibility or no-overflow assumption on the mathematical model and includes the empty list. It records the height-vector side effect separately from acceptance.

Preamble
import Definitions.Def_BIP68_Model
import Definitions.Def_BIP68_Core
Formal statement
theorem BitcoinBIP68.height_vector (version flags : BitVec 32)
    (ctx : BitcoinBIP68.Context) (inputs : List BitcoinBIP68.Input) :
    BitcoinBIP68.returnedHeights (BitcoinBIP68.calculate version flags ctx inputs) =
      BitcoinBIP68.expectedHeights version flags inputs := by sorry
Source
BIP68, Specification and Implementation: https://github.com/bitcoin/bips/blob/100ba872c808946155b1eeb8c4568058f2eea0a7/bip-0068.mediawiki; Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48, CalculateSequenceLocks (lines 45–101), EvaluateSequenceLocks (103–111), SequenceLocks (113–116): https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/consensus/tx_verify.cpp#L45-L116. Functional contract extracted from these routines; the BIP does not number these claims as mathematical theorems.
Read-back

What the Lean code literally says, in plain math · GPT-6 (Codex independent sub-agent)

For every pair of 32-bit bit vectors vvv and fff, every context consisting of a natural number HHH and an arbitrary function M:N→NM:\mathbb{N}\to\mathbb{N}M:N→N, and every finite ordered list of inputs (si,ci)(s_i,c_i)(si​,ci​), where each sis_isi​ is a 32-bit bit vector and each cic_ici​ is a natural number, the following calculation returns the list whose iiith entry is 000 if the unsigned value of vvv is at least 222, the unsigned value of fff is odd, and ⌊unsigned⁡(si)/2147483648⌋=1\lfloor\operatorname{unsigned}(s_i)/2147483648\rfloor=1⌊unsigned(si​)/2147483648⌋=1, and is cic_ici​ otherwise. The calculation uses an accumulator (a,b,L)(a,b,L)(a,b,L) with two integer fields and a list of natural numbers, initially (−1,−1,[])(-1,-1,[])(−1,−1,[]). It is enabled precisely when the unsigned value of vvv is at least 222 and bitwise AND of fff with the 32-bit value 111 is nonzero. When enabled, it processes the inputs from left to right: if bitwise AND of sis_isi​ with 214748364821474836482147483648 is nonzero, it prepends 000 to LLL and leaves a,ba,ba,b unchanged; otherwise, it prepends cic_ici​ to LLL and, if bitwise AND of sis_isi​ with 419430441943044194304 is nonzero, replaces bbb by max⁡(b,M(ci−1)+512di−1)\max(b,M(c_i-1)+512d_i-1)max(b,M(ci​−1)+512di​−1) while leaving aaa unchanged, and if that bitwise AND is zero, replaces aaa by max⁡(a,ci+di−1)\max(a,c_i+d_i-1)max(a,ci​+di​−1) while leaving bbb unchanged. Here did_idi​ is the unsigned value of the bitwise AND of sis_isi​ with 655356553565535; the term 512di512d_i512di​ is obtained by shifting that masked 32-bit vector left by 999 bits and taking its unsigned value, with no truncation of nonzero bits for these masked values. All additions and final subtractions in the accumulator updates are integer operations after converting the natural quantities to integers, whereas the argument ci−1c_i-1ci​−1 of MMM uses natural-number subtraction and is 000 when ci=0c_i=0ci​=0. When the calculation is not enabled, it leaves a=b=−1a=b=-1a=b=−1 and sets LLL to the reverse of the input list of coin heights cic_ici​. Its returned list is the reverse of the final LLL. The asserted equality is equality of ordered lists, including repeated entries, and applies to the empty input list, in which case both lists are empty. There are no hypotheses restricting HHH, MMM, the coin heights, or the bit vectors: in particular HHH and coin heights may be zero, coin heights need not be bounded by HHH, and no monotonicity or upper bound is imposed on MMM.

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

    Confirmed by the moderator at approval.

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