Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

BIP68 sequence masks agree with arithmetic decoding

Proved
BitcoinBIP68.decode_sequence

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

bip68bitcoinbitcoin-mainnetconsensusformal-verification

Let sss be any unsigned 32-bit word and nnn its value. Put d=n mod 65536d=n\bmod65536d=nmod65536. The implementation's disable-bit and time-type tests agree with the corresponding quotient-and-remainder tests, its masked delay is ddd, and its masked left-shifted seconds value is 512d512d512d:

disabledcore(s)  ⟺  ⌊n/231⌋=1,timecore(s)  ⟺  ⌊n/222⌋ mod 2=1,delaycore(s)=d,secondscore(s)=512d.\begin{aligned} \mathrm{disabled}_{\mathrm{core}}(s)&\iff\lfloor n/2^{31}\rfloor=1,\\ \mathrm{time}_{\mathrm{core}}(s)&\iff\lfloor n/2^{22}\rfloor\bmod2=1,\\ \mathrm{delay}_{\mathrm{core}}(s)&=d,\\ \mathrm{seconds}_{\mathrm{core}}(s)&=512d. \end{aligned}disabledcore​(s)timecore​(s)delaycore​(s)secondscore​(s)​⟺⌊n/231⌋=1,⟺⌊n/222⌋mod2=1,=d,=512d.​

The statement includes every bit pattern and makes no hypothesis on the unused bits. It connects the bit-vector implementation to the arithmetic specification, including the fact that the masked nine-bit shift loses no significant bits.

Preamble
import Definitions.Def_BIP68_Model
import Definitions.Def_BIP68_Core
Formal statement
theorem BitcoinBIP68.decode_sequence (sequence : BitVec 32) :
    (BitcoinBIP68.coreDisabled sequence = true ↔ BitcoinBIP68.specDisabled sequence) ∧
    (BitcoinBIP68.coreTimeBased sequence = true ↔ BitcoinBIP68.specTimeBased sequence) ∧
    BitcoinBIP68.coreDelay sequence = BitcoinBIP68.specDelay sequence ∧
    BitcoinBIP68.coreSeconds sequence = 512 * BitcoinBIP68.specDelay sequence := 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 32-bit word sss, let nnn be its unsigned natural-number value, so 0≤n<2320 \le n < 2^{32}0≤n<232. The following four statements hold simultaneously: (1) the Boolean test that the bitwise conjunction of sss with the 32-bit mask 0x80000000\mathtt{0x80000000}0x80000000 is nonzero returns true if and only if ⌊n/2147483648⌋=1\lfloor n/2147483648\rfloor=1⌊n/2147483648⌋=1; (2) the Boolean test that the bitwise conjunction of sss with the 32-bit mask 0x00400000\mathtt{0x00400000}0x00400000 is nonzero returns true if and only if ⌊n/4194304⌋ mod 2=1\lfloor n/4194304\rfloor \bmod 2=1⌊n/4194304⌋mod2=1; (3) the unsigned natural-number value of the bitwise conjunction of sss with the 32-bit mask 0x0000ffff\mathtt{0x0000ffff}0x0000ffff equals n mod 65536n \bmod 65536nmod65536; and (4) the unsigned natural-number value obtained by taking that last conjunction and shifting it left by nine positions as a 32-bit word, discarding any bits shifted beyond its width, equals 512(n mod 65536)512(n \bmod 65536)512(nmod65536), with this multiplication performed in the natural numbers. There are no additional hypotheses on sss: the statements include the all-zero word, the all-one word, and every combination of its bits, including either value of the bits tested in (1) and (2).

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