The encoded target drops by at most a factor of four per period, up to rounding
ProvedBitcoinDifficulty.encoded_target_lowerFor setCompact bits ≤ powLimit and any timestamps: setCompact (getCompact (setCompact bits / 4)) ≤ setCompact (calculateNextWork bits lastTime firstTime). The new target is at least the compact encoding of a quarter of the old one (round_mono).
import Definitions.Def_BitcoinDifficulty import Definitions.Def_BitcoinPow open BitcoinDifficulty BitcoinPow
theorem BitcoinDifficulty.encoded_target_lower (bits : BitVec 32) (hb : BitcoinPow.setCompact bits ≤ BitcoinPow.powLimit)
(lastTime firstTime : Int) :
BitcoinPow.setCompact (BitcoinPow.getCompact (BitcoinPow.setCompact bits / 4)) ≤
BitcoinPow.setCompact (BitcoinPow.calculateNextWork bits lastTime firstTime) := 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.encoded_target_lower
Statement
Binders (universally quantified).
- , a compact word (a 32-bit word, i.e. an integer with ; named
bits); - and , integers (named
lastTime,firstTime), each positive, zero or negative, with no relation between them.
Hypothesis.
- (hb) , i.e. the decoded value of is at most .
Conclusion.
where is natural-number floor division. Unfolding : with , and , the right-hand side is . So the statement compares two values that have each been passed through "encode then decode": the quarter of the decoded input (not capped at , not divided via ) on the left, and the computed, capped next target on the right. The inequality is non-strict ().
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.
Edge cases and what the quantifiers include
- No ordering of and is assumed. For (including and ) the clamped timespan is ; for it is . The range of over all is exactly the integer interval .
- The hypothesis admits every word with (e.g. , or top byte , or top byte ): then both sides are and the conclusion reads .
- The hypothesis admits words with bit 23 (the "sign" bit) set, and words the original code would flag as overflowing, as long as the decoded value is ; the statement does not mention the sign or overflow flags.
- When the product is at most , so the reduction modulo inside does not alter it; the statement nevertheless contains that reduction literally.
- For the left-hand side is .
- No conclusion is drawn about itself versus ; only the re-rounded value appears on the left.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.