Skip to content
BIP ATLAS

BIPs 0065 · 0068 · 0112 · 0113

When is a coin allowed to move?

A coin can require a wait before it is spent. The delay can name a block height or time, or count from when the coin was created.

An escrow can have a deadline, and a refund can be made to wait. Bitcoin can make a delay part of a coin’s spending conditions. An absolute lock names a block height or time; a relative lock requires the coin to reach a minimum age.1234

The transaction fields and script opcodes have different jobs. A field can delay one transaction. A script condition can require the transaction to use that field. The examples below check both against Bitcoin Core’s test transactions.567

Source revision
bitcoin/bips @ 3a10b5b
Source checked
1 October 2026
Review state
Awaiting review
Source details

This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not an endorsement or a sign of consensus.

BIP 65: OP_CHECKLOCKTIMEVERIFY

BIP
65
Layer
Consensus (soft fork)
Title
OP_CHECKLOCKTIMEVERIFY
Authors
Peter Todd
Status
Deployed
Type
Specification
Assigned
2014-10-01
License
PD

Pinned source · Reader view on bips.dev
SHA-256 717400aef7789a795bbc86a67e0f40ea94966aea13975052e1fc31a047207399
Git blob 4bd292f8b45a2b2b68013b24f45c23e354b70e4f

BIP 68: Relative lock-time using consensus-enforced sequence numbers

BIP
68
Layer
Consensus (soft fork)
Title
Relative lock-time using consensus-enforced sequence numbers
Authors
Mark Friedenbach
BtcDrak
Nicolas Dorier
kinoshitajona
Status
Deployed
Type
Specification
Assigned
2015-05-28

Pinned source · Reader view on bips.dev
SHA-256 ec5a50cc66fff7b4e4bc1f2e24587d7876649d1b5329ef73ffa2e5a3f647281b
Git blob 5b4c6d66311a28325cd5cb27f4977f1c137dc6ad

BIP 112: CHECKSEQUENCEVERIFY

BIP
112
Layer
Consensus (soft fork)
Title
CHECKSEQUENCEVERIFY
Authors
BtcDrak
Mark Friedenbach
Eric Lombrozo
Status
Deployed
Type
Specification
Assigned
2015-08-10
License
PD

Pinned source · Reader view on bips.dev
SHA-256 61022872545daeb779ef5d38f769d7a155c0f85333653b20c83b0a2329b523c4
Git blob 085ec730fc46079c72a2931049fcd0e8d7157651

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

BIP
113
Layer
Consensus (soft fork)
Title
Median time-past as endpoint for lock-time calculations
Authors
Thomas Kerin
Mark Friedenbach
Status
Deployed
Type
Specification
Assigned
2015-08-10
License
PD

Pinned source · Reader view on bips.dev
SHA-256 f0643ba529837a673015a37287c21972bfa24cebfdc67e2844c6ad8d51d1ea69
Git blob 5ae089682ec3729854e9808591a4e505a7046ed7

Fig. A10.1 One field, two scales

One field, two scalesnLockTime is 32 bits. Values below 500,000,000 are block heights; from 500,000,000 (1985-11-05) to 4,294,967,295 (2106-02-07) they are Unix times. A relative lock keeps 16 bits: up to 65,535 blocks, or up to 65,535 units of 512 seconds, 33,553,920 seconds; at 600 seconds a block the first is the longer.nLOCKTIME · 32 BITS, TO SCALEUNIX TIMES0 · HEIGHTS500,000,000 = 1985-11-054,294,967,295 = 2106-02-07nSEQUENCE · LOW 16 BITS, IN WALL-CLOCK TIMEBIT 22 CLEAR: 65,535 BLOCKS (≈ 1.25 YEARS)BIT 22 SET: 65,535 × 512 S (≈ 1.06 YEARS)= 33,553,920 S · BARS AT 600 S A BLOCK
nLockTime splits its 32 bits at 500,000,000: heights below, Unix times above. A relative lock reads the same 16 bits as blocks or as 512-second units, depending on one flag.489

A field that does not lock a coin

Every transaction ends with a four-byte number, nLockTime. When enforced, it prevents inclusion until the block height or applicable block time is greater than that value. The field constrains this spending transaction. It does not prevent a different transaction from spending the same coins.1011

Setting nLockTime does not by itself make the coins unspendable before that time. As BIP 65 explains, another signed transaction may already spend them without a lock. A condition in the output’s script is needed to enforce the delay on the spend.12

