2

I have difficulty understanding how does CheckLockTimeVerify works. The BIP-65 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?

0

2 Answers 2

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.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.