<blockquote>
<p>if nLockTime field is greater than the CLTV argument the execution fails, otherwise will continue as if NOP had been executed.</p>
</blockquote>
<p>This is backwards.</p>
<p>If the transaction's nLockTime is greater than or equal to the CLTV argument, then it continues as if a NOP was executed. Execution fails when it is less than the argument.</p>
<p>The code given in the BIP is confusing as it uses <code>nLockTime</code> to refer to the CLTV argument. The transaction's locktime is <code>txTo.nLockTime</code>.</p>

CC BY-SA 4.0
2023-10-20T15:28:49.883Z
2023-10-20T15:28:49.883Z
Ava Chow
<p>The <code>nLockTime</code> transaction field allows you to specify the time before which the transaction cannot be part of the blockchain. You can define that time through the height of the block or in UNIX timestamp form.</p>
<p>The <code>OP_CHECKLOCKTIMEVERIFY</code> has the role of defining the time (block height/UNIX timestamp) before which the given output cannot be used. It works indirectly so that when the given output is referenced and the execution of the script starts, when encountering the given operator, the value given with <code>OP_CHECKLOCKTIMEVERIFY</code> and the value of the <code>nLockTime</code> field are compared. If the value of the <code>nLockTime</code> field is <strong>greater than or equal</strong> to the <code>OP_CHECKLOCKTIMEVERIFY</code> argument, the execution of the script continues, otherwise it is terminated and the transaction is marked as invalid.</p>

CC BY-SA 4.0
2023-10-20T15:52:02.023Z
2023-10-20T15:52:02.023Z
dassd
<p>I have difficulty understanding how does CheckLockTimeVerify works. The <a href="https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki" rel="nofollow noreferrer">BIP-65</a> which proposed CTLV says:</p>
<blockquote>
<p>This BIP describes a new opcode (OP_CHECKLOCKTIMEVERIFY) for the
Bitcoin scripting system that allows a transaction output to be made
unspendable until some point in the future.</p>
</blockquote>
<p>And the mechanism it works is by comparing the nLockTime field of the transaction by CLTV argument, if nLockTime field is greater than the CLTV argument the execution fails, otherwise will continue as if NOP had been executed.
I can't understand how it can prevent the spender from spedning the output before specific time or block height. Since the spender can simply set the transaction's nLockTime field to zero, then it's always spendable because zero is always less than or equal to nLockTime field. How does CLTV <em>allow a transaction output to be made unspendable until some point in the future</em> when the spender can create arbitrary transactions?</p>

<transactions><locktime><checklocktimeverify>
How does CLTV prevent spender from spending the output?
Amir reza Riahi
# How does CLTV prevent spender from spending the output?

(Asked by: username_0 on 2023-10-20)

I have difficulty understanding how does CheckLockTimeVerify works. The [BIP-65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki) which proposed CTLV says:

> This BIP describes a new opcode (OP\_CHECKLOCKTIMEVERIFY) for the
> Bitcoin scripting system that allows a transaction output to be made
> unspendable until some point in the future.

And the mechanism it works is by comparing the nLockTime field of the transaction by CLTV argument, if nLockTime field is greater than the CLTV argument the execution fails, otherwise will continue as if NOP had been executed.
I can't understand how it can prevent the spender from spedning the output before specific time or block height. Since the spender can simply set the transaction's nLockTime field to zero, then it's always spendable because zero is always less than or equal to nLockTime field. How does CLTV *allow a transaction output to be made unspendable until some point in the future* when the spender can create arbitrary transactions?

**Tags:** transactions, locktime, checklocktimeverify


---

## 2 answers

### Answer by username_1 on 2023-10-20. Score: 2

> if nLockTime field is greater than the CLTV argument the execution fails, otherwise will continue as if NOP had been executed.

This is backwards.

If the transaction's nLockTime is greater than or equal to the CLTV argument, then it continues as if a NOP was executed. Execution fails when it is less than the argument.

The code given in the BIP is confusing as it uses `nLockTime` to refer to the CLTV argument. The transaction's locktime is `txTo.nLockTime`.


---

### Answer by username_2 on 2023-10-20. Score: 1

The `nLockTime` transaction field allows you to specify the time before which the transaction cannot be part of the blockchain. You can define that time through the height of the block or in UNIX timestamp form.

The `OP_CHECKLOCKTIMEVERIFY` has the role of defining the time (block height/UNIX timestamp) before which the given output cannot be used. It works indirectly so that when the given output is referenced and the execution of the script starts, when encountering the given operator, the value given with `OP_CHECKLOCKTIMEVERIFY` and the value of the `nLockTime` field are compared. If the value of the `nLockTime` field is **greater than or equal** to the `OP_CHECKLOCKTIMEVERIFY` argument, the execution of the script continues, otherwise it is terminated and the transaction is marked as invalid.


---