Fig. A10.2 A field that does not lock a coin

  1. A field that does not lock a coin, step 1 of 3A coin, and a signed transaction A spending it whose nLockTime is in the future and whose input is not final, so no block can include A yet.THE COINTRANSACTION AnLockTime: LATERNOT YET MINEABLE

    A signed transaction with a future nLockTime (and an input that is not final) cannot be mined yet: it proves the coin can be spent later.

  2. A field that does not lock a coin, step 2 of 3A second signed transaction B spends the same coin with nLockTime 0; B can be mined now, so A's future date locked nothing.THE SAME COINTRANSACTION AnLockTime: LATERTRANSACTION BnLockTime: 0MINEABLE NOW

    But nothing about the coin stops another signed transaction, with no lock at all, from spending it now.

  3. A field that does not lock a coin, step 3 of 3The coin's script now holds an expiry and OP_CHECKLOCKTIMEVERIFY. Transaction B, with nLockTime 0, fails that check, so no spend can come before the expiry.THE COIN'S SCRIPT<expiry> OP_CLTVTRANSACTION BnLockTime: 0✗ FAILS THE SCRIPT

    BIP 65 puts the condition in the coin’s own script: OP_CHECKLOCKTIMEVERIFY fails any spend whose nLockTime is too early.

Schematic. A future nLockTime proves a spend is possible later, but another spend of the same coin may already exist. A condition in the coin’s own script closes that gap.11012

The same field carries two kinds of value. Below a threshold it is a block height; at or above it, a time. BIP 65’s code names the threshold LOCKTIME_THRESHOLD, and Bitcoin Core defines it as 500,000,000, which as a Unix time falls on 5 November 1985. Any height Bitcoin will reach for a very long time sits below that line, and any date worth locking to sits above it.8

If every input has the maximum sequence number, 0xffffffff, the transaction’s nLockTime is not enforced. BIP 143’s native P2WPKH example sets nLockTime to 17 and leaves one input non-final, so no block below height 18 could include it. BIP 174’s final transaction has nLockTime 0 and only final inputs.1314

Fig. A10.3 Reading published transactions

Reading published transactionsNative P2WPKH example (signed) (BIP 143 · version 1, line 190): version 1, nLockTime 17, inputs 0xffffffee, 0xffffffff final. nLockTime enforced: no block before height 18. Version 1, so BIP 68 gives nSequence no meaning. P2SH-P2WPKH example (unsigned) (BIP 143 · version 1, line 206): version 1, nLockTime 1,170, inputs 0xfffffffe. nLockTime enforced: no block before height 1,171. Version 1, so BIP 68 gives nSequence no meaning. Signed legacy transaction (BIP 174 · version 2, line 619): version 2, nLockTime 1,257,139, inputs 0xfffffffe. nLockTime enforced: no block before height 1,257,140. Bit 31 is set on every input, so BIP 68 reads no relative lock. Final extracted transaction (BIP 174 · version 2, line 833): version 2, nLockTime 0, inputs 0xffffffff final, 0xffffffff final. Every input is final, so nLockTime is not enforced. Bit 31 is set on every input, so BIP 68 reads no relative lock.NATIVE P2WPKH EXAMPLE (SIGNED) · BIP 143 · VERSION 1VERSION1IN 0ffffffeeIN 1 · FINALffffffffnLOCKTIME17ENFORCED: NO BLOCK BELOW HEIGHT 18VERSION 1: NO BIP 68 MEANINGP2SH-P2WPKH EXAMPLE (UNSIGNED) · BIP 143 · VERSION 1VERSION1IN 0fffffffenLOCKTIME1,170ENFORCED: NO BLOCK BELOW HEIGHT 1,171VERSION 1: NO BIP 68 MEANINGSIGNED LEGACY TRANSACTION · BIP 174 · VERSION 2VERSION2IN 0fffffffenLOCKTIME1,257,139ENFORCED: NO BLOCK BELOW HEIGHT 1,257,140BIP 68: BIT 31 SET ON EVERY INPUT, NO RELATIVE LOCKFINAL EXTRACTED TRANSACTION · BIP 174 · VERSION 2VERSION2IN 0 · FINALffffffffIN 1 · FINALffffffffnLOCKTIME0EVERY INPUT FINAL: nLOCKTIME NOT ENFORCEDBIP 68: BIT 31 SET ON EVERY INPUT, NO RELATIVE LOCK
Version, nLockTime and nSequence of four transactions published in BIPs 143 and 174, as consensus reads them.13141516

Putting the lock in the output

BIP 65 closes the gap with a new opcode, OP_CHECKLOCKTIMEVERIFY, which redefines the unused NOP2. It sits in the output’s script, so the condition travels with the coin, and it makes the output unspendable until some point in the future.1

The opcode compares its argument with the spending transaction’s nLockTime. It does not read the current chain height or time. The transaction’s nLockTime must also permit inclusion in the block. Together, these checks enforce the script’s requirement. The BIP credits Gregory Maxwell with suggesting this indirect comparison.17

OP_CHECKLOCKTIMEVERIFY rejects the script if any of these conditions applies:5

  • The stack is empty.
  • The argument is negative.
  • The argument and nLockTime use different units: block height versus time.
  • The argument is greater than nLockTime.
  • This input’s nSequence is 0xffffffff.5

The last check prevents this input from disabling nLockTime. If all checks pass, execution continues as for a NOP: no further operation occurs at this opcode.513

