Home › Glossary › OP_CHECKLOCKTIMEVERIFY (CLTV)

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.

BIPs that define OP_CHECKLOCKTIMEVERIFY (CLTV)

  • BIP 65: OP_CHECKLOCKTIMEVERIFY: Deployed. Adds OP_CHECKLOCKTIMEVERIFY, a script command that keeps coins unspendable until a chosen date or block height. It enables time-locked savings, escrow with deadlines, and payment channels such as…
  • BIP 113: Median time-past as endpoint for lock-time calculations: Deployed. Changes how Bitcoin measures time for timelocked transactions, using the median time of the previous 11 blocks instead of a single block's timestamp. Because this value only moves forward, miners…
  • BIP 46: Address Scheme for Timelocked Fidelity Bonds: Draft. Defines how HD wallets create time-locked addresses for "fidelity bonds," where coins are locked for a period to prove a costly commitment. Such bonds can help resist fake identities in systems like…

Related terms

  • OP_CHECKSEQUENCEVERIFY (CSV): OP_CHECKSEQUENCEVERIFY (CSV, BIP 112) is an opcode that blocks spending an output until it has aged a set number of blocks or time since it confirmed.
  • Timelock: A timelock is a rule that stops bitcoin from being spent until a set block height or time, or until the coin has aged a set amount since it confirmed.
  • HTLC: An HTLC (hashed time-locked contract) pays whoever reveals a secret before a deadline and refunds the sender after it; Lightning routes payments with them.
  • Opcode: An opcode is a one-byte instruction in Bitcoin Script, such as OP_CHECKSIG (0xac) or OP_RETURN (0x6a), that pushes data or acts on the stack.

Learn more

Guides