OP_CHECKSEQUENCEVERIFY (OP_CSV)
A script condition enforcing a relative delay after the input confirmed.
Basically
OP_CHECKSEQUENCEVERIFY (OP_CSV) makes you wait before you can spend Bitcoin. You set the wait as a number of blocks or an amount of time after the funds are confirmed.
Key Takeaways
- OP_CHECKSEQUENCEVERIFY (OP_CSV) enforces relative timelocks in Bitcoin Script. You cannot spend an output until a set number of blocks or time units has passed since that output was confirmed on-chain.
- OP_CSV underpins Lightning Network security by creating the delay window that lets honest parties detect and punish cheating with revocation keys and justice transactions.
- BIP 112 defines OP_CSV, which activated in July 2016. It works with BIP 68, which gives consensus meaning to the nSequence field, and supports block-height-based and time-based modes, with time measured in 512-second intervals.
What Is OP_CHECKSEQUENCEVERIFY?
OP_CHECKSEQUENCEVERIFY (OP_CSV) is a Bitcoin Script opcode that enforces a relative timelock on a transaction output. An absolute timelock locks funds until a specific block height or date, while a relative timelock locks them for a duration measured from the output's confirmation in a block. OP_CSV suits protocols where the confirmation time is unknown in advance, such as Lightning channels.
OP_CSV was introduced in BIP 112, authored by BtcDrak, Mark Friedenbach, and Eric Lombrozo. It activated at block #419,328 on July 4, 2016, in a soft fork that also included BIP 68 for consensus-enforced sequence numbers and BIP 113 for median time-past lock-time evaluation. The opcode redefines the previously unused OP_NOP3 and has opcode value 0xb2.
Before OP_CSV, Bitcoin had only absolute timelocks through OP_CHECKLOCKTIMEVERIFY (BIP 65). Payment channels using absolute timelocks needed a fixed expiry date at channel opening, so channels had to close before the deadline or risk fund theft. OP_CSV removed this limitation by measuring lock durations from confirmation, making it a prerequisite for practical Lightning Network deployment.
How It Works
OP_CSV compares a value on the script stack with the nSequence field of the spending transaction input. Script evaluation fails and the transaction is invalid if the relative lock-time encoded in nSequence has not been satisfied. Execution continues as if a NOP was executed once the condition is met, leaving the stack unchanged.
OP_CSV relies on two companion BIPs working together. BIP 68 gives consensus meaning to nSequence, while BIP 113 supplies median time-past for lock-time evaluation.
The spending transaction must use version 2 or higher. The script fails if the transaction version is less than 2 and the disable flag is not set.
The nSequence Field Encoding
BIP 68 repurposes the 32-bit nSequence field of each transaction input to encode relative lock-time values. You read the field according to its bit layout.
Three constants define the field layout. Together, they describe how you read the flags and relative lock-time value.
Block-Height Mode vs. Time-Based Mode
A block-height lock applies when bit 22, the type flag, is unset. Bits 0 through 15 then encode a number of blocks, and you cannot spend the output until that many blocks have been mined after its confirmation. The range of 0 to 65,535 blocks allows relative locks of up to approximately 455 days at 10 minutes per block.
A time-based lock applies when bit 22 is set, with bits 0 through 15 encoding a number of 512-second intervals. Bitcoin targets 600-second block intervals, and the 512-second granularity was chosen to provide sufficient precision for protocol use cases while fitting within 16 bits. The maximum time-based lock is 65,535 × 512 seconds, or approximately 388 days.
OP_CSV requires the type flags to match when it compares the stack value with the nSequence field. You cannot compare a block-height lock with a time-based nSequence value, or a time-based lock with a block-height nSequence value. The script fails if the types differ.
Script Example
A script can require a 144-block relative delay, approximately one day, before the owner can spend. It enforces that delay with OP_CSV.
The spending transaction must set the input's nSequence to at least 144. The disable flag and type flag must be unset for block-height mode. The network rejects the transaction if fewer than 144 blocks have elapsed since the output was confirmed.
OP_CSV vs. OP_CHECKLOCKTIMEVERIFY
Bitcoin has two timelock opcodes, OP_CSV and OP_CHECKLOCKTIMEVERIFY, and they measure time differently. See the Bitcoin timelocks deep dive for a comprehensive comparison.
OP_CLTV says "cannot spend before block 900,000", while OP_CSV says "cannot spend until 144 blocks after this output is confirmed". OP_CSV is more flexible for protocols because you do not need to know when the output will be created.
Lightning Network Penalty Mechanism
OP_CSV is a key building block of the Lightning Network's security model. Every commitment transaction uses OP_CSV to delay the broadcaster's own funds. The to_local output in a commitment transaction uses a script with two spending paths.
The first path lets the counterparty spend immediately with a revocation key. The second path forces the broadcaster to wait to_self_delay blocks, enforced by OP_CSV, before claiming their own funds. The delay is typically 144 to 2,016 blocks, or one day to two weeks, and is negotiated when the channel opens.
The counterparty holds the revocation key for a state if a party publishes a revoked, outdated commitment transaction. The cheater's funds remain locked behind the OP_CSV delay, giving the honest party time to detect the breach and broadcast a justice transaction that sweeps the entire channel balance. Lightning calls this the LN-Penalty enforcement mechanism.
Watchtower Protection
The CSV delay window also enables watchtowers, third-party services that monitor the blockchain for offline nodes. A watchtower can submit the penalty transaction during the OP_CSV delay period if it detects a revoked commitment transaction being broadcast. Without the relative timelock, watchtowers would have no window to act; see Lightning watchtowers explained for more detail.
Anchor Outputs and Anti-Pinning
The Lightning specification's anchor outputs feature adds a 1-block OP_CSV lock to all HTLC spending transactions. It prevents certain transaction pinning attacks where a malicious party could attach a low-fee child transaction to stop the HTLC from being confirmed promptly. The 1-block CSV lock prevents immediate spending of HTLC transactions, giving the honest party time to use child-pays-for-parent fee bumping.
Bitcoin Vaults
Vault constructions use OP_CSV to create a withdrawal delay. Funds moved out of a vault first go to an intermediate address locked with a relative timelock, and the vault owner can claw back the funds during this waiting period if the withdrawal was unauthorised. More advanced vault designs using covenants complement OP_CSV rather than replace it.
Escrow and Payment Protocols
OP_CSV enables time-locked escrow without trusted intermediaries. A multi-signature output can include an OP_CSV path that lets one party reclaim funds after a timeout, so funds are never permanently locked if the other party becomes unresponsive. You can find this pattern in payment channel designs and atomic swap protocols.
Why It Matters
OP_CSV expanded what is possible on Bitcoin by enabling protocols that rely on relative time guarantees. Payment channels had fixed expiry dates before OP_CSV, which limited their practicality. Channels could remain open indefinitely after OP_CSV because the security mechanism activates only when a commitment transaction is broadcast, not at a predetermined deadline.
OP_CSV's relative timelocks allow the Lightning Network's penalty mechanism to work at scale. Layer 2 protocols like Spark build on these Bitcoin Script primitives to enable fast, low-cost transactions while preserving the base layer's security guarantees. You need to understand OP_CSV when working with Bitcoin Layer 2 technology or building applications that use Bitcoin Script programmability.
Maximum Lock Duration
The 16-bit value field limits relative timelocks to 65,535 blocks, approximately 455 days, or 65,535 × 512 seconds, approximately 388 days. Protocols that need longer lock periods cannot rely solely on OP_CSV. They must use alternative mechanisms or combine OP_CSV with absolute timelocks.
Transaction Version Requirement
OP_CSV requires the spending transaction to use version 2 or higher. Modern Bitcoin software normally meets this requirement, but legacy transaction-building tools that default to version 1 produce invalid transactions when spending OP_CSV-locked outputs.
Type Flag Mismatch
The script fails if the type flag, bit 22, in the script value does not match the type flag in the spending input's nSequence field. Developers must keep the locking script and spending transaction consistent. Mixing block-height and time-based modes is a common implementation error.
Interaction with Replace-By-Fee
The nSequence field serves two purposes: BIP 68 uses it for relative timelocks, while BIP 125 uses nSequence values below 0xfffffffe to signal replace-by-fee (RBF) opt-in. OP_CSV requires the disable flag, bit 31, to be unset, so every OP_CSV-locked input automatically signals RBF eligibility. Protocol designers should account for this when assessing transaction replaceability.
Future Evolution
The proposed eltoo (LN-Symmetry) protocol would simplify Lightning's enforcement mechanism by allowing any later channel state to replace any earlier state. It would remove the need for the penalty-based revocation that OP_CSV currently enables and would require a new sighash flag, SIGHASH_ANYPREVOUT (BIP 118), which has not yet been activated. OP_CSV would still be used for timelocking if adopted, but the overall channel design would change significantly.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.