THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin BIP113 Median-Time-Past: Why Timelocks Do Not Use Wall-Clock Time

permalink THAMER
#bip113#bitcoin#locktime#median-time-past#mtp

Bitcoin uses timestamps, but it does not have a universally trusted clock. BIP113 addresses this problem for transaction finality by using median-time-past (MTP), a value derived from recent blocks, rather than simply trusting the timestamp chosen for the candidate block. This matters for absolute transaction locktime and for understanding the limits of time-based spending restrictions.

What median-time-past means

MTP is the median timestamp of the previous 11 blocks (or fewer where the chain is shorter). Taking the median limits how much a single unusually early or late block timestamp can influence the value. It does not make the timestamps perfectly accurate, and MTP can lag real-world time.

When validating a candidate block, Bitcoin compares a time-based nLockTime against the MTP of the preceding block. The transaction must be final under that context; a block timestamp that jumps forward does not by itself allow a time-locked transaction to bypass the MTP requirement.

Why the previous block matters

The rule makes the endpoint for transaction locktime independent of the timestamp the candidate miner proposes. This reduces an incentive for a miner to choose an aggressive block timestamp solely to include otherwise non-final transactions. MTP is also used in relative time-lock calculations, though the exact reference point depends on the rule being evaluated.

BIP113 was activated alongside BIP68 and BIP112 in the CSV soft-fork deployment. These proposals addressed distinct parts of transaction and Script validation: absolute time endpoints, sequence-based relative locks, and the Script opcode that enforces relative locktime commitments.

Time is approximate, not a promise

A wallet that says a payment becomes spendable at a particular date must account for how MTP progresses. Blocks arrive irregularly, timestamps are constrained but not synchronized to a perfect clock, and transaction propagation and confirmation depend on fees and miners. An eligible transaction may still remain unconfirmed.

Similarly, a height-based locktime measures blocks, not a guaranteed number of minutes. Estimating 10 minutes per block is a useful long-run heuristic, not a consensus scheduling rule.

Reading validation failures

When diagnosing a non-final transaction, first identify whether the locktime is height-based or time-based, then check whether any input is non-final. For relative locks, inspect BIP68 flags and the confirmation context of the UTXO being spent. Distinguish the consensus lock from wallet policy, mempool acceptance, and eventual confirmation.

Primary references

BIP113 — Median time-past as endpoint for lock-time calculations: https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki

BIP68 — Relative lock-time: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki

Bitcoin developer reference — Block headers: https://developer.bitcoin.org/reference/block_chain.html

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects