Una of the most useful functions it has Bitcoin ScriptAre the time locks or TimeLockLike opcode (OP_CODE) CheckSequenceVerify (CSV). Which together with other lock codes make it possible for Bitcoin can be used as a programmable digital money.
El CheckSequenceVerify is a relative time lock that operates at the script level. This allows us to define the exact moment in which a block on a given transaction will end. And although this is a characteristic that was part of the soft fork of 68 BIPit wasn't until 112 BIP where it was truly added to the Bitcoin system.
The utility CheckSequenceVerify enables advanced functionality for building systems such as payment channels de Lightning Network (LN). In addition, it opens the doors to the creation of advanced functionalities for the management of funds in a decentralized way, useful for Decentralized exchanges (DEX) or exchange services P2P insurance.
Likewise, although the way of operating of CheckSequenceVerify (CSV) is quite similar to that of CheckLockTimeVerify (CLTV)In CSV, the upper stack is checked with the input field, instead of checking the time, as is the case with CLTV. Thus we can calculate the time based on the number of blocks that have been generated after the transaction has been confirmed. That is, relative time locks like CheckSequenceVerify can mark a transaction as invalid. And for this, they monitor that the established time interval has elapsed since the previous exits of the transaction were confirmed.
In simpler words, relative time locks allow us to define exactly the amount of time to elapse before a transaction can be confirmed. Unlike absolute time locks that define the exact moment (block number, or date and time) at which the block on the transaction will end.
How does CheckSequenceVerify (CSV) work?
Script-level time locks like CheckSequenceVerify (CSV) operate in conjunction with transaction level locksTherefore, the latter are important when applying a CSV lock. This is because in CSV locks the scripts check the transaction lock. To do this, they verify that said transaction is blocked and use these locks on the transactions as a guarantee of age that indicates that the established time has elapsed.
Find the model you want in 112 BIP Bitcoin, CheckSequenceVerify is described as an opcode that gives a new definition to the already existing OP_NOP3 command. This update enables you to block a transaction at the script level based on the age or age of the output being spent. This functionality is executed in conjunction with BIP 68. In this way, you can also prevent a transaction from being included within a block. This until the established time or age has elapsed.
When checking CSV lock with value nSequence established, it is verified if the minimum age of the output being spent has already been met. If not already fulfilled, the script execution paths that include the CSV lock can be validated. Thus, the transaction cannot be included in a block until the condition is met.
Thus, when the CSV opcode is called, it causes the script to fail unless the sequence number in the transaction indicates that a time interval has already elapsed in the relative time lock, which is greater than or equal to the CSV opcode indicator. Thus guaranteeing that the transaction can only be included in a valid block once the blocking time has been met or expired.
When this opcode is implemented, CheckSequenceVerify allows you to set locks on transactions with a maximum of up to 65.535 blocks. But you can also set such a lock to a maximum up to 65.535 * 512 seconds. On the other hand, these locks are very useful when establishing relative time locks on transactions that have not been confirmed or transmitted to the network. Since CSV allows the creation of intelligent transactions defining and establishing all the instructions that are necessary for their execution in advance. Thus we have the guarantee and security that said contract or transaction will only occur under the established order. All this regardless of when it begins to run.
CheckSequenceVerify (CSV) Implementations
The implementation of the operation code OP_CSV allow transactions on the blockchain to have a relative expiration date. A property that in turn allows transactions to be stored indefinitely. As long as the initially established time blocking conditions remain. The opposite would happen if the OP_CLTV operation code is used, with which the entire chain of transactions would have a deadline of execution and expiration.
So, when OP_CSV is used to chain transactions through relative hang times, it is possible to create a code path that is only accessible after the set time interval elapses. That is, after the exits that are being spent are confirmed. Allowing the creation and application of additional functions that make the network much more attractive. For example, the implementation of contracts with expiration terms or the possibility of practically having the chain reorganization characteristic or retroactive invalidation. Although it is almost impossible to perform on a blockchain, other similar applications can be established, such as custody protocols or time-blocked contracts, bidirectional payment channels y Lighting Network.