Timelock is a Bitcoin feature that enables specifying the time or block height for processing a transaction. This means that transactions are only processed during a predetermined period with certain prerequisites. A unique type of transaction or output is used to accomplish this.
Types of Timelocks
Timelocks can be implemented either at the transaction-level or the UTXO-level. At the transaction-level, the timelock ensures that the transaction is not confirmed until a specific time has passed. At the UTXO-level, it stops bitcoin funds from being expended until a certain block height or time has passed. Timelocks can be implemented in both absolute and relative ways.
The following are types of timelocks:
- NlockTime
The nLockTime variable is a part of a transaction that sets the minimum block height or timestamp for the transaction to be added to the blockchain. In case the current block height or timestamp is lower than the specified nLockTime value, the network views the transaction as invalid.It is critical to note that nLockTime is a timelock feature operating at the TRANSACTION LEVEL.
- NSequence
By entering a value in the transaction input, the nSequence field can be utilized as a timelock, indicating that the input has a relative timelock. This means that a transaction can't be spent until a specific time has passed since the related UTXO was verified. For example, if a transaction input is assigned an nSequence value of 30 blocks, it can only be spent after 30 blocks have been mined since the creation of the referenced UTXO. While a transaction can have several time locked inputs, they all must have matured by the designated relative time lock duration before the transaction can be considered valid.
- CheckLockTimeVerify(CLTV)
CLTV, or CheckLockTimeVerify, is a mechanism that verifies a specific block height or timestamp to ensure that the funds from a transaction can only be spent after a certain block or timestamp has been reached.
- CheckSequenceVerify(CSV)
CSV, or CheckSequenceVerify, allows locking a transaction output for a particular number of blocks instead of a specific time, enabling more flexible time-based conditions such as releasing funds only after a specific number of blocks or allowing time-based refunds if a condition isn't met.
It's worth mentioning that both CLTV and CSV are Timelocks based on UTXO.
Use Cases For Timelocks
Timelocks offer various possibilities for creating different types of transactions in Bitcoin. Here are a few common examples:
Escrow Services:
Timelocks enable the creation of escrow services, where funds are held until certain conditions are met. For example, let's say Solomon intends to purchase an item from Sadeeq's store. He can create a transaction that includes a timelock, indicating that the funds will only be released to Sadeeq after a specific period of time has elapsed. If Sadeeq delivers the product within the specified time frame, Solomon can release the funds. Otherwise, the funds are returned to Solomon.
Multi-signature wallets:
In multi-signature wallets, Timelocks are effective in preventing funds from being spent without the consent of multiple parties. For instance, a company can apply a Timelock to a transaction, mandating that all three signatories approve it within a particular time frame. If one of the signatories doesn't endorse the transaction within the specified time, it gets canceled.
Bitcoin Lightning Network:
The Lightning Network uses timelocks to ensure that funds are not locked up indefinitely in payment channels. For instance, if Chinonso and Stephanie have a payment channel open with a balance of 1 BTC and Chinonso wants to send 0.5 BTC to Stephanie,, He can create a payment channel update transaction with a timelock. If Stephanie tries to cheat by broadcasting an earlier transaction that claims more funds than he is entitled to, Alice can use the timelock to reclaim her funds.
To sum up, Timelocks represent a significant aspect of Bitcoin, offering an extra layer of protection to transactions. They enable enforcing time-based constraints, such as prohibiting fund spendings before a specific time, establishing time-bound payment channels, and preventing fraud in several situations.