Over m periods the target grows by at most 4^m
ProvedBitcoinDifficulty.target_after_upperFor setCompact bits ≤ powLimit and any list of periods with any timestamps: setCompact (targetAfter bits periods) ≤ 4^m · setCompact bits.
import Definitions.Def_BitcoinDifficulty import Definitions.Def_BitcoinPow open BitcoinDifficulty BitcoinPow
theorem BitcoinDifficulty.target_after_upper (bits : BitVec 32) (hb : BitcoinPow.setCompact bits ≤ BitcoinPow.powLimit) :
∀ (periods : List (Int × Int)),
BitcoinPow.setCompact (BitcoinDifficulty.targetAfter bits periods) ≤ 4 ^ periods.length * BitcoinPow.setCompact bits := 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)
Read-back: theorem BitcoinDifficulty.target_after_upper
Statement
Binders (universally quantified).
- , a compact word (a 32-bit word, named
bits); - , a finite list of pairs of integers (named
periods), quantified inside the statement after the hypothesis on ; possibly empty; entries arbitrary and unrelated.
Hypothesis.
- (hb) .
Conclusion. For every such list , writing for its length,
a non-strict inequality between natural numbers, with an ordinary product (no reduction modulo and no cap at on the right-hand side).
Definitions used
Constants (from the imported proof-of-work definitions).
- (the modulus called
width). - (the value called
powLimit). - (the value called
targetTimespan); hence and .
Decoding a compact word, (the function called setCompact). A compact word is a 32-bit word, i.e. an integer with . Put
- , the top byte of , an integer in ;
- , the low 23 bits of (bit 23, worth , and the top byte are discarded).
Then is the natural number
Consequences of this definition that the quantifiers below silently include: always; whenever , whenever , and whenever (the shift then exceeds 256 bits and the reduction modulo leaves ); for or only the low 16 or low 8 bits of survive the reduction; a word whose bit 23 ("sign" bit) is set decodes to the same value as the word with that bit cleared. never consults the overflow or sign conditions of the original code; it is a total function on all words.
Encoding a natural number, (the function called getCompact). For a natural number let be its bit length (, and for ) and let (the number of bytes of ). Put
If bit 23 of is set (i.e. , bitwise and), let and ; otherwise and . Then is the 32-bit word (bitwise or, then reduction modulo ).
Consequences: for every one has and , so the reductions modulo and change nothing and the bitwise or is a plain sum ; the word then has top byte and low 23 bits (bit 23 of is clear). Composing with : for , equals with its lowest bits set to zero (lowest bits when the bit-23 adjustment fired; nothing zeroed when and no adjustment), so in particular , and .
Clamping a timespan, (the function called clampTimespan). For an integer (positive, zero or negative),
always lies in , so it is positive and its conversion to a natural number (written below as well) is lossless.
The next encoded target, (the function called calculateNextWork). For a compact word and integers ("last time") and ("first time"), put and
i.e. . Then , a compact word. The product is reduced modulo before the floor division by ; the cap at is applied before re-encoding, and nothing caps or checks the decoded value of the encoded result afterwards.
Iterated retargeting, (the function called targetAfter, defined in this bundle). For a compact word and a finite list of pairs of integers, defined by recursion on the list:
So for , : the first pair of the list is applied first. The pairs are arbitrary integers; nothing relates to , requires , or restricts their magnitude.
Edge cases and what the quantifiers include
- : , , , and the conclusion reads .
- If the right-hand side is for every , so the statement asserts that for every list in that case; such are admitted by the hypothesis.
- The right-hand side grows without bound in and is not capped at or reduced modulo ; for large it exceeds , above every possible value of .
- Each step of decodes, multiplies by a clamped timespan in modulo , floor-divides by , caps at , and re-encodes (which can only lower the value, per the remark on ); the statement is about the final decoded value only.
- Pairs may have or ; there is no condition linking the pairs, no height condition, and no sign/overflow condition on or on intermediate words.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.