script – How to calculate P2WSH signatures with OP_CODESEPARATOR?

[ad_1]

witnessScript is not the redeemScript but it is analog to it. It is the actual Script that is committed to by its hash in the output, and executed when spending it. It is the “Segwit version of the redeemScript” if you will.

CODESEPARATOR is an (interesting [1]) OP code which allows to customize the behaviour of the CHECKSIG OP code. It allows to section the script code for a signature to commit to only part of it.
BIP143 slightly changed its behaviour for SegWit scripts.

Regarding your last question, if i understand correctly you are refering to these comments in the test vector.

(please note that the not-yet-executed OP_CODESEPARATOR is not removed from the scriptCode)
everything up to the last executed OP_CODESEPARATOR, including that OP_CODESEPARATOR, are removed

These comments are here to illustrate the new behaviour introduced in BIP143. The witness script of the output these signatures are for is the following.

<026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880ae> CHECKSIGVERIFY CODESEPARATOR <0255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465> CHECKSIG

The two comments describe the difference in the scriptCode for computing the signature of each public key contained in the witness script.
For the first one there was no CODESEPARATOR before the CHECKSIGVERIFY, therefore the scriptCode is the entire witness Script. For the second one however there was a CODESEPARATOR executed before the CHECKSIG, therefore the scriptCode is the part of the witness script starting just after the CODESEPARATOR up to the end.


[1] CODESEPARATOR was initially used to execute the scriptPubkey and scriptSig as a single stack (inserted in-between). It was then removed by Satoshi when patching the 1 RETURN bug.

[ad_2]

Source link

Leave a Comment