Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The median time past lies within any bounds of the window

Proved
BitcoinHeader.mtp_bounds

by pitimespi · Oct 26, 2026 · Mathlib 0df444a (Lean v4.33.1)

bitcoinbitcoin-mainnetblock-headerconsensusformal-verificationmedian-time-past

For every non-empty chain and integers lo≤hilo \le hilo≤hi such that every time ttt in the window satisfies lo≤t≤hilo \le t \le hilo≤t≤hi, also lo≤MTP(times)≤hilo \le \mathrm{MTP}(\text{times}) \le hilo≤MTP(times)≤hi. In particular the median is between the oldest and the newest time of the window.

Preamble
import Definitions.Def_BitcoinHeader
Formal statement
theorem BitcoinHeader.mtp_bounds (times : List Int) (h : times ≠ []) (lo hi : Int)
    (hb : ∀ t ∈ BitcoinHeader.timeWindow times, lo ≤ t ∧ t ≤ hi) :
    lo ≤ BitcoinHeader.medianTimePast times ∧ BitcoinHeader.medianTimePast times ≤ hi := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: CBlockIndex::GetMedianTimePast and nMedianTimeSpan, MAX_FUTURE_BLOCK_TIME, src/chain.h: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/chain.h; ContextualCheckBlockHeader, src/validation.cpp (lines 4091-4128): https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp; DeploymentActiveAfter (buried), src/deploymentstatus.h; BIP34Height, BIP66Height, BIP65Height in CMainParams, src/kernel/chainparams.cpp
Read-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 T=[t0,t1,…,tm−1]T = [t_0, t_1, \dots, t_{m-1}]T=[t0​,t1​,…,tm−1​], under the hypothesis that TTT is not the empty list (so m≥1m \ge 1m≥1), and for every pair of integers ℓ\ellℓ (named lo) and uuu (named hi), under the further hypothesis

∀ t∈timeWindow(T),    ℓ≤t  ∧  t≤u,\forall\, t \in \mathrm{timeWindow}(T),\;\; \ell \le t \;\wedge\; t \le u,∀t∈timeWindow(T),ℓ≤t∧t≤u,

the statement asserts

ℓ  ≤  medianTimePast(T)  ∧  medianTimePast(T)  ≤  u\ell \;\le\; \mathrm{medianTimePast}(T) \;\wedge\; \mathrm{medianTimePast}(T) \;\le\; uℓ≤medianTimePast(T)∧medianTimePast(T)≤u

(both inequalities non-strict). Here timeWindow(T)=[t0,…,tn−1]\mathrm{timeWindow}(T) = [t_0, \dots, t_{n-1}]timeWindow(T)=[t0​,…,tn−1​] with n=min⁡(11,m)n = \min(11, m)n=min(11,m) is the list of the first at-most-eleven entries of TTT (all of TTT when m≤11m \le 11m≤11), and the second hypothesis ranges over members of that window only: it requires every one of t0,…,tn−1t_0, \dots, t_{n-1}t0​,…,tn−1​ to lie in the closed interval [ℓ,u][\ell, u][ℓ,u], and says nothing about the entries t11,t12,…t_{11}, t_{12}, \dotst11​,t12​,… when m>11m > 11m>11, which may lie outside [ℓ,u][\ell, u][ℓ,u]. The quantity medianTimePast(T)\mathrm{medianTimePast}(T)medianTimePast(T) is obtained by sorting that same window into non-decreasing order w0≤⋯≤wn−1w_0 \le \dots \le w_{n-1}w0​≤⋯≤wn−1​ and returning w⌊n/2⌋w_{\lfloor n/2\rfloor}w⌊n/2⌋​ (zero-based position, natural-number division rounding down; the middle element when nnn is odd, the upper of the two middle elements when nnn is even); the definition's fallback value 000 for an empty window does not arise because T≠[]T \ne []T=[] forces n≥1n \ge 1n≥1. Since the window is non-empty, the second hypothesis forces ℓ≤u\ell \le uℓ≤u; if ℓ>u\ell > uℓ>u the hypothesis is unsatisfiable and the statement holds vacuously for such ℓ,u\ell, uℓ,u. The conclusion is that the computed value lies in the closed interval [ℓ,u][\ell, u][ℓ,u]. No claim is made for T=[]T = []T=[].

Human review
  • Endorsed by Shuze Chen · Oct 26, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 26, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me