In the absolute-lock view, change nLockTime and follow the first check that fails. Then compare a relative lock. Passing the script check satisfies the script’s comparison; the transaction must also meet the separate conditions for inclusion in a block.35671117

Fig. A10.4 The lock fields, checked

Static view: the first absolute-lock case, with the checks it passes or fails, both readings shown. With JavaScript you can switch to relative locks, pick any of the 12 cases and change a field.

The gate a spend has to passHeight lock, argument equals nLockTime: every check passes and the script continues. Bitcoin Core labels it valid; the model agrees. The locking script is 499999999 OP_CHECKLOCKTIMEVERIFY. The spending transaction has version 1, input 0 nSequence 0x00000000 and nLockTime 499,999,999. Checks in order: The stack is not empty: yes (top item: 499,999,999); The argument is not negative: yes (499,999,999 ≥ 0); Argument and nLockTime are the same kind: yes (argument is a height, nLockTime 499,999,999 is a height); The argument is not greater than nLockTime: yes (499,999,999 ≤ 499,999,999); This input is not final: yes (nSequence 0x00000000). nLockTime 499,999,999 read as a height is block 499,999,999, read as a time 1985-11-05 00:53:19 UTC; it is read as a height.HEIGHT LOCK, ARGUMENT EQUALS NLOCKTIMEBITCOIN CORE tx_valid.json #99 · VALIDTHE COIN'S LOCK (SPENT OUTPUT SCRIPT)499999999 OP_CHECKLOCKTIMEVERIFYARGUMENT 499,999,999 · A HEIGHTTHE SPENDING TRANSACTIONNVERSION1INPUT 0 NSEQUENCE0x00000000NLOCKTIME499,999,999HEIGHTS · 0TIMES · 2³² − 1500,000,000ARGnLockTimeHALVES NOT TO ONE SCALEAS A HEIGHT: BLOCK 499,999,999 ← READ THIS WAYAS A TIME: 1985-11-05 00:53:19 UTCBIP 65'S CHECKS, IN ORDER✓1 The stack is not emptytop item: 499,999,999✓2 The argument is not negative499,999,999 ≥ 0✓3 Argument and nLockTime are the same kindargument is a height, nLockTime 499,999,999 is a he…✓4 The argument is not greater than nLockTime499,999,999 ≤ 499,999,999✓5 This input is not finalnSequence 0x00000000✓ THIS SCRIPT CHECK PASSESBLOCK ELIGIBILITY IS NOT CHECKED HERE

Height lock, argument equals nLockTime: every check passes and the script continues. Bitcoin Core labels it valid; the model agrees.

The separate chain checkSchematic for an active absolute lock L. The script checks the transaction fields first. Block inclusion also requires candidate height greater than L, or for a time lock, the previous block's median time past greater than L. All other transaction rules still apply. This is not live chain data.CHAIN CHECK · SCHEMATIC, NOT CHAIN DATAACTIVE ABSOLUTE LOCK: nLockTime = LTOO EARLYLAFTER LHEIGHT > L · OR PARENT MTP > LPASSING THIS RULE DOES NOT CHECK THE REST OF A SPEND

For an active absolute lock, the candidate block’s height must exceed nLockTime. A time-based lock instead uses the previous block’s median time past (MTP). If every input is final, nLockTime is not enforced.

Exact checks and fields
Locking script
499999999 OP_CHECKLOCKTIMEVERIFY
nVersion · input 0 nSequence · nLockTime
1 · 0x00000000 · 499,999,999
The stack is not empty: yes
top item: 499,999,999
The argument is not negative: yes
499,999,999 ≥ 0
Argument and nLockTime are the same kind: yes
argument is a height, nLockTime 499,999,999 is a height
The argument is not greater than nLockTime: yes
499,999,999 ≤ 499,999,999
This input is not final: yes
nSequence 0x00000000

