Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The raw next target is between a quarter and four times the last target

Proved
BitcoinDifficulty.raw_target_bounds

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

bitcoinbitcoin-mainnetconsensusdifficultyformal-verificationproof-of-workretargettimewarp

For a last target t≤t \let≤ powLimit and any timestamps: rawNextTarget t lastTime firstTime ≤4t\le 4t≤4t, and either the cap binds (the raw target is powLimit) or rawNextTarget t lastTime firstTime ≥⌊t/4⌋\ge \lfloor t/4 \rfloor≥⌊t/4⌋. From the clamp bounds of the proof-of-work mission and the exact arithmetic.

Preamble
import Definitions.Def_BitcoinDifficulty
import Definitions.Def_BitcoinPow
open BitcoinDifficulty BitcoinPow
Formal statement
theorem BitcoinDifficulty.raw_target_bounds (t : Nat) (ht : t ≤ BitcoinPow.powLimit) (lastTime firstTime : Int) :
    BitcoinDifficulty.rawNextTarget t lastTime firstTime ≤ 4 * t ∧
    (BitcoinDifficulty.rawNextTarget t lastTime firstTime = BitcoinPow.powLimit ∨
      t / 4 ≤ BitcoinDifficulty.rawNextTarget t lastTime firstTime) := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: CalculateNextWorkRequired, GetNextWorkRequired, src/pow.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/pow.cpp; arith_uint256::SetCompact/GetCompact (arith_uint256.cpp); 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: theorem BitcoinDifficulty.raw_target_bounds

Statement

Binders (universally quantified).

  • ttt, a natural number;
  • ℓ\ellℓ and fff, integers (named lastTime, firstTime), unrelated to each other.

Hypothesis.

  • (ht) t≤L=2224−1t \le L = 2^{224} - 1t≤L=2224−1.

Conclusion. A conjunction of two parts, writing R=R(t,ℓ,f)R = R(t, \ell, f)R=R(t,ℓ,f) for the raw next target:

R≤4tand(R=L    or    ⌊t/4⌋≤R).R \le 4t \quad\text{and}\quad \Big( R = L \;\;\text{or}\;\; \lfloor t / 4 \rfloor \le R \Big).R≤4tand(R=Lor⌊t/4⌋≤R).

Here 4t4t4t is the natural-number product, ⌊t/4⌋\lfloor t/4 \rfloor⌊t/4⌋ is natural-number floor division, "or" is inclusive disjunction, and both inequalities are non-strict.

Definitions used

Constants (from the imported proof-of-work definitions).

  • W=2256W = 2^{256}W=2256 (the modulus called width).
  • L=2224−1L = 2^{224} - 1L=2224−1 (the value called powLimit).
  • T=14⋅24⋅60⋅60=1,209,600T = 14 \cdot 24 \cdot 60 \cdot 60 = 1{,}209{,}600T=14⋅24⋅60⋅60=1,209,600 (the value called targetTimespan); hence ⌊T/4⌋=302,400\lfloor T/4 \rfloor = 302{,}400⌊T/4⌋=302,400 and 4T=4,838,4004T = 4{,}838{,}4004T=4,838,400.

Clamping a timespan, κ(a)\kappa(a)κ(a) (the function called clampTimespan). For an integer aaa (positive, zero or negative),

κ(a)={302,400if a<302,400,4,838,400if a>4,838,400,aotherwise.\kappa(a) = \begin{cases} 302{,}400 & \text{if } a < 302{,}400,\\ 4{,}838{,}400 & \text{if } a > 4{,}838{,}400,\\ a & \text{otherwise.} \end{cases}κ(a)=⎩⎨⎧​302,4004,838,400a​if a<302,400,if a>4,838,400,otherwise.​

κ(a)\kappa(a)κ(a) always lies in [302,400,  4,838,400][302{,}400,\; 4{,}838{,}400][302,400,4,838,400], so it is positive and its conversion to a natural number (written κ(a)\kappa(a)κ(a) below as well) is lossless.

The raw next target, R(t,ℓ,f)R(t, \ell, f)R(t,ℓ,f) (the function called rawNextTarget, defined in this bundle). For a natural number ttt and integers ℓ,f\ell, fℓ,f, with τ=κ(ℓ−f)\tau = \kappa(\ell - f)τ=κ(ℓ−f),

R(t,ℓ,f)=min⁡ ⁣(⌊(t⋅τ) mod 2256T⌋,  L)R(t, \ell, f) = \min\!\left( \left\lfloor \frac{(t \cdot \tau) \bmod 2^{256}}{T} \right\rfloor,\; L \right)R(t,ℓ,f)=min(⌊T(t⋅τ)mod2256​⌋,L)

(the minimum is written in the source as "if L<L <L< the quotient then LLL else the quotient"). Unfolding the definitions, N(c,ℓ,f)=E(R(D(c),ℓ,f))N(c, \ell, f) = E\big(R(D(c), \ell, f)\big)N(c,ℓ,f)=E(R(D(c),ℓ,f)).

(For reference, R(t,ℓ,f)R(t, \ell, f)R(t,ℓ,f) unfolds to: let τ=κ(ℓ−f)\tau = \kappa(\ell - f)τ=κ(ℓ−f); let q=⌊((t⋅τ) mod 2256)/T⌋q = \lfloor ((t\cdot\tau) \bmod 2^{256}) / T \rfloorq=⌊((t⋅τ)mod2256)/T⌋; then R=LR = LR=L if L<qL < qL<q, else R=qR = qR=q. No encoding to a compact word is involved.)

Edge cases and what the quantifiers include

  • t=0t = 0t=0: then R=0R = 0R=0, the first part reads 0≤00 \le 00≤0, and the second part's right disjunct reads 0≤00 \le 00≤0.
  • t<4t < 4t<4: ⌊t/4⌋=0\lfloor t/4 \rfloor = 0⌊t/4⌋=0, so the right disjunct of the second part holds trivially whatever RRR is.
  • ℓ\ellℓ and fff are arbitrary integers; ℓ−f≤302,400\ell - f \le 302{,}400ℓ−f≤302,400 (including ℓ≤f\ell \le fℓ≤f) gives τ=302,400\tau = 302{,}400τ=302,400, and ℓ−f≥4,838,400\ell - f \ge 4{,}838{,}400ℓ−f≥4,838,400 gives τ=4,838,400\tau = 4{,}838{,}400τ=4,838,400.
  • For the admitted t≤Lt \le Lt≤L, t⋅τ<2247t \cdot \tau < 2^{247}t⋅τ<2247, so the reduction modulo 22562^{256}2256 inside RRR does not change the product; it is still literally present.
  • The second part is a disjunction: in the case R=LR = LR=L the statement makes no claim that ⌊t/4⌋≤R\lfloor t/4 \rfloor \le R⌊t/4⌋≤R (though with t≤Lt \le Lt≤L that would follow), and in the other case it makes no claim that R≠LR \ne LR=L.
  • The first part bounds RRR by 4t4t4t without any cap: when t>L/4t > L/4t>L/4 the bound 4t4t4t exceeds LLL, and the first part is then weaker than the cap built into RRR.
Human review
  • Endorsed by Shuze Chen · Oct 29, 2026

    Confirmed by the moderator at approval.

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