Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Appending a block that passes time-too-old never lowers the median

Proved
BitcoinHeader.mtp_mono

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

bitcoinbitcoin-mainnetblock-headerconsensusformal-verificationmedian-time-past

For every chain of times ccc and time ttt with MTP(c)<t\mathrm{MTP}(c) < tMTP(c)<t,

MTP(c)≤MTP(t::c).\mathrm{MTP}(c) \le \mathrm{MTP}(t :: c).MTP(c)≤MTP(t::c).

The new window is ttt followed by the ten most recent times of ccc: it gains ttt, which lies above the old median, and loses at most the eleventh time of the old window. For a chain shorter than eleven blocks the window grows instead and the median index may move; the inequality holds in both cases.

Preamble
import Definitions.Def_BitcoinHeader
Formal statement
theorem BitcoinHeader.mtp_mono (times : List Int) (t : Int)
    (h : BitcoinHeader.medianTimePast times < t) :
    BitcoinHeader.medianTimePast times ≤ BitcoinHeader.medianTimePast (t :: times) := 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​] (possibly empty) and every integer ttt, under the hypothesis

medianTimePast(T)<t(strict),\mathrm{medianTimePast}(T) < t \quad(\text{strict}),medianTimePast(T)<t(strict),

the statement asserts the non-strict inequality

medianTimePast(T)  ≤  medianTimePast(t::T),\mathrm{medianTimePast}(T) \;\le\; \mathrm{medianTimePast}(t :: T),medianTimePast(T)≤medianTimePast(t::T),

where t::T=[t,t0,t1,…,tm−1]t :: T = [t, t_0, t_1, \dots, t_{m-1}]t::T=[t,t0​,t1​,…,tm−1​] is the list obtained by placing ttt in front of TTT as its new first entry (so ∣t::T∣=m+1|t::T| = m+1∣t::T∣=m+1). Here medianTimePast(L)\mathrm{medianTimePast}(L)medianTimePast(L), for any list of integers LLL, is computed by taking the first n=min⁡(11,∣L∣)n = \min(11, |L|)n=min(11,∣L∣) entries of LLL, sorting them 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, rounding down; the middle element for odd nnn, the upper of the two middle elements for even nnn), with the fallback value 000 when LLL is empty. Note that the window of t::Tt :: Tt::T consists of ttt together with the first min⁡(10,m)\min(10, m)min(10,m) entries of TTT: when m≥11m \ge 11m≥11, the entry t10t_{10}t10​ (the eleventh entry of TTT) belongs to the window of TTT but not to the window of t::Tt :: Tt::T, so the two windows are not nested in general. The hypothesis compares ttt only with the median of TTT's window, not with the individual entries of TTT. Edge case m=0m = 0m=0: then medianTimePast([])=0\mathrm{medianTimePast}([]) = 0medianTimePast([])=0, the hypothesis reads 0<t0 < t0<t, and the conclusion reads 0≤medianTimePast([t])=t0 \le \mathrm{medianTimePast}([t]) = t0≤medianTimePast([t])=t. The conclusion is ≤\le≤, not <<<: it allows the two medians to be equal.

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