Bitcoin Core v29.0 tx_valid.json, entry 99 (Core’s comment for its group: “By-height locks, with argument == 0 and == tx nLockTime”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.

Twelve one-input transactions from Bitcoin Core’s test suite check script conditions against transaction fields. Passing does not establish block eligibility. The timeline shows the separate chain rule schematically; it does not use live chain data. Field changes are computed examples, not Core test cases.356711131516171819

Try the absolute cases above. An argument of 499,999,999 against nLockTime 499,999,998 fails by one block. Add one to nLockTime and it passes; add one more and nLockTime becomes a time, and the same argument now fails because the kinds no longer match.578

The argument is read as a number of up to five bytes, not the usual four. BIP 65’s code explains why: four bytes would give a year 2038 problem, while nLockTime itself, an unsigned 32-bit field, only becomes meaningless after the year 2106.20

The BIP’s simplest example prevents spending before an expiry time. Its script contains the expiry, OP_CHECKLOCKTIMEVERIFY, a DROP, and an ordinary pay-to-public-key-hash check. The signature check cannot authorize a spend before the expiry requirement is met.21

Counting from the coin

An absolute lock names a moment. Many protocols need something else: a delay that starts only when a coin is created. BIP 68 builds that out of each input’s nSequence field, and it does so only for transactions with version 2 or higher.315

If bit 31 is set, BIP 68 does not enforce a relative lock. The value 0xffffffff still marks the input final for nLockTime. When bit 31 is clear, bit 22 selects the relative-lock unit: blocks if clear, or 512-second units if set. The low 16 bits hold the value. The mask 0x0000ffff MUST be applied to extract it. The intervening bits are reserved for future use.4162223

Fig. A10.5 Thirty-two bits, three jobs

Thirty-two bits, three jobsnSequence under BIP 68, bit 31 on the left. Bit 31 is the disable flag; bit 22 picks the unit; bits 0 to 15 hold the value; the rest have no meaning. 65,535 blocks is 0x0000ffff; 65,535 units of 512 seconds is 0x0040ffff.nSEQUENCE · BIT 31 ON THE LEFTBIT 31 DISABLEBIT 22 TYPE65,535 BLOCKS = 0x0000ffff · BIT 31 CLEAR65,535 × 512 S = 0x0040ffff · BIT 31 CLEARVALUE · BITS 0–15MASK 0x0000ffffFADED: NO MEANING UNDER BIP 68
BIP 68’s two largest relative locks as bits: the disable flag, the type flag and the 16 value bits; the rest carry no meaning.491622

Why 512 seconds? The authors chose it because blocks arrive every 600 seconds on average, so either unit covers about the same span with the same bits. BIP 68’s own examples give the limits: up to 65,535 blocks, about 1.25 years, or a time below 33,554,431 seconds, about 1.06 years.924

A block-based relative lock of n permits inclusion at the coin’s confirmation height plus n, or later. A time-based lock uses median time past (MTP), not elapsed wall-clock time. Its starting value is the MTP of the block immediately before the coin’s confirmation block. Add 512 × n seconds to get the required time. The MTP of the candidate spending block’s parent must reach or exceed that time. The coinbase input is exempt.325

BIP 112 replaces NOP3 with OP_CHECKSEQUENCEVERIFY. It lets a script branch require a minimum age for the spent coin. The opcode fails if the stack is empty or the argument is negative. If the argument has bit 31 set, the opcode acts as a NOP, reserved for future soft forks.2618

Otherwise, the opcode compares the argument with the input’s nSequence after masking both values. It rejects the script if any of these conditions applies:6

  • The transaction version is below 2.
  • Bit 31 of the input’s nSequence is set.
  • The argument and nSequence use different units.
  • The masked argument is greater than the masked nSequence.6

Fig. A10.6 CHECKSEQUENCEVERIFY, check by check

  1. CHECKSEQUENCEVERIFY, check by check, step 1 of 7Check 1 of BIP 112 on Time lock, argument equals the input's lock: The stack is not empty, passes (top item: 4,259,839).CHECK 1 · ✓TOP OF THE STACK4,259,839ON THE STACK

    The stack is not empty: top item: 4,259,839. ✓

  2. CHECKSEQUENCEVERIFY, check by check, step 2 of 7Check 2 of BIP 112 on Time lock, argument equals the input's lock: The argument is not negative, passes (4,259,839 ≥ 0).CHECK 2 · ✓TOP OF THE STACK4,259,8394,259,839 ≥ 0

    The argument is not negative: 4,259,839 ≥ 0. ✓

  3. CHECKSEQUENCEVERIFY, check by check, step 3 of 7Check 3 of BIP 112 on Time lock, argument equals the input's lock: The argument's disable flag is clear, passes (bit 31 is clear).CHECK 3 · ✓3122150ARGUMENT · BIT 31 CLEAR

    The argument's disable flag is clear: bit 31 is clear. ✓

  4. CHECKSEQUENCEVERIFY, check by check, step 4 of 7Check 4 of BIP 112 on Time lock, argument equals the input's lock: Transaction version is at least 2, passes (version 2).CHECK 4 · ✓nVERSION22 ≥ 2

    Transaction version is at least 2: version 2. ✓

  5. CHECKSEQUENCEVERIFY, check by check, step 5 of 7Check 5 of BIP 112 on Time lock, argument equals the input's lock: The input's disable flag is clear, passes (nSequence 0x0040ffff: bit 31 clear).CHECK 5 · ✓3122150ARGUMENT · BIT 31 CLEARINPUT 0 nSEQUENCE · BIT 31 CLEAR

    The input's disable flag is clear: nSequence 0x0040ffff: bit 31 clear. ✓

  6. CHECKSEQUENCEVERIFY, check by check, step 6 of 7Check 6 of BIP 112 on Time lock, argument equals the input's lock: Argument and nSequence use the same unit, passes (argument counts time, nSequence counts time).CHECK 6 · ✓3122150ARGUMENT · BIT 31 CLEARINPUT 0 nSEQUENCE · BIT 31 CLEAR

    Argument and nSequence use the same unit: argument counts time, nSequence counts time. ✓

  7. CHECKSEQUENCEVERIFY, check by check, step 7 of 7Check 7 of BIP 112 on Time lock, argument equals the input's lock: Masked argument is not greater than masked nSequence, passes (65,535 ≤ 65,535 (units of 512 s)).CHECK 7 · ✓3122150ARGUMENT · BIT 31 CLEARINPUT 0 nSEQUENCE · BIT 31 CLEAR

    Masked argument is not greater than masked nSequence: 65,535 ≤ 65,535 (units of 512 s). ✓

Time lock, argument equals the input's lock: Bitcoin Core tx_valid.json entry 127, labelled valid; argument 0x0040ffff, input nSequence 0x0040ffff, version 2.

One of Bitcoin Core’s cases, a time-based relative lock, run check by check by the tested model.6722
Caveat

A relative lock needs both halves: a transaction version of 2 or more, and bit 31 of nSequence clear. With either missing, nSequence carries no relative lock under BIP 68, and a CHECKSEQUENCEVERIFY whose argument has bit 31 clear fails rather than passing.6151618

BIP 112 gives escrow and payment-channel examples. One escrow permits spending with two of three signatures at any time, or to Alice alone after 30 days. The delay starts when the payment into the escrow confirms. For channels, the authors argue that a relative lock gives a predictable response period for a revoked transaction. An absolute deadline would instead require closing the channel before that deadline.2627

Which clock?

Before BIP 113, time-based nLockTime used the including block’s own timestamp. Block timestamps need not increase in order. The authors identified an incentive for a miner to claim a later time and collect fees from transactions that had not matured by wall-clock time.28

BIP 113 replaces that timestamp with the median of the past 11 blocks’ timestamps, the median time past, which only moves forward. The rule covers every transaction, coinbase included, and the authors expected time-locked transactions to confirm about an hour later than before. BIP 68’s time-based locks are measured in the same median time past.4192930

Fig. A10.7 Which clock

Which clockSchematic: the timestamps of the last 11 blocks, in block order and not all increasing; sorted, the middle one is the median time past, which only moves forward as blocks are added. Bar heights are illustrative.LAST 11 BLOCKS · TIMESTAMPS IN BLOCK ORDERSORTEDMEDIAN TIME PASTSCHEMATIC
Schematic, not chain data: block timestamps need not increase, so locks read the median of the last eleven instead.1928
Note

The figures here check fields against fields, as the opcodes do. Whether a block may include a transaction also depends on the chain’s height and median time past, which this site never sees.1719

The proposals and their rollout

A payment channel, an escrow with a deadline, a refund that must wait: each needs a coin that cannot move yet. Bitcoin gets there with four specifications from 2014 and 2015, all consensus soft forks recorded as deployed. BIP 65 lets an output demand a date or a block height. BIP 68 repurposes each input’s sequence number as a relative lock, BIP 112 lets an output demand it, and BIP 113 decides which clock time locks read.12192331

The rollout is recorded in the BIPs. BIP 65 used the older switchover for version-4 blocks: enforced once 750 of the previous 1,000 blocks signalled, with older versions rejected at 950. BIPs 68, 112 and 113 were to deploy together through BIP 9 on bit 0, with a mainnet start of 1 May 2016.3233

For a script-enforced delay, the opcode checks the transaction’s fields. The block-inclusion rules check the transaction against the chain. Both must pass before the transaction can be included.356111719

Evidence

Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim from the BIP files at commit 3a10b5b, wiki markup included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the author’s rationale, history, a test vector, or our own inference.

  1. ↩ a b c d Rule OP_CHECKLOCKTIMEVERIFY lets a transaction output be made unspendable until some point in the future; it redefines NOP2.

    Quoted source text (2)

    This BIP describes a new opcode (OP_CHECKLOCKTIMEVERIFY) for the Bitcoin scripting system that allows a transaction output to be made unspendable until some point in the future.

    BIP 65, lines 14–16

    CHECKLOCKTIMEVERIFY redefines the existing NOP2 opcode.

    BIP 65, line 21
  2. ↩ a b c Rule CHECKSEQUENCEVERIFY redefines NOP3 and, with BIP 68, lets a script branch require a minimum age of the output being spent.

    Quoted source text (2)

    This BIP describes a new opcode (CHECKSEQUENCEVERIFY) for the Bitcoin scripting system that in combination with BIP 68 allows execution pathways of a script to be restricted based on the age of the output being spent.

    BIP 112, lines 16–19

    CHECKSEQUENCEVERIFY redefines the existing NOP3 opcode.

    BIP 112, line 24
  3. ↩ a b c d e f Rule A block-based relative lock n allows inclusion at the confirmation height plus n or later. A time-based lock allows inclusion when the candidate block’s parent MTP is at least the MTP of the block immediately before the coin’s confirmation plus 512 × n seconds.

    Quoted source text (3)

    More generally, a relative block lock-time n can be included n blocks after the mining date of the output it is spending, or any block thereafter.

    BIP 68, line 51

    More generally, a relative time-based lock-time n can be included into any block produced 512 * n seconds after the mining date of the output it is spending

    BIP 68, line 46

    The mining date of the output is equal to the median-time-past of the previous block which mined it. The block produced time is equal to the median-time-past of its previous block.

    BIP 68, lines 47–49
  4. ↩ a b c d e Rule Bit 22 chooses the unit: set means 512-second units counted from the median time past of the coin's previous block, clear means blocks.

    Quoted source text (1)

    Bit (1 << 22) determines if the relative lock-time is time-based or block based: If the bit is set, the relative lock-time specifies a timespan in units of 512 seconds granularity. The timespan starts from the median-time-past of the output’s previous block, and ends at the MTP of the previous block. If the bit is not set, the relative lock-time specifies a number of blocks.

    BIP 68, line 36
  5. ↩ a b c d e f g h Rule CHECKLOCKTIMEVERIFY fails if the stack is empty, the top item is negative, its lock-time type differs from nLockTime's, it is greater than nLockTime, or the input's nSequence is 0xffffffff; otherwise it acts as a NOP.

    Quoted source text (1)

    * the stack is empty; or * the top item on the stack is less than 0; or * the lock-time type (height vs. timestamp) of the top stack item and the nLockTime field are not the same; or * the top stack item is greater than the transaction's nLockTime field; or * the nSequence field of the txin is 0xffffffff; Otherwise, script execution will continue as if a NOP had been executed.

    BIP 65, lines 25–31
  6. ↩ a b c d e f g h i Rule CHECKSEQUENCEVERIFY fails on an empty stack or a negative argument; if the argument's disable flag is clear, it also fails when the transaction version is below 2, the input's disable flag is set, the units differ, or the masked argument exceeds the masked nSequence.

    Quoted source text (1)

    * the stack is empty; or * the top item on the stack is less than 0; or * the top item on the stack has the disable flag (1 << 31) unset; and ** the transaction version is less than 2; or ** the transaction input sequence number disable flag (1 << 31) is set; or ** the relative lock-time type is not the same; or ** the top stack item is greater than the transaction input sequence (when masked according to the BIP68);

    BIP 112, lines 27–33
  7. ↩ a b c d e Test vector This chapter's opcode figure uses 12 of 51 one-input CLTV/CSV transactions from Bitcoin Core's own transaction tests (v29.0, pinned excerpt); for all 51 the site's model gives the same verdict Core's tests expect, and the build fails otherwise. The cases and their labels are in sources/external/core-locktime-cases-excerpt.json, pinned by commit and SHA-256; the BIP line cited is the reference implementation those tests accompany.

    Quoted source text (1)

    A reference implementation is provided by the following pull request: https://github.com/bitcoin/bitcoin/pull/7524

    BIP 112, lines 340–342
  8. ↩ a b c Observed nLockTime is read either as a block height or as a time, depending on whether it is below LOCKTIME_THRESHOLD; Bitcoin Core's script.h (pinned excerpt, v29.0) defines that threshold as 500,000,000, a Unix time in November 1985. (The value rests on the pinned script.h lines in sources/external/core-locktime-cases-excerpt.json and a test that checks the model's constant against them.)

    Quoted source text (1)

    // There are two types of nLockTime: lock-by-blockheight // and lock-by-blocktime, distinguished by whether // nLockTime < LOCKTIME_THRESHOLD.

    BIP 65, lines 241–243
  9. ↩ a b c Rule BIP 68's encoding examples: up to 65,535 blocks (about 1.25 years), or a time under 33,554,431 seconds (about 1.06 years) encoded as (1 << 22) | (nTime >> 9).

    Quoted source text (1)

    0 <= nHeight <= 65,535 blocks (1.25 years) nSequence = nHeight; nHeight = nSequence & 0x0000ffff; // 0 <= nTime < 33,554,431 seconds (1.06 years) nSequence = (1 << 22) | (nTime >> 9);

    BIP 68, lines 243–249
  10. ↩ a b Rule nLockTime keeps a transaction from being mined until a given block height or block time.

    Quoted source text (1)

    The nLockTime field in a transaction prevents the transaction from being mined until either a certain block height, or block time, has been reached.

    BIP 65, lines 33–34
  11. ↩ a b c d Rule A transaction is excluded from a block while the height (or time) is less than or equal to its nLockTime, so nLockTime names the last height or time at which it may not be mined.

    Quoted source text (1)

    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.

    BIP 113, lines 24–26
  12. ↩ a b Author’s rationale BIP 65's motivation: nLockTime can show a spend is possible later, but cannot show the output is unspendable until then, because another valid signed transaction spending it may exist.

    Quoted source text (2)

    The nLockTime field in transactions can be used to prove that it is ''possible'' to spend a transaction output in the future, by constructing a valid transaction spending that output with the nLockTime field set.

    BIP 65, lines 43–50

    However, the nLockTime field can't prove that it is ''impossible'' to spend a transaction output until some time in the future, as there is no way to know if a valid signature for a different transaction spending that output has been created.

    BIP 65, lines 47–50
  13. ↩ a b c d Rule If every input's nSequence is the maximum value (0xffffffff), nLockTime is not enforced.

    Quoted source text (2)

    // Finally the nLockTime feature can be disabled and thus // CHECKLOCKTIMEVERIFY bypassed if every txin has been // finalized by setting nSequence to maxint.

    BIP 65, lines 259–263

    Setting nSequence to this value for every input in a transaction * disables nLockTime. */ static const uint32_t SEQUENCE_FINAL = 0xffffffff;

    BIP 68, lines 67–69
  14. ↩ a b Test vector Read by this site's model, BIP 143's native P2WPKH example has version 1, nLockTime 17 and one non-final input, so no block below height 18 can include it; BIP 174's signed legacy transaction has version 2 and nLockTime 1,257,139 with a non-final input; BIP 174's final transaction has nLockTime 0 and only final inputs.

    Quoted source text (3)

    nLockTime: 11000000

    BIP 143, line 184

    0200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf6

    BIP 174, line 619

    0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd75

    BIP 174, line 833
  15. ↩ a b c d Rule BIP 68 gives nSequence meaning only in transactions with nVersion 2 or more.

    Quoted source text (1)

    This specification defines the meaning of sequence numbers for transactions with an nVersion greater than or equal to 2

    BIP 68, line 26
  16. ↩ a b c d e Rule If bit 31 is set, nSequence has no consensus meaning; if it is clear, the field is an encoded relative lock-time.

    Quoted source text (1)

    If bit (1 << 31) of the sequence number is set, then no consensus meaning is applied to the sequence number and can be included in any block under all currently possible circumstances. If bit (1 << 31) of the sequence number is not set, then the sequence number is interpreted as an encoded relative lock-time.

    BIP 68, lines 30–32
  17. ↩ a b c d e Author’s rationale By comparing its argument with nLockTime, the opcode indirectly verifies that the height or time has been reached; the BIP credits Gregory Maxwell with suggesting the comparison against nLockTime rather than the chain.

    Quoted source text (2)

    By comparing the argument to CHECKLOCKTIMEVERIFY against the nLockTime field, we indirectly verify that the desired block height or block time has been reached; until that block height or block time has been reached the transaction output remains unspendable.

    BIP 65, lines 34–38

    Thanks goes to Gregory Maxwell for suggesting that the argument be compared against the per-transaction nLockTime, rather than the current block height and time.

    BIP 65, lines 306–308
  18. ↩ a b c Rule An argument with the disable flag set makes CHECKSEQUENCEVERIFY behave as a NOP, kept for future soft-fork extensibility.

    Quoted source text (1)

    // To provide for future soft-fork extensibility, if the // operand has the disabled lock-time flag set, // CHECKSEQUENCEVERIFY behaves as a NOP.

    BIP 112, lines 279–283
  19. ↩ a b c d e f Rule BIP 113 compares time locks against the median of the past 11 blocks' timestamps instead of the including block's own timestamp; that median advances monotonically.

    Quoted source text (2)

    The median of the last 11 blocks is used instead of the block's timestamp, ensuring that it increases monotonically with each block.

    BIP 113, lines 16–19

    This BIP proposes that after activation calls to IsFinalTx() within consensus code use the return value of `GetMedianTimePast(pindexPrev)` instead.

    BIP 113, lines 64–67
  20. ↩ Author’s rationale The argument may be a 5-byte number so that, like the 32-bit nLockTime field, it lasts until 2106 rather than hitting a year-2038 limit.

    Quoted source text (1)

    // If we kept to that limit we'd have a year 2038 problem, // even though the nLockTime field in transactions // themselves is uint32 which only becomes meaningless // after the year 2106.

    BIP 65, lines 225–232
  21. ↩ Author’s rationale BIP 65's example of frozen funds: <expiry time> CHECKLOCKTIMEVERIFY DROP followed by an ordinary pay-to-public-key-hash check, which nobody can spend before the expiry.

    Quoted source text (2)

    With the following scriptPubKey, nobody will be able to spend the encumbered output until the provided expiry time.

    BIP 65, lines 183–187

    <expiry time> CHECKLOCKTIMEVERIFY DROP DUP HASH160 <pubKeyHash> EQUALVERIFY CHECKSIG

    BIP 65, line 187
  22. ↩ a b c Rule Only 16 bits are interpreted: a 0x0000ffff mask MUST be applied, leaving the other bits for future expansion.

    Quoted source text (2)

    This specification only interprets 16 bits of the sequence number as relative lock-time, so a mask of 0x0000ffff MUST be applied to the sequence field to extract the relative lock-time. The 16-bit specification allows for a year of relative lock-time and the remaining bits allow for future expansion.

    BIP 68, line 40

    Additionally, this BIP specifies only 16 bits to actually encode relative lock-time meaning a further 6 are unused (1 << 16 through 1 << 21 inclusive).

    BIP 68, lines 236–238
  23. ↩ a b Rule BIP 68 repurposes nSequence, whose only use in Bitcoin Core until then was disabling nLockTime checks (a use the BIP preserves).

    Quoted source text (2)

    nSequence will be repurposed to prevent mining of a transaction until a certain age of the spent output in blocks or timespan.

    BIP 68, line 22

    The only use of sequence numbers by the Bitcoin Core reference client software is to disable checking the nLockTime constraints in a transaction. The semantics of that application are preserved by this BIP.

    BIP 68, line 234
  24. ↩ Author’s rationale The authors chose 512-second granularity because blocks come every 600 seconds on average, so either unit covers about the same span with the same bits.

    Quoted source text (1)

    For time based relative lock-time, 512 second granularity was chosen because bitcoin blocks are generated every 600 seconds. So when using block-based or time-based, the same amount of time can be encoded with the available number of bits.

    BIP 68, line 44
  25. ↩ Rule The rules do not apply to the coinbase input's nSequence.

    Quoted source text (1)

    The new rules are not applied to the nSequence field of the input of the coinbase transaction.

    BIP 68, line 53
  26. ↩ Author’s rationale BIP 112's escrow example: a 2-of-3 branch any time, or Alice alone after 30 days; the clock starts only when the payment to the escrow confirms.

    Quoted source text (2)

    An escrow that times out automatically 30 days after being funded can be established in the following way. Alice, Bob and Escrow create a 2-of-3 address with the following redeemscript.

    BIP 112, lines 59–61

    At any time funds can be spent using signatures from any two of Alice, Bob or the Escrow. After 30 days Alice can sign alone. The clock does not start ticking until the payment to the escrow address confirms.

    BIP 112, lines 70–76
  27. ↩ Author’s rationale BIP 112 argues relative locks suit payment channels: the clock starts when a transaction confirms, giving a predictable time to respond, while an absolute deadline forces channels to close before it.

    Quoted source text (1)

    Scriptable relative locktime provides a predictable amount of time to respond in the event a counterparty broadcasts a revoked transaction: Absolute locktime necessitates closing the channel and reopen it when getting close to the timeout, whereas with relative locktime, the clock starts ticking the moment the transactions confirms in a block.

    BIP 112, lines 105–111
  28. ↩ a b Author’s rationale The authors' reason: block timestamps are not strictly ordered, so miners had an incentive to lie about time to include not-yet-mature transactions and collect their fees.

    Quoted source text (1)

    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.

    BIP 113, lines 24–30
  29. ↩ Rule BIP 113's rule applies to all transactions, including the coinbase.

    Quoted source text (1)

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

    BIP 113, line 69
  30. ↩ Author’s rationale The authors expected transactions using time-based lock-time to confirm about an hour later than under the old rules.

    Quoted source text (1)

    Transactions generated using time-based lock-time will take approximately an hour longer to confirm than would be expected under the old rules.

    BIP 113, lines 101–103
  31. ↩ History BIP 65 (OP_CHECKLOCKTIMEVERIFY) was assigned in 2014, BIPs 68, 112 and 113 in 2015; all four are consensus soft forks recorded as Deployed.

    Quoted source text (7)

    Layer: Consensus (soft fork) Title: OP_CHECKLOCKTIMEVERIFY Authors: Peter Todd <pete@petertodd.org> Status: Deployed Type: Specification Assigned: 2014-10-01

    BIP 65, lines 3–8

    Layer: Consensus (soft fork) Title: Relative lock-time using consensus-enforced sequence numbers

    BIP 68, lines 3–11

    Status: Deployed Type: Specification Assigned: 2015-05-28

    BIP 68, lines 9–11

    Layer: Consensus (soft fork) Title: CHECKSEQUENCEVERIFY

    BIP 112, lines 3–10

    Status: Deployed Type: Specification Assigned: 2015-08-10

    BIP 112, lines 8–10

    Layer: Consensus (soft fork) Title: Median time-past as endpoint for lock-time calculations

    BIP 113, lines 3–9

    Status: Deployed Type: Specification Assigned: 2015-08-10

    BIP 113, lines 7–9
  32. ↩ History BIP 65 activated by the IsSuperMajority mechanism for version-4 blocks: enforced when 750 of the previous 1,000 blocks signalled, and lower versions rejected at 950.

    Quoted source text (1)

    The new rules are in effect for every block (at height H) with nVersion = 4 and at least 750 out of 1000 blocks preceding it (with heights H-1000..H-1) also have nVersion >= 4. Furthermore, when 950 out of the 1000 blocks preceding a block do have nVersion >= 4, nVersion < 4 blocks become invalid

    BIP 65, lines 281–287
  33. ↩ History BIPs 68, 112 and 113 were to deploy together through BIP 9 using bit 0, with a mainnet start time of midnight 1 May 2016 UTC.

    Quoted source text (2)

    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

    BIP 68, lines 224–226

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

    BIP 112, line 353