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 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
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
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
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
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
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.
But nothing about the coin stops another signed transaction, with no lock at all, from spending it now.
BIP 65 puts the condition in the coin’s own script: OP_CHECKLOCKTIMEVERIFY fails any spend whose nLockTime is too early.
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
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.
Height lock, argument equals nLockTime: every check passes and the script continues. Bitcoin Core labels it valid; the model agrees.
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.
Height lock, argument equals nLockTime, with nLockTime + 1: fails at “Argument and nLockTime are the same kind”. Not a Core test case: the tested model's verdict.
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· 500,000,000 - 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: no
- argument is a height, nLockTime 500,000,000 is a time
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.
Height lock, argument equals nLockTime, with input made final: fails at “This input is not final”. Not a Core test case: the tested model's verdict.
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 ·
0xffffffff· 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: no
- nSequence 0xffffffff would switch nLockTime off
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.
Time lock, argument equals nLockTime: every check passes and the script continues. Bitcoin Core labels it valid; the model agrees.
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
500000000 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 500,000,000 - The stack is not empty: yes
- top item: 500,000,000
- The argument is not negative: yes
- 500,000,000 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a time, nLockTime 500,000,000 is a time
- The argument is not greater than nLockTime: yes
- 500,000,000 ≤ 500,000,000
- This input is not final: yes
- nSequence 0x00000000
Bitcoin Core v29.0 tx_valid.json, entry 102 (Core’s comment for its group: “By-time locks, with argument just beyond tx nLockTime (but within numerical boundaries)”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Time lock, argument equals nLockTime, with nLockTime + 1: every check passes and the script continues. Not a Core test case: the tested model's verdict.
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
500000000 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 500,000,001 - The stack is not empty: yes
- top item: 500,000,000
- The argument is not negative: yes
- 500,000,000 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a time, nLockTime 500,000,001 is a time
- The argument is not greater than nLockTime: yes
- 500,000,000 ≤ 500,000,001
- This input is not final: yes
- nSequence 0x00000000
Bitcoin Core v29.0 tx_valid.json, entry 102 (Core’s comment for its group: “By-time locks, with argument just beyond tx nLockTime (but within numerical boundaries)”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Time lock, argument equals nLockTime, with input made final: fails at “This input is not final”. Not a Core test case: the tested model's verdict.
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
500000000 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0xffffffff· 500,000,000 - The stack is not empty: yes
- top item: 500,000,000
- The argument is not negative: yes
- 500,000,000 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a time, nLockTime 500,000,000 is a time
- The argument is not greater than nLockTime: yes
- 500,000,000 ≤ 500,000,000
- This input is not final: no
- nSequence 0xffffffff would switch nLockTime off
Bitcoin Core v29.0 tx_valid.json, entry 102 (Core’s comment for its group: “By-time locks, with argument just beyond tx nLockTime (but within numerical boundaries)”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Height lock, argument one block too late: fails at “The argument is not greater than nLockTime”. Bitcoin Core labels it invalid; the model agrees.
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,998 - 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,998 is a height
- The argument is not greater than nLockTime: no
- 499,999,999 > 499,999,998
Bitcoin Core v29.0 tx_invalid.json, entry 68 (Core’s comment for its group: “By-height locks, with argument just beyond tx nLockTime”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Height lock, argument one block too late, with nLockTime + 1: every check passes and the script continues. Not a Core test case: the tested model's verdict.
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_invalid.json, entry 68 (Core’s comment for its group: “By-height locks, with argument just beyond tx nLockTime”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Height lock, argument one block too late, with input made final: fails at “The argument is not greater than nLockTime”. Not a Core test case: the tested model's verdict.
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 ·
0xffffffff· 499,999,998 - 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,998 is a height
- The argument is not greater than nLockTime: no
- 499,999,999 > 499,999,998
Bitcoin Core v29.0 tx_invalid.json, entry 68 (Core’s comment for its group: “By-height locks, with argument just beyond tx nLockTime”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
A time argument against a height nLockTime: fails at “Argument and nLockTime are the same kind”. Bitcoin Core labels it invalid; the model agrees.
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
500000000 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 499,999,999 - The stack is not empty: yes
- top item: 500,000,000
- The argument is not negative: yes
- 500,000,000 ≥ 0
- Argument and nLockTime are the same kind: no
- argument is a time, nLockTime 499,999,999 is a height
Bitcoin Core v29.0 tx_invalid.json, entry 90 (Core’s comment for its group: “Argument/tx height/time mismatch, both versions”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
A time argument against a height nLockTime, with nLockTime + 1: every check passes and the script continues. Not a Core test case: the tested model's verdict.
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
500000000 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 500,000,000 - The stack is not empty: yes
- top item: 500,000,000
- The argument is not negative: yes
- 500,000,000 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a time, nLockTime 500,000,000 is a time
- The argument is not greater than nLockTime: yes
- 500,000,000 ≤ 500,000,000
- This input is not final: yes
- nSequence 0x00000000
Bitcoin Core v29.0 tx_invalid.json, entry 90 (Core’s comment for its group: “Argument/tx height/time mismatch, both versions”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
A time argument against a height nLockTime, with input made final: fails at “Argument and nLockTime are the same kind”. Not a Core test case: the tested model's verdict.
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
500000000 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0xffffffff· 499,999,999 - The stack is not empty: yes
- top item: 500,000,000
- The argument is not negative: yes
- 500,000,000 ≥ 0
- Argument and nLockTime are the same kind: no
- argument is a time, nLockTime 499,999,999 is a height
Bitcoin Core v29.0 tx_invalid.json, entry 90 (Core’s comment for its group: “Argument/tx height/time mismatch, both versions”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
The input is final: fails at “This input is not final”. Bitcoin Core labels it invalid; the model agrees.
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
0 OP_CHECKLOCKTIMEVERIFY 1- nVersion · input 0 nSequence · nLockTime
- 1 ·
0xffffffff· 0 - The stack is not empty: yes
- top item: 0
- The argument is not negative: yes
- 0 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a height, nLockTime 0 is a height
- The argument is not greater than nLockTime: yes
- 0 ≤ 0
- This input is not final: no
- nSequence 0xffffffff would switch nLockTime off
Bitcoin Core v29.0 tx_invalid.json, entry 81 (Core’s comment for its group: “Input locked”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
The input is final, with nLockTime + 1: fails at “This input is not final”. Not a Core test case: the tested model's verdict.
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
0 OP_CHECKLOCKTIMEVERIFY 1- nVersion · input 0 nSequence · nLockTime
- 1 ·
0xffffffff· 1 - The stack is not empty: yes
- top item: 0
- The argument is not negative: yes
- 0 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a height, nLockTime 1 is a height
- The argument is not greater than nLockTime: yes
- 0 ≤ 1
- This input is not final: no
- nSequence 0xffffffff would switch nLockTime off
Bitcoin Core v29.0 tx_invalid.json, entry 81 (Core’s comment for its group: “Input locked”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
The input is final, with input made non-final: every check passes and the script continues. Not a Core test case: the tested model's verdict.
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
0 OP_CHECKLOCKTIMEVERIFY 1- nVersion · input 0 nSequence · nLockTime
- 1 ·
0xfffffffe· 0 - The stack is not empty: yes
- top item: 0
- The argument is not negative: yes
- 0 ≥ 0
- Argument and nLockTime are the same kind: yes
- argument is a height, nLockTime 0 is a height
- The argument is not greater than nLockTime: yes
- 0 ≤ 0
- This input is not final: yes
- nSequence 0xfffffffe
Bitcoin Core v29.0 tx_invalid.json, entry 81 (Core’s comment for its group: “Input locked”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
A negative argument: fails at “The argument is not negative”. Bitcoin Core labels it invalid; the model agrees.
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
-1 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 0 - The stack is not empty: yes
- top item: -1
- The argument is not negative: no
- -1 < 0
Bitcoin Core v29.0 tx_invalid.json, entry 76 (Core’s comment for its group: “Argument negative with by-blockheight nLockTime=0”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
A negative argument, with nLockTime + 1: fails at “The argument is not negative”. Not a Core test case: the tested model's verdict.
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
-1 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 1 - The stack is not empty: yes
- top item: -1
- The argument is not negative: no
- -1 < 0
Bitcoin Core v29.0 tx_invalid.json, entry 76 (Core’s comment for its group: “Argument negative with by-blockheight nLockTime=0”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
A negative argument, with input made final: fails at “The argument is not negative”. Not a Core test case: the tested model's verdict.
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
-1 OP_CHECKLOCKTIMEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0xffffffff· 0 - The stack is not empty: yes
- top item: -1
- The argument is not negative: no
- -1 < 0
Bitcoin Core v29.0 tx_invalid.json, entry 76 (Core’s comment for its group: “Argument negative with by-blockheight nLockTime=0”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Block lock, argument equals the input's lock: every check passes and the script continues. Bitcoin Core labels it valid; the model agrees.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
65535 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x0000ffff· 0 - The stack is not empty: yes
- top item: 65,535
- The argument is not negative: yes
- 65,535 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: yes
- nSequence 0x0000ffff: bit 31 clear
- Argument and nSequence use the same unit: yes
- argument counts blocks, nSequence counts blocks
- Masked argument is not greater than masked nSequence: yes
- 65,535 ≤ 65,535 (blocks)
Bitcoin Core v29.0 tx_valid.json, entry 122 (Core’s comment for its group: “By-height locks, with argument == 0 and == txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Block lock, argument equals the input's lock, with version 1: fails at “Transaction version is at least 2”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
65535 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x0000ffff· 0 - The stack is not empty: yes
- top item: 65,535
- The argument is not negative: yes
- 65,535 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: no
- version 1
Bitcoin Core v29.0 tx_valid.json, entry 122 (Core’s comment for its group: “By-height locks, with argument == 0 and == txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Block lock, argument equals the input's lock, with the input's bit 31 set: fails at “The input's disable flag is clear”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
65535 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x8000ffff· 0 - The stack is not empty: yes
- top item: 65,535
- The argument is not negative: yes
- 65,535 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: no
- nSequence 0x8000ffff: bit 31 set
Bitcoin Core v29.0 tx_valid.json, entry 122 (Core’s comment for its group: “By-height locks, with argument == 0 and == txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Time lock, argument equals the input's lock: every check passes and the script continues. Bitcoin Core labels it valid; the model agrees.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
4259839 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x0040ffff· 0 - The stack is not empty: yes
- top item: 4,259,839
- The argument is not negative: yes
- 4,259,839 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: yes
- nSequence 0x0040ffff: bit 31 clear
- Argument and nSequence use the same unit: yes
- argument counts time, nSequence counts time
- Masked argument is not greater than masked nSequence: yes
- 65,535 ≤ 65,535 (units of 512 s)
Bitcoin Core v29.0 tx_valid.json, entry 127 (Core’s comment for its group: “By-time locks, with argument == 0 and == txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Time lock, argument equals the input's lock, with version 1: fails at “Transaction version is at least 2”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
4259839 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x0040ffff· 0 - The stack is not empty: yes
- top item: 4,259,839
- The argument is not negative: yes
- 4,259,839 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: no
- version 1
Bitcoin Core v29.0 tx_valid.json, entry 127 (Core’s comment for its group: “By-time locks, with argument == 0 and == txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Time lock, argument equals the input's lock, with the input's bit 31 set: fails at “The input's disable flag is clear”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
4259839 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x8040ffff· 0 - The stack is not empty: yes
- top item: 4,259,839
- The argument is not negative: yes
- 4,259,839 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: no
- nSequence 0x8040ffff: bit 31 set
Bitcoin Core v29.0 tx_valid.json, entry 127 (Core’s comment for its group: “By-time locks, with argument == 0 and == txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Argument with the disable flag set: the argument's disable flag is set, so the opcode does nothing and the script continues. Bitcoin Core labels it valid; the model agrees.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
2147483648 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x80000000· 0 - The stack is not empty: yes
- top item: 2,147,483,648
- The argument is not negative: yes
- 2,147,483,648 ≥ 0
- The argument's disable flag is set: no lock: yes
- bit 31 is set, so the opcode does nothing (left for future soft forks)
Bitcoin Core v29.0 tx_valid.json, entry 131 (Core’s comment for its group: “Upper sequence with upper sequence is fine”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Argument with the disable flag set, with version 1: the argument's disable flag is set, so the opcode does nothing and the script continues. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
2147483648 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x80000000· 0 - The stack is not empty: yes
- top item: 2,147,483,648
- The argument is not negative: yes
- 2,147,483,648 ≥ 0
- The argument's disable flag is set: no lock: yes
- bit 31 is set, so the opcode does nothing (left for future soft forks)
Bitcoin Core v29.0 tx_valid.json, entry 131 (Core’s comment for its group: “Upper sequence with upper sequence is fine”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Argument with the disable flag set, with the input's bit 31 cleared: the argument's disable flag is set, so the opcode does nothing and the script continues. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
2147483648 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x00000000· 0 - The stack is not empty: yes
- top item: 2,147,483,648
- The argument is not negative: yes
- 2,147,483,648 ≥ 0
- The argument's disable flag is set: no lock: yes
- bit 31 is set, so the opcode does nothing (left for future soft forks)
Bitcoin Core v29.0 tx_valid.json, entry 131 (Core’s comment for its group: “Upper sequence with upper sequence is fine”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Block lock, one block short: fails at “Masked argument is not greater than masked nSequence”. Bitcoin Core labels it invalid; the model agrees.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
1 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x00000000· 0 - The stack is not empty: yes
- top item: 1
- The argument is not negative: yes
- 1 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: yes
- nSequence 0x00000000: bit 31 clear
- Argument and nSequence use the same unit: yes
- argument counts blocks, nSequence counts blocks
- Masked argument is not greater than masked nSequence: no
- 1 > 0 (blocks)
Bitcoin Core v29.0 tx_invalid.json, entry 105 (Core’s comment for its group: “By-height locks, with argument just beyond txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Block lock, one block short, with version 1: fails at “Transaction version is at least 2”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
1 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 0 - The stack is not empty: yes
- top item: 1
- The argument is not negative: yes
- 1 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: no
- version 1
Bitcoin Core v29.0 tx_invalid.json, entry 105 (Core’s comment for its group: “By-height locks, with argument just beyond txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Block lock, one block short, with the input's bit 31 set: fails at “The input's disable flag is clear”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
1 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x80000000· 0 - The stack is not empty: yes
- top item: 1
- The argument is not negative: yes
- 1 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: no
- nSequence 0x80000000: bit 31 set
Bitcoin Core v29.0 tx_invalid.json, entry 105 (Core’s comment for its group: “By-height locks, with argument just beyond txin.nSequence”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Blocks against a time-based input: fails at “Argument and nSequence use the same unit”. Bitcoin Core labels it invalid; the model agrees.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
65535 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x00400000· 0 - The stack is not empty: yes
- top item: 65,535
- The argument is not negative: yes
- 65,535 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: yes
- nSequence 0x00400000: bit 31 clear
- Argument and nSequence use the same unit: no
- argument counts blocks, nSequence counts time
Bitcoin Core v29.0 tx_invalid.json, entry 118 (Core’s comment for its group: “Argument/tx height/time mismatch, both versions”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Blocks against a time-based input, with version 1: fails at “Transaction version is at least 2”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
65535 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00400000· 0 - The stack is not empty: yes
- top item: 65,535
- The argument is not negative: yes
- 65,535 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: no
- version 1
Bitcoin Core v29.0 tx_invalid.json, entry 118 (Core’s comment for its group: “Argument/tx height/time mismatch, both versions”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Blocks against a time-based input, with the input's bit 31 set: fails at “The input's disable flag is clear”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
65535 OP_CHECKSEQUENCEVERIFY- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x80400000· 0 - The stack is not empty: yes
- top item: 65,535
- The argument is not negative: yes
- 65,535 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: no
- nSequence 0x80400000: bit 31 set
Bitcoin Core v29.0 tx_invalid.json, entry 118 (Core’s comment for its group: “Argument/tx height/time mismatch, both versions”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Version 1 transaction: fails at “Transaction version is at least 2”. Bitcoin Core labels it invalid; the model agrees.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
0 OP_CHECKSEQUENCEVERIFY 1- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x00000000· 0 - The stack is not empty: yes
- top item: 0
- The argument is not negative: yes
- 0 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: no
- version 1
Bitcoin Core v29.0 tx_invalid.json, entry 128 (Core’s comment for its group: “Failure due to insufficient tx.version (<2)”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Version 1 transaction, with version 2: every check passes and the script continues. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
0 OP_CHECKSEQUENCEVERIFY 1- nVersion · input 0 nSequence · nLockTime
- 2 ·
0x00000000· 0 - The stack is not empty: yes
- top item: 0
- The argument is not negative: yes
- 0 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: yes
- version 2
- The input's disable flag is clear: yes
- nSequence 0x00000000: bit 31 clear
- Argument and nSequence use the same unit: yes
- argument counts blocks, nSequence counts blocks
- Masked argument is not greater than masked nSequence: yes
- 0 ≤ 0 (blocks)
Bitcoin Core v29.0 tx_invalid.json, entry 128 (Core’s comment for its group: “Failure due to insufficient tx.version (<2)”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
Version 1 transaction, with the input's bit 31 set: fails at “Transaction version is at least 2”. Not a Core test case: the tested model's verdict.
For a block-based relative lock, start at the coin’s confirmation height. For a time-based lock, start at the MTP before confirmation and compare it with the candidate block’s parent MTP. BIP 68 applies only with transaction version 2 or higher and the input’s disable flag clear.
Exact checks and fields
- Locking script
0 OP_CHECKSEQUENCEVERIFY 1- nVersion · input 0 nSequence · nLockTime
- 1 ·
0x80000000· 0 - The stack is not empty: yes
- top item: 0
- The argument is not negative: yes
- 0 ≥ 0
- The argument's disable flag is clear: yes
- bit 31 is clear
- Transaction version is at least 2: no
- version 1
Bitcoin Core v29.0 tx_invalid.json, entry 128 (Core’s comment for its group: “Failure due to insufficient tx.version (<2)”), pinned by commit and hash; one-input transactions with no signatures. Every check run by the tested model at build time.
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
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
The stack is not empty: top item: 4,259,839. ✓
The argument is not negative: 4,259,839 ≥ 0. ✓
The argument's disable flag is clear: bit 31 is clear. ✓
Transaction version is at least 2: version 2. ✓
The input's disable flag is clear: nSequence 0x0040ffff: bit 31 clear. ✓
Argument and nSequence use the same unit: argument counts time, nSequence counts time. ✓
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.
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
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.
-
↩ 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.
CHECKLOCKTIMEVERIFY redefines the existing NOP2 opcode.
-
↩ 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.
CHECKSEQUENCEVERIFY redefines the existing NOP3 opcode.
-
↩ 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.
BIP 68 L51 BIP 68 L46 BIP 68 L47–49
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.
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
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.
-
↩ 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.
-
↩ 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.
-
↩ 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);
-
↩ 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
-
↩ 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.
-
↩ 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);
-
↩ 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.
-
↩ 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.
-
↩ 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.
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.
-
↩ 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.
Setting nSequence to this value for every input in a transaction * disables nLockTime. */ static const uint32_t SEQUENCE_FINAL = 0xffffffff;
-
↩ 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.
BIP 143 L184 BIP 174 L619 BIP 174 L833
Quoted source text (3)
nLockTime: 11000000
0200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf6
0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd75
-
↩ 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
-
↩ 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.
-
↩ 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.
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.
-
↩ 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.
-
↩ 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.
This BIP proposes that after activation calls to IsFinalTx() within consensus code use the return value of `GetMedianTimePast(pindexPrev)` instead.
-
↩ 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.
-
↩ 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.
<expiry time> CHECKLOCKTIMEVERIFY DROP DUP HASH160 <pubKeyHash> EQUALVERIFY CHECKSIG
-
↩ 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.
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).
-
↩ 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.
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.
-
↩ 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.
-
↩ 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.
-
↩ 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.
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.
-
↩ 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.
-
↩ 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.
-
↩ 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.
-
↩ 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.
-
↩ 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.
BIP 65 L3–8 BIP 68 L3–11 BIP 68 L9–11 BIP 112 L3–10 BIP 112 L8–10 BIP 113 L3–9 BIP 113 L7–9
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
Layer: Consensus (soft fork) Title: Relative lock-time using consensus-enforced sequence numbers
Status: Deployed Type: Specification Assigned: 2015-05-28
Layer: Consensus (soft fork) Title: CHECKSEQUENCEVERIFY
Status: Deployed Type: Specification Assigned: 2015-08-10
Layer: Consensus (soft fork) Title: Median time-past as endpoint for lock-time calculations
Status: Deployed Type: Specification Assigned: 2015-08-10
-
↩ 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
-
↩ 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
This BIP must be deployed simultaneously with BIP68 and BIP113 using the same deployment mechanism.