OP_CHECKLOCKTIMEVERIFY (OP_CLTV)

A script condition that forbids spending until a height or time is reached.

Basically

OP_CHECKLOCKTIMEVERIFY is a Bitcoin rule that locks funds until a set block number or time. You cannot spend the funds before then.

Key Takeaways

  • OP_CHECKLOCKTIMEVERIFY (OP_CLTV) is a Bitcoin Script opcode that enforces absolute timelocks. It prevents a UTXO from being spent until a specific block height or Unix timestamp has passed.
  • BIP 65 defined OP_CLTV, which activated in December 2015. OP_CLTV compares a value on the script stack with the spending transaction's nLockTime field, and the script fails and rejects the spend if the transaction's lock time has not reached the required threshold.
  • OP_CLTV is a foundational building block for HTLCs, time-locked savings, inheritance contracts and the Lightning Network's security model. It enforces payment expiry deadlines across multi-hop routes.

What Is OP_CHECKLOCKTIMEVERIFY?

OP_CHECKLOCKTIMEVERIFY, commonly abbreviated OP_CLTV, is a Bitcoin consensus opcode that creates absolute timelocks on transaction outputs. A script containing it guarantees that the output cannot be spent until a specified point in time, either a particular block height or a Unix timestamp. The network rejects any transaction that tries to spend the output before that point because it is invalid.

OP_CLTV was introduced in BIP 65, authored by Peter Todd, and activated on Bitcoin mainnet at block 388,381 on December 14, 2015. It replaced the previously unused OP_NOP2 opcode, opcode number 177 / 0xb1. The upgrade was a soft fork because older nodes that had not upgraded treated the byte as a harmless no-op, while upgraded nodes enforced the new timelock semantics.

Bitcoin's nLockTime field could restrict when a transaction was valid before OP_CLTV, but no script-level mechanism could restrict when a specific output could be spent. OP_CLTV bridges this gap by letting scripts encode time-based spending conditions directly into the output.

How It Works

OP_CLTV reads the top value from the script stack and compares it with the nLockTime field of the transaction attempting to spend the output. The opcode leaves that value on the stack after execution rather than consuming it, so scripts typically follow OP_CLTV with OP_DROP.

The opcode runs four checks in order. The script stops and the transaction becomes invalid if any check fails:

The 500,000,000 Threshold

Bitcoin uses one nLockTime field for two different purposes. The LOCKTIME_THRESHOLD constant of 500,000,000 separates them:

OP_CLTV requires the script's required value and the transaction's nLockTime to use the same interpretation. You cannot lock an output to a block height and then spend it with a timestamp-based nLockTime, or vice versa.

Script Example

A basic time-locked output script prevents spending until block 900,000. The script sets that limit directly:

OP_DROP follows OP_CLTV to remove the lock time value from the stack. The remaining script, a standard P2PKH check, can then execute cleanly.

OP_CLTV vs OP_CSV

Bitcoin has two timelock opcodes with complementary purposes. OP_CHECKSEQUENCEVERIFY (OP_CSV), defined in BIP 112 and activated in May 2016, enforces relative timelocks rather than absolute ones.

The distinction matters in practice because OP_CLTV sets a fixed deadline that never changes, regardless of when the UTXO was created. OP_CSV starts its timer when the UTXO confirms on-chain, which suits protocols such as payment channels where the clock should start only after a specific transaction confirms. Many protocols use both opcodes together, with CLTV for payment expiry and CSV for revocation delays.

The research article on Bitcoin timelocks: CLTV and CSV provides a detailed comparison of both opcodes and their protocol interactions. The comparison explains how each opcode behaves and how protocols use them.

Time-Locked Savings

OP_CLTV can make funds provably unspendable until a chosen date, which enforces HODLing. You can send Bitcoin to a script that locks the output until a future block height. The funds then stay locked even if someone steals the private key, which suits long-term savings, vesting schedules and cold storage with time-based access controls.

HTLC Refund Paths

Hashed Time-Locked Contracts are the core mechanism behind Lightning Network payments and cross-chain atomic swaps. Every HTLC has two spending paths:

