The retarget always passes the permitted-transition check
ProvedBitcoinPow.nextWork_permittedFor every height divisible by , every last word whose decoded value is at most , and all block times ,
Here calculateNextWork is the mainnet CalculateNextWorkRequired: decode, multiply by the clamped elapsed time inside 256 bits, divide by , cap, re-encode. permittedTransition is the mainnet PermittedDifficultyTransition: the decoded new word must lie between the re-encoded caps of and .
The hypothesis on holds for every word DeriveTarget accepts, hence for every block on a valid chain; under it none of the three 256-bit products wraps. The statement is the consistency of the two functions: a header carrying the required nBits is never rejected by the cheap header-chain check, whatever the timestamps.
Formalization Note. The proof reduces to the monotonicity of the rounding map and to the ordering of the three capped quotients; no assumption that is itself a GetCompact output is made.
import Definitions.Def_BitcoinPow
theorem BitcoinPow.nextWork_permitted (height : Nat) (lastBits : BitVec 32) (lastTime firstTime : Int)
(hh : height % BitcoinPow.difficultyAdjustmentInterval = 0)
(hold : BitcoinPow.setCompact lastBits ≤ BitcoinPow.powLimit) :
BitcoinPow.permittedTransition height lastBits
(BitcoinPow.calculateNextWork lastBits lastTime firstTime) = true := by sorryRead-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 ("height"), every 32-bit word ("lastBits"), and all integers ("lastTime") and ("firstTime"), if
- (H1) (where ; this includes ), and
- (H2) (non-strict), where is the "setCompact" decoding defined below,
then the Boolean
equals true. Unfolded (using H1 to select the retarget branch of ), the conclusion is the pair of non-strict inequalities
literally asserted as with , where
with and .
The value being tested. is the 32-bit word where: is the natural number equal to , i.e. if , if , and otherwise (the integer-to-natural conversion applied here is the identity since the clamp is positive); ; ; if , else .
The decoding and encoding . For a 32-bit word with top byte and low 23 bits , if and if (bit 23 of is ignored). For a natural number , is computed by: if , else ; ; if , else ; ; , if , else , ; as a 32-bit word.
Binders and hypotheses. Four universally quantified variables: over all natural numbers, over all 32-bit words, and over all integers. Two hypotheses, H1 and H2. Note what is not assumed: no relation between and the times ; no condition that 's "negative" bit 23 is clear or that its "overflow" flag is false (H2 only bounds the decoded value , which ignores bit 23 and is already reduced modulo ); is allowed by H2 (then ); and may be negative, zero, or arbitrarily large. The conclusion is a single Boolean equality; it is an implication, not an equivalence, and nothing is asserted when or when . The height passed to is itself (not ), and the old word is while the new word is the output of on the same .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.