OP_CHECKLOCKTIMEVERIFY
INFO
Opcode number: 177
Byte representation: 0xb1
Short description: Prevent a transaction input from being spent until a specified absolute time or block height.
OP_CHECKLOCKTIMEVERIFY
(CLTV
) allows a script to require that the current transaction's locktime (nLockTime) be greater than or equal to a specified value on the stack. This enables time-based spending conditions, such as "can't be spent until block 700000" or "not before a certain UNIX timestamp."
When OP_CLTV
is encountered, it does not consume the value on the stack but instead checks whether the transaction's locktime satisfies the condition. If it does not, the script fails.
Operation
- Peek at the top stack item (do not remove it).
- Interpret it as an integer (locktime).
- Check if the transaction’s nLockTime is greater than or equal to this value.
- Also check that the transaction’s nLockTime and the stack locktime are of the same type:
- both block heights (less than 500000000), or
- both timestamps (≥ 500000000)
- If all conditions pass, continue execution.
- If any condition fails, the script fails immediately.
Notes
- OP_CLTV does not remove the top item from the stack.
OP_CHECKLOCKTIMEVERIFY
is implemented by reinterpreting the existingOP_NOP2
opcode (0xb1
). Older clients treat this byte as a no-op, while upgraded clients enforce the locktime condition. This made theCLTV
upgrade a soft fork.- Requires the transaction's input to set the
nSequence
field below0xffffffff
to makenLockTime
active. - Commonly used for delayed spending, covenants, and vault constructions.
Example
Simple timelock that prevents spending before block 800000.
shell
# ASM script
OP_PUSHBYTES_3 00350c OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG
# Raw script (simplified)
03 00350c b1 75 <pubkey> ac
# Transaction nLockTime
800000 or higher -> passes
Less than 800000 -> fails