2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								<pre>
							 
						 
					
						
							
								
									
										
										
										
											2015-08-24 19:06:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  BIP: 113
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 09:45:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Layer: Consensus (soft fork)
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:55:04 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Title: Median time-past as endpoint for lock-time calculations
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  Author: Thomas Kerin <me@thomaskerin.io>
							 
						 
					
						
							
								
									
										
										
										
											2016-02-03 07:02:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          Mark Friedenbach <mark@friedenbach.org>
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 09:47:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Comments-Summary: No comments yet.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0113
							 
						 
					
						
							
								
									
										
										
										
											2016-07-18 23:37:42 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  Status: Final
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  Type: Standards Track
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Created: 2015-08-10
							 
						 
					
						
							
								
									
										
										
										
											2016-11-30 09:47:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  License: PD
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								</pre>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								==Abstract==
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:55:04 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This BIP is a proposal to redefine the semantics used in determining a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								time-locked transaction's eligibility for inclusion in a block. The
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								median of the last 11 blocks is used instead of the block's timestamp,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ensuring that it increases monotonically with each block.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								==Motivation==
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 15:59:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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).
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								==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 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								block time for the purpose of checking lock-time constraints:
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    enum { nMedianTimeSpan=11 };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    int64_t GetMedianTimePast(const CBlockIndex* pindex)
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    {
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        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];
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-29 15:59:43 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 17:28:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The new rule applies to all transactions, including the coinbase transaction.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-05 16:53:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								A reference implementation of this proposal is provided by the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								following pull request:
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-05 16:53:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								https://github.com/bitcoin/bitcoin/pull/6566
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								==Deployment==
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 20:14:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This BIP is to be deployed by "versionbits" BIP9 using bit 0.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-24 19:06:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 20:14:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								==Acknowledgements==
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Mark Friedenbach for designing and authoring the reference
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								implementation of this BIP.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-24 19:06:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Thanks go to Gregory Maxwell who came up with the original idea,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								in #bitcoin-wizards on 2013-07-16.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:55:04 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Thomas Kerin authored this BIP document.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								==Compatibility==
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								==References==
							 
						 
					
						
							
								
									
										
										
										
											2016-03-17 20:14:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki BIP9: Versionbits]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-18 01:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki BIP65: OP_CHECKLOCKTIMEVERIFY]
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 19:13:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-18 01:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki BIP68: Consensus-enforced transaction replacement signaled via sequence numbers]
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 19:13:23 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-24 19:06:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki BIP112: CHECKSEQUENCEVERIFY]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-August/010396.html Softfork deployment considerations]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[https://gist.github.com/sipa/bf69659f43e763540550 Version bits]
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 16:30:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 00:06:41 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								==Copyright==
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This document is placed in the public domain.