diff --git a/9_2_Using_CLTV_in_Scripts.md b/9_2_Using_CLTV_in_Scripts.md index 75a7e21..333a3d3 100644 --- a/9_2_Using_CLTV_in_Scripts.md +++ b/9_2_Using_CLTV_in_Scripts.md @@ -101,6 +101,29 @@ In the case of the above example, the following unlocking script would suffice, ``` +### Run a CLTV Script + +To run the Script, you would first concatenate the unlocking and locking scripts: +``` +Script: OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG +Stack: [ ] +``` +The sthree constants would be pushed onto the stack: +``` +Script: OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG +Stack: [ ] +``` +Then, `OP_CHECKLOCKTIMEVERIFY` would run. It finds something on the stack and verifies that `nSequence` isn't 0xffffffff. Finally, it compares `` with `nLockTime`. If they are both the same sort of representation and if `nLockTime ≥ `, then it successfully processes (else, it ends the script): +``` +Script: OP_DROP OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG +Stack: [ ] +``` +Then, `OP_DROP` gets rid of that `` left around: +``` +Script: OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG +Stack: [ ] +``` +Finally, the remainder of the script runs, which is a normal check of a signature and public key. ## Summary: Using CLTV in Scripts `OP-CHECKLOCKTIMEVERIFY` is a simple opcode that looks at a single arguments, interprets it as a blockheight or UNIX timestamp, and only continues with a UTXO's redemption if that blockheight or UNIX timestamp is in the past. Setting `nLockTime` on the new transaction is what allows Bitcoin to make this calculation.