Home › Topics › Sequence › BIP 113

BIP 113: Median time-past as endpoint for lock-time calculations

Also known as: median time-past, MTP, BIP113, BIP-0113.

In plain English: Changes how Bitcoin measures time for timelocked transactions, using the median time of the previous 11 blocks instead of a single block's timestamp. Because this value only moves forward, miners cannot game timestamps to include timelocked transactions early.

Status
Deployed
Type
Specification
Layer
Consensus (soft fork)
Authors
Thomas Kerin, Mark Friedenbach
Assigned
Last changed
Activated
Block 419,328 (2016-07)
Topics
Sequence, Consensus
Source
bip-0113.mediawiki on GitHub · Markdown

Full specification

Abstract

This BIP is a proposal to redefine the semantics used in determining a time-locked transaction's eligibility for inclusion in a block. The median of the last 11 blocks is used instead of the block's timestamp, ensuring that it increases monotonically with each block.

Motivation

At present, transactions are excluded from inclusion in a block if the present time or block height is less than or equal to that specified in the locktime. Since the consensus rules do not mandate strict ordering of block timestamps, this has the unfortunate outcome of creating a perverse incentive for miners to lie about the time of their blocks in order to collect more fees by including transactions that by wall clock determination have not yet matured.

This BIP proposes comparing the locktime against the median of the past 11 block's timestamps, rather than the timestamp of the block including the transaction. Existing consensus rules guarantee this value to monotonically advance, thereby removing the capability for miners to claim more transaction fees by lying about the timestamps of their block.

This proposal seeks to ensure reliable behaviour in locktime calculations as required by BIP65 (CHECKLOCKTIMEVERIFY) and matching the behavior of BIP68 (sequence numbers) and BIP112 (CHECKSEQUENCEVERIFY).

Specification

The values for transaction locktime remain unchanged. The difference is only in the calculation determining whether a transaction can be included. Instead of an unreliable timestamp, the following function is used to determine the current block time for the purpose of checking lock-time constraints:

enum { nMedianTimeSpan=11 };

int64_t GetMedianTimePast(const CBlockIndex* pindex) { int64_t pmedian[nMedianTimeSpan]; int64_t* pbegin = &pmedian[nMedianTimeSpan]; int64_t* pend = &pmedian[nMedianTimeSpan]; for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev) *(--pbegin) = pindex->GetBlockTime(); std::sort(pbegin, pend); return pbegin[(pend - pbegin)/2]; }

Lock-time constraints are checked by the consensus method IsFinalTx(). This method takes the block time as one parameter. This BIP proposes that after activation calls to IsFinalTx() within consensus code use the return value of `GetMedianTimePast(pindexPrev)` instead.

The new rule applies to all transactions, including the coinbase transaction.

A reference implementation of this proposal is provided by the following pull request:

https://github.com/bitcoin/bitcoin/pull/6566

Deployment

This BIP is to be deployed by "versionbits" BIP9 using bit 0.

For Bitcoin mainnet, the BIP9 starttime will be midnight 1st May 2016 UTC (Epoch timestamp 1462060800) and BIP9 timeout will be midnight 1st May 2017 UTC (Epoch timestamp 1493596800).

For Bitcoin testnet, the BIP9 starttime will be midnight 1st March 2016 UTC (Epoch timestamp 1456790400) and BIP9 timeout will be midnight 1st May 2017 UTC (Epoch timestamp 1493596800).

This BIP must be deployed simultaneously with BIP68 and BIP112 using the same deployment mechanism.

Acknowledgements

Mark Friedenbach for designing and authoring the reference implementation of this BIP.

Thanks go to Gregory Maxwell who came up with the original idea, in #bitcoin-wizards on 2013-07-16.

Thomas Kerin authored this BIP document.

Compatibility

Transactions generated using time-based lock-time will take approximately an hour longer to confirm than would be expected under the old rules. This is not known to introduce any compatibility concerns with existing protocols.

References

BIP9: Versionbits

BIP65: OP_CHECKLOCKTIMEVERIFY

BIP68: Consensus-enforced transaction replacement signaled via sequence numbers

BIP112: CHECKSEQUENCEVERIFY

Softfork deployment considerations

Version bits

This document is placed in the public domain.

Questions about BIP 113

What is BIP 113?

BIP 113, “Median time-past as endpoint for lock-time calculations”, is a specification Bitcoin Improvement Proposal written by Thomas Kerin and Mark Friedenbach and assigned in August 2015. Changes how Bitcoin measures time for timelocked transactions, using the median time of the previous 11 blocks instead of a single block's timestamp. Because this value only moves forward, miners cannot game timestamps to include timelocked transactions early.

Is BIP 113 active?

Yes. BIP 113 has the status Deployed, which means it is live: adopted by the Bitcoin network or by widely used software. It activated on Bitcoin's main network at block 419,328 in July 2016.

Who wrote BIP 113?

BIP 113 was written by Thomas Kerin and Mark Friedenbach. Its number was assigned on August 10, 2015.

Which BIPs build on BIP 113?

2 other BIPs reference BIP 113: BIP 9 (Version bits with timeout and delay) and BIP 123 (BIP Classification).

Where can I read the full BIP 113 specification?

The complete text of BIP 113 is on this page, taken unchanged from the official bitcoin/bips repository on GitHub. It is also available as Markdown and JSON.

BIPs that build on BIP 113

  • BIP 9: Version bits with timeout and delay: Deployed. Lets miners signal readiness for several soft forks (backward-compatible rule upgrades) at once by setting individual bits in each block's version number. An upgrade locks in once enough blocks…
  • BIP 123: BIP Classification: Deployed. Sets out a way to classify BIPs into layers, such as consensus, peer services, APIs and applications, according to which part of the system they affect. This helps readers judge how widely a…

Learn more

Guides

Glossary

Related proposals

  • BIP 30: Duplicate transactions: Deployed. Added a rule forbidding a block from including a transaction with the same ID as an earlier one whose outputs are not fully spent. Such duplicates can overwrite earlier coins and make them…
  • BIP 34 (block height in coinbase): Block v2, Height in Coinbase: Deployed. Upgraded blocks to version 2 and required each block's coinbase transaction (the one paying the miner) to include the block's height. This makes every coinbase unique, preventing duplicate…
  • BIP 42: A finite monetary supply for Bitcoin: Deployed. A tongue-in-cheek proposal fixing a software quirk that would have made the block reward reappear and coin issuance restart a couple of centuries from now. It ensures the roughly 21 million coin…
  • BIP 50: March 2013 Chain Fork Post-Mortem: Deployed. A post-mortem of the March 2013 incident in which a database limit in older Bitcoin software caused the blockchain to split temporarily. It explains what went wrong, how miners and developers…
  • BIP 54: Consensus Cleanup: Complete. Bundles fixes for several long-standing protocol weaknesses: the timewarp attack (manipulating block timestamps to speed up coin issuance), blocks that take extremely long to validate, Merkle tree…
  • BIP 62: Dealing with malleability: Closed. Proposed a set of rules to stop third parties from altering a transaction's ID without changing what it does, a problem called malleability. It was withdrawn after Segregated Witness (SegWit) solved…