Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Off a retarget boundary the required word is unchanged and permitted

Proved
BitcoinPow.nextWork_off_boundary

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

bitcoinbitcoin-mainnetconsensusdifficultyformal-verificationproof-of-work

For every last height hhh with h+1≢0(mod2016)h + 1 \not\equiv 0 \pmod{2016}h+1≡0(mod2016), every last word ccc, and all block times,

nextWorkRequired(h,c,tlast,tfirst)=candpermittedTransition(h+1,c,c)=true.\mathrm{nextWorkRequired}(h, c, t_{\text{last}}, t_{\text{first}}) = c \qquad\text{and}\qquad \mathrm{permittedTransition}(h+1, c, c) = \mathtt{true}.nextWorkRequired(h,c,tlast​,tfirst​)=candpermittedTransition(h+1,c,c)=true.

On mainnet, where minimum-difficulty blocks are disabled, GetNextWorkRequired returns the previous word between retargets, and PermittedDifficultyTransition accepts an unchanged word there.

Preamble
import Definitions.Def_BitcoinPow
Formal statement
theorem BitcoinPow.nextWork_off_boundary (lastHeight : Nat) (lastBits : BitVec 32) (lastTime firstTime : Int)
    (h : (lastHeight + 1) % BitcoinPow.difficultyAdjustmentInterval ≠ 0) :
    BitcoinPow.nextWorkRequired lastHeight lastBits lastTime firstTime = lastBits ∧
    BitcoinPow.permittedTransition (lastHeight + 1) lastBits lastBits = true := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: GetNextWorkRequired (lines 14-48), CalculateNextWorkRequired (50-85), PermittedDifficultyTransition (89-136), DeriveTarget (146-159), CheckProofOfWorkImpl (161-171), src/pow.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/pow.cpp; arith_uint256::SetCompact (176-194), GetCompact (196-216), base_uint::operator<<= (15-30), operator*=(uint32_t) (49-59), operator/= (77-104), bits() (205-218), src/arith_uint256.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/arith_uint256.cpp; CMainParams powLimit, nPowTargetTimespan, nPowTargetSpacing, fPowAllowMinDifficultyBlocks, fPowNoRetargeting, enforce_BIP94, src/kernel/chainparams.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/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)

Statement. For every natural number hℓh_\ellhℓ​ ("lastHeight"), every 32-bit word ccc ("lastBits"), and all integers tℓt_\elltℓ​ ("lastTime") and tft_ftf​ ("firstTime"), if

(hℓ+1) mod 2016≠0(h_\ell + 1) \bmod 2016 \ne 0(hℓ​+1)mod2016=0

(where 2016=⌊1209600/600⌋2016 = \lfloor 1209600 / 600 \rfloor2016=⌊1209600/600⌋ is the custom "difficulty adjustment interval"), then both of the following hold:

  1. nextWorkRequired(hℓ,c,tℓ,tf)=c\mathrm{nextWorkRequired}(h_\ell, c, t_\ell, t_f) = cnextWorkRequired(hℓ​,c,tℓ​,tf​)=c, an equality of 32-bit words (bit for bit); and
  2. the Boolean permittedTransition(hℓ+1,c,c)\mathrm{permittedTransition}(h_\ell + 1, c, c)permittedTransition(hℓ​+1,c,c) equals true, where the transition is tested from the word ccc to the same word ccc at height hℓ+1h_\ell + 1hℓ​+1.

The function nextWorkRequired\mathrm{nextWorkRequired}nextWorkRequired, unfolded. It returns ccc if (hℓ+1) mod 2016≠0(h_\ell+1) \bmod 2016 \ne 0(hℓ​+1)mod2016=0, and otherwise returns calculateNextWork(c,tℓ,tf)\mathrm{calculateNextWork}(c, t_\ell, t_f)calculateNextWork(c,tℓ​,tf​) (a custom retargeting computation, not reached under the hypothesis). So conclusion 1 is, under the hypothesis, the first branch of the definition.

The function permittedTransition(h,cold,cnew)\mathrm{permittedTransition}(h, c_{\mathrm{old}}, c_{\mathrm{new}})permittedTransition(h,cold​,cnew​), unfolded. If h mod 2016≠0h \bmod 2016 \ne 0hmod2016=0 it is the Boolean [cold=cnew][c_{\mathrm{old}} = c_{\mathrm{new}}][cold​=cnew​] (equality of 32-bit words). If h mod 2016=0h \bmod 2016 = 0hmod2016=0 it is instead [minimum≤S(cnew)≤maximum][\mathrm{minimum} \le S(c_{\mathrm{new}}) \le \mathrm{maximum}][minimum≤S(cnew​)≤maximum] where, with SSS the "setCompact" decoding and GGG the "getCompact" encoding, maximum=S(G(L))\mathrm{maximum} = S(G(L))maximum=S(G(L)) with L=min⁡(2224−1, ⌊((S(cold)⋅4838400) mod 2256)/1209600⌋)L = \min\big(2^{224}-1,\ \lfloor ((S(c_{\mathrm{old}}) \cdot 4838400) \bmod 2^{256}) / 1209600 \rfloor\big)L=min(2224−1, ⌊((S(cold​)⋅4838400)mod2256)/1209600⌋) and minimum=S(G(ℓ))\mathrm{minimum} = S(G(\ell))minimum=S(G(ℓ)) with ℓ=min⁡(2224−1, ⌊((S(cold)⋅302400) mod 2256)/1209600⌋)\ell = \min\big(2^{224}-1,\ \lfloor ((S(c_{\mathrm{old}}) \cdot 302400) \bmod 2^{256}) / 1209600 \rfloor\big)ℓ=min(2224−1, ⌊((S(cold​)⋅302400)mod2256)/1209600⌋). In conclusion 2 the height argument is h=hℓ+1h = h_\ell + 1h=hℓ​+1, which under the hypothesis satisfies h mod 2016≠0h \bmod 2016 \ne 0hmod2016=0, so conclusion 2 reduces to the Boolean [c=c][c = c][c=c] being true; the retarget branch (and hence SSS, GGG, the modular products and caps) is not exercised.

Binders and hypotheses. Four universally quantified variables (hℓh_\ellhℓ​ over all natural numbers including 000; ccc over all 32-bit words, with no validity condition on its negative bit, exponent, or decoded value; tℓ,tft_\ell, t_ftℓ​,tf​ over all integers, unused in the conclusions) and one hypothesis, (hℓ+1) mod 2016≠0(h_\ell + 1) \bmod 2016 \ne 0(hℓ​+1)mod2016=0, i.e. hℓ∉{2015,4031,6047,… }h_\ell \notin \{2015, 4031, 6047, \dots\}hℓ​∈/{2015,4031,6047,…}. The conclusion is a conjunction. The statement is an implication only; nothing is asserted when (hℓ+1) mod 2016=0(h_\ell+1) \bmod 2016 = 0(hℓ​+1)mod2016=0.

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