OP_CLTV provides the trustless guarantee that a sender can recover funds from an unclaimed HTLC. The absolute timelock makes the refund path available after a fixed block height, regardless of the recipient's cooperation.

Inheritance and Dead Man's Switch

OP_CLTV can make an heir's key valid only after a prolonged period. The owner periodically moves funds to a new UTXO with a fresh lock time to reset the deadline, so the heir can claim the funds after the timelock expires if the owner stops refreshing because of death or incapacitation. OP_CSV relative timelocks often suit dead man's switch patterns better because their timer resets automatically on each spend.

Escrow with Timeout

OP_CLTV allows multi-party escrow scripts with a timeout fallback. A 2-of-2 multisig between a buyer and seller can, for example, include a third-party arbitrator key that activates only after a CLTV expiry. The arbitrator can step in after the timeout to resolve the dispute if the buyer and seller cannot agree.

Role in Lightning Network Security

OP_CLTV is fundamental to the Lightning Network's routing security. Each HTLC in a multi-hop payment carries an absolute block height expiry enforced by OP_CLTV, and these expiry values decrease at each hop: the sender's HTLC expires later than the next node's, which expires later than the next, and so on to the final recipient.

The decreasing chain of timelocks keeps the route safe. Each routing node has a buffer of blocks, called cltv_expiry_delta and typically 40 blocks or roughly 6.7 hours, between the expiry of its outgoing HTLC and the expiry of its incoming HTLC. The routing node still has enough time to claim its incoming HTLC before expiry if a downstream node settles an HTLC on-chain at the last possible moment.

OP_CLTV stops a malicious node from holding an HTLC indefinitely and locking liquidity across the entire route by enforcing absolute deadlines. The timelock guarantees that funds always return to the sender if payment fails, making trustless multi-hop routing possible. OP_CSV handles the separate concern of revocation delays after a force-close, giving watchtowers time to detect and penalise cheating attempts through justice transactions.

Why It Matters

OP_CLTV gave Bitcoin output-level time constraints embedded directly in Script, rather than only transaction-level timelocks. Before BIP 65, nLockTime could delay when a transaction was valid, but nothing stopped an output from being spent by a different transaction without a timelock. OP_CLTV closes that gap by making the timelock part of the spending condition itself.

OP_CLTV enabled a class of trustless protocols. HTLCs rely on OP_CLTV for their refund mechanism and underpin the Lightning Network, atomic swaps and submarine swaps. Layer 2 protocols such as Spark also benefit from the wider ecosystem of timelock-based constructions that OP_CLTV enabled, because timelocks are a core primitive for securing off-chain state transitions and ensuring users can always recover their funds on-chain.

Irreversible Lock Periods

Funds sent to a CLTV-locked output cannot be spent before the specified time, even if circumstances change. A script that locks funds until block 1,000,000 is absolute, and no key, signature or protocol upgrade can override the timelock. You must choose lock times carefully because mistakes, such as locking funds to a block height decades in the future, are permanent.

Clock Skew with Timestamps

Unix timestamps make the effective unlock time depend on miners' block timestamps, which may deviate from real-world time within certain bounds. The median time past (MTP) rule means the actual unlock time can differ from the wall-clock expectation by up to a few hours. Block heights are generally more predictable than timestamps for precision-sensitive applications.

Transaction Size Overhead

OP_CLTV adds bytes to the script: typically 4-5 bytes for the lock time value, plus 1 byte for the opcode and 1 byte for OP_DROP. Standard single-condition scripts have minimal overhead, but complex scripts with multiple branches and timelocks produce larger transactions and higher fees. Taproot and Miniscript can reduce this effect in modern constructions by hiding unused script branches.

No Cancellation Mechanism

OP_CLTV is a one-way constraint that enforces a minimum time before spending but cannot impose a maximum. Bitcoin has no native "spend only before block N" opcode. Protocols that need expiry windows, meaning spending between time A and time B, must set the upper bound through other means, such as pre-signed transactions or relative timelocks with OP_CSV.

The glossary entry is for informational purposes only and does not constitute financial or investment advice. You should always do your own research before using any protocol or technology.

0

← All 1876 glossary terms