Median time past is non-decreasing along a chain obeying time-too-old
ProvedBitcoinHeader.mtp_mono_chainLet be the block times of a chain, most recent first, such that every block satisfies the time-too-old rule against its predecessor:
Then for all ,
the median time past of any ancestor is at most that of any descendant. Here is the transcription of GetMedianTimePast: the element at index of the sorted window of at most eleven most recent times.
This is the clock-monotonicity property that time-based lock-times (BIP113, BIP68) rely on: once the chain's median time has passed a threshold, it never falls back below it. The chain's times themselves need not be increasing; only the median rule is assumed.
Formalization Note. The statement is about suffixes times.drop i of the time list; the hypothesis is the time-too-old conjunct of ContextualCheckBlockHeader at every position.
import Definitions.Def_BitcoinHeader
theorem BitcoinHeader.mtp_mono_chain (times : List Int)
(hok : ∀ (i : Nat) (hi : i < times.length),
BitcoinHeader.medianTimePast (times.drop (i + 1)) < times[i]) :
∀ (i j : Nat), i ≤ j → j ≤ times.length →
BitcoinHeader.medianTimePast (times.drop j) ≤ BitcoinHeader.medianTimePast (times.drop i) := 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)
For every finite list of integers (indexed from ; may be ), under the hypothesis
the statement asserts
Here is the list obtained from by removing its first entries (it is the empty list when ), and in the hypothesis is the entry of at position , which is well defined because the hypothesis supplies the bound as an explicit argument (the hypothesis is a dependent statement: for each and each proof that , the inequality holds; this is logically the same as "for each "). For any list , is computed by taking the first entries of , sorting them into non-decreasing order , and returning (zero-based, natural-number division rounding down; the middle element when is odd, the upper of the two middle elements when is even), or returning the fallback value when is empty. Thus the hypothesis says: for every position , the entry strictly exceeds the median (in the above sense) of the window formed by the up-to-eleven entries immediately following it; in particular, for the last position the list is empty, so the hypothesis includes the condition (the last entry is strictly positive). The conclusion says: for any two positions with , the median of the window of entries from position onward is at most the median of the window of entries from position onward; for the list is empty and its median is , so the conclusion includes for every , and for it is the trivial reflexive inequality. Edge case : the hypothesis is vacuously true (no ), and the conclusion only concerns , asserting . Nothing is asserted for ; the hypothesis is stated for every index of , not merely for indices within the first eleven.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.