The header path is the Header mission's contextual check
ProvedBitcoinBlock.acceptHeader_iffacceptHeader S h now = accept S [] iff the proof of work holds, h.prevBlock is the tip's hash, and the Header mission's contextualCheck holds with the chain's tip height, times, required bits and the clock.
Deprecated. Superseded by BitcoinBlockV2.acceptHeader_iff (revision 2 of the block mission): the p2shSigOpCount of this revision counted every push of scriptSig instead of only the redeem script, over-counting P2SH sigops; the V2 declarations carry the corrected definition.
import Definitions.Def_BitcoinBlock import Definitions.Def_BitcoinSer import Definitions.Def_BitcoinHeader
theorem BitcoinBlock.acceptHeader_iff (S : ChainState) (h : BitcoinSer.Header) (now : Int) :
BitcoinBlock.acceptHeader S h now = .accept S [] ↔
BitcoinBlock.checkHeaderPow h = true ∧ h.prevBlock = S.tipHash ∧
BitcoinHeader.contextualCheck ⟨h.version, (h.time : Int), BitVec.ofNat 32 h.bits⟩ S.tipHeight
(S.timesTo S.tipHeight) S.requiredBits now = 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)
Read-back: BitcoinBlock.acceptHeader_iff
Binders
- : a chain state, i.e. a pair where is a list of serialized block headers (each with fields: version , previous-block hash (a byte list), merkle root (a byte list), time , bits , nonce ) and is a ledger (an association list from outpoints to coins). No hypothesis is placed on : its header list may be empty, may not start with the genesis header, etc.
- : a serialized block header (same six fields as above; time and bits are unbounded natural numbers).
- : the local clock.
There are no further hypotheses.
Conclusion
The statement is an equivalence (iff):
Left-hand side, unfolded
is a value of the four-constructor outcome type (accept with a state and undo list / invalid / futureTime / missingPrev), computed by the following ordered chain of tests:
- if is false, the result is invalid;
- else if , the result is missingPrev;
- else if , the result is invalid;
- else if (as integers), the result is invalid;
- else if , the result is futureTime;
- else if , the result is invalid;
- else the result is : the very same state and the empty undo list.
So the left side holds exactly when all six tests pass (constructor equality on the outcome type; the accepted state must be literally and the undo list literally empty, which is what step 7 produces).
Here:
- is reduced modulo and viewed as a 32-bit word.
- : let be the little-endian numeric value of the 32-byte double-SHA256 of the serialized header; decode as a compact target (mantissa low 23 bits, exponent top byte, shifted into 256 bits with truncation modulo ); the check is false if the compact word is "negative" (mantissa non-zero and bit set), the decoded target is , the compact word "overflows", or the target exceeds ; otherwise it is .
- with natural-number subtraction (so when the header list is empty).
- is the last header of , or the genesis header if the list is empty; is its double-SHA256 header hash.
- is the list of the times (as integers) of the first headers of , most recent first.
- is the median-time-past of the tip: take the first entries of , sort them ascending, and take the element at index ( the window length), with default for an empty window.
- : with the header at index (natural subtraction, so index when the tip height is below ; the genesis header if that index is out of range), it is : the tip's bits unchanged unless is a multiple of , in which case the retargeted compact word computed from the clamped timespan .
- holds when and , or and , or and .
Right-hand side, unfolded
The right side is a conjunction of three Boolean equalities:
- (as above);
- (byte-list equality);
- from the header-rules development, applied to the reduced header , the previous height , the previous times , the required word and the clock . That function is the conjunction
where is the same window-of-11 sorted median described above and is the header development's own constant (a separate definition from the block development's constant of the same value).
Edge cases silently included
Empty header list (, tip defaults to the genesis header, median defaults over a window of length gives ); and are unbounded naturals reduced/cast when used; clamps at ; the header at index defaults to the genesis header when out of range; no well-formedness of or is assumed; the "futureTime" and "missingPrev" outcomes are both just "not accept" on the left.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.