Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The compact overflow flag is exactly the 256-bit bound

Proved
BitcoinPow.overflow_iff

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

bitcoinbitcoin-mainnetconsensusdifficultyformal-verificationproof-of-work

For every 32-bit word ccc with size SSS and mantissa WWW,

compactOverflow(c)=true  ⟺  2256≤specTarget(c),\mathrm{compactOverflow}(c) = \mathtt{true} \iff 2^{256} \le \mathrm{specTarget}(c),compactOverflow(c)=true⟺2256≤specTarget(c),

where specTarget(c)=W⋅256S−3\mathrm{specTarget}(c) = W \cdot 256^{S-3}specTarget(c)=W⋅256S−3 for S>3S > 3S>3 and ⌊W/2563−S⌋\lfloor W / 256^{3-S} \rfloor⌊W/2563−S⌋ otherwise. The flag computed by SetCompact from the three threshold tests on SSS and WWW is therefore not an approximation: it is set precisely when the encoded value does not fit in 256 bits. Both directions are asserted, for all 2322^{32}232 words.

Preamble
import Definitions.Def_BitcoinPow
Formal statement
theorem BitcoinPow.overflow_iff (c : BitVec 32) :
    BitcoinPow.compactOverflow c = true ↔ BitcoinPow.width ≤ BitcoinPow.specTarget c := 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 32-bit word ccc (an integer with 0≤c<2320 \le c < 2^{32}0≤c<232), writing s=⌊c/224⌋s = \lfloor c / 2^{24} \rfloors=⌊c/224⌋ for its top byte (0≤s≤2550 \le s \le 2550≤s≤255) and m=c mod 223m = c \bmod 2^{23}m=cmod223 for its low 23 bits (0≤m≤83886070 \le m \le 83886070≤m≤8388607), the following two conditions are equivalent (a genuine "if and only if"):

  1. The Boolean value
[m≠0] ∧ ([s>34] ∨ ([m>255]∧[s>33]) ∨ ([m>65535]∧[s>32]))[m \ne 0] \ \wedge\ \Big( [s > 34] \ \vee\ \big([m > 255] \wedge [s > 33]\big) \ \vee\ \big([m > 65535] \wedge [s > 32]\big) \Big)[m=0] ∧ ([s>34] ∨ ([m>255]∧[s>33]) ∨ ([m>65535]∧[s>32]))

is true (this is the custom "compact overflow" flag of ccc; all comparisons are strict);

  1. the natural number
T(c)={⌊m/256 3−s⌋if s≤3,m⋅256 s−3if s>3T(c) = \begin{cases} \lfloor m / 256^{\,3-s} \rfloor & \text{if } s \le 3, \\ m \cdot 256^{\,s-3} & \text{if } s > 3 \end{cases}T(c)={⌊m/2563−s⌋m⋅256s−3​if s≤3,if s>3​

(the custom "spec target" of ccc, computed on unbounded natural numbers with no reduction modulo 22562^{256}2256) satisfies the non-strict inequality

2256≤T(c).2^{256} \le T(c).2256≤T(c).

Binders and hypotheses. The only variable is ccc, universally quantified over all 2322^{32}232 words; there are no further hypotheses. Bit 23 of ccc (the bit of value 2232^{23}223) plays no role on either side.

Edge cases visible in the statement. When m=0m = 0m=0 the left side is false and T(c)=0T(c) = 0T(c)=0, so the right side is also false. When s≤3s \le 3s≤3 the left side is false and T(c)≤m<223T(c) \le m < 2^{23}T(c)≤m<223, so the right side is false. The equivalence is asserted in both directions: overflow-flag true implies T(c)≥2256T(c) \ge 2^{256}T(c)≥2256, and T(c)≥2256T(c) \ge 2^{256}T(c)≥2256 implies overflow-flag true. The threshold is exactly 22562^{256}2256 with ≤\le≤, so a value of T(c)T(c)T(c) equal to 22562^{256}2256 would fall on the "overflow" side (though T(c)T(c)T(c) is a multiple of mmm with m<223m < 2^{23}m<223 times a power of 256, so the auditor may check which values are attainable).

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