The target never exceeds powLimit
ProvedBitcoinDifficulty.target_after_le_powLimitFor setCompact bits ≤ powLimit and any list of periods: setCompact (targetAfter bits periods) ≤ powLimit.
import Definitions.Def_BitcoinDifficulty import Definitions.Def_BitcoinPow open BitcoinDifficulty BitcoinPow
theorem BitcoinDifficulty.target_after_le_powLimit (bits : BitVec 32) (hb : BitcoinPow.setCompact bits ≤ BitcoinPow.powLimit) :
∀ (periods : List (Int × Int)), BitcoinPow.setCompact (BitcoinDifficulty.targetAfter bits periods) ≤ BitcoinPow.powLimit := 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_le_powLimit
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 ; the list may be empty and its entries are arbitrary integers with no relations among them.
Hypothesis.
- (hb) .
Conclusion. For every such list ,
a non-strict inequality, where is the compact word obtained by applying the retarget map once per list element, in list order, starting from .
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 is exactly the hypothesis .
- of length one: the conclusion is , i.e. the decoded value of is at most ; note the cap at inside is applied to the value before encoding, and the conclusion is about the value after encoding and decoding.
- Pairs may have (clamped to ) or huge (clamped to ); consecutive pairs are unrelated.
- Words with , with bit 23 set, or with top byte satisfy the hypothesis and are included.
- The statement bounds only the decoded value; it says nothing about the sign bit, overflow flag or top byte of the words themselves.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.