OP_CHECKLOCKTIMEVERIFY (CLTV)
Also called: CLTV, OP_CLTV, CHECKLOCKTIMEVERIFY, OP_NOP2, BIP 65, absolute timelock.
OP_CHECKLOCKTIMEVERIFY (CLTV, BIP 65) is an opcode that keeps an output unspendable until a chosen block height or time: an absolute timelock.
OP_CHECKLOCKTIMEVERIFY (CLTV) is a Bitcoin Script opcode that makes an output unspendable until a given block height or time. Peter Todd specified it in BIP 65, and it activated as a soft fork at block 388,381 in December 2015. It reuses the do-nothing opcode OP_NOP2 (0xb1), so old nodes still accept scripts that contain it.
How CLTV works
CLTV doesn't read the clock itself. It compares the number on top of the stack with the spending transaction's nLockTime field, which consensus already enforces. The script fails if:
- the stack is empty or the top item is negative;
- the top item and nLockTime are different kinds (block heights are below 500,000,000, Unix times above);
- the top item is greater than nLockTime; or
- the input's nSequence is 0xffffffff, which would disable nLockTime.
So only a transaction that is itself locked until at least that point can pass CLTV, and it can't be mined before then. CLTV leaves its argument on the stack, hence the usual pattern:
<expiry> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG
Time-based values are compared against median time past (BIP 113).
What CLTV is used for
BIP 65 lists escrow with a delayed backup key, non-interactive refunds for payment channels and two-factor wallets. CLTV now appears in HTLCs for Lightning payments, in inheritance and recovery paths, and in timelocked fidelity bonds (BIP 46).
For a lock that starts counting when the coin confirms, use OP_CHECKSEQUENCEVERIFY instead. See BIP 65 vs BIP 112 and the timelock overview.