The encoded target at most quadruples per period
ProvedBitcoinDifficulty.encoded_target_upperFor setCompact bits ≤ powLimit and any timestamps: setCompact (calculateNextWork bits lastTime firstTime) ≤ 4 · setCompact bits. The compact encoding rounds down (getCompact_le).
import Definitions.Def_BitcoinDifficulty import Definitions.Def_BitcoinPow open BitcoinDifficulty BitcoinPow
theorem BitcoinDifficulty.encoded_target_upper (bits : BitVec 32) (hb : BitcoinPow.setCompact bits ≤ BitcoinPow.powLimit)
(lastTime firstTime : Int) :
BitcoinPow.setCompact (BitcoinPow.calculateNextWork bits lastTime firstTime) ≤ 4 * 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.encoded_target_upper
Statement
Binders (universally quantified).
- , a compact word (a 32-bit word, named
bits); - and , integers (named
lastTime,firstTime), unrelated to each other.
Hypothesis.
- (hb) .
Conclusion.
where is an ordinary natural-number product (no reduction modulo anything, no cap at on the right-hand side). Unfolding : with , and , the left-hand side is — the decoded value of the re-encoded, capped next target. 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
- and range over all integers; may be zero or negative (clamped to ) or arbitrarily large (clamped to ).
- If the right-hand side is , so the statement asserts for every in that case; the hypothesis admits all such words (zero mantissa, top byte , top byte , etc.).
- The hypothesis constrains only the decoded value; the sign bit (bit 23) and the overflow conditions of the original code are not mentioned.
- The cap at inside applies before encoding; the bound on the right may exceed (it does whenever ), and the statement does not assert .
- When , , so the modular reduction inside is inactive for every admitted ; it is still part of the literal statement.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.