Sunday, December 22, 2024

script – Learn how to calculate P2WSH signatures with OP_CODESEPARATOR?

witnessScript isn’t the redeemScript however it’s analog to it. It’s the precise Script that’s dedicated to by its hash within the output, and executed when spending it. It’s the “Segwit model of the redeemScript” if you’ll.

CODESEPARATOR is an (attention-grabbing [1]) OP code which permits to customise the behaviour of the CHECKSIG OP code. It permits to part the script code for a signature to decide to solely a part of it.
BIP143 barely modified its behaviour for SegWit scripts.

Concerning your final query, if i perceive accurately you’re refering to those feedback within the take a look at vector.

(please notice that the not-yet-executed OP_CODESEPARATOR isn't faraway from the scriptCode)
every part as much as the final executed OP_CODESEPARATOR, together with that OP_CODESEPARATOR, are eliminated

These feedback are right here for example the brand new behaviour launched in BIP143. The witness script of the output these signatures are for is the next.

<026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880ae> CHECKSIGVERIFY CODESEPARATOR <0255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465> CHECKSIG

The 2 feedback describe the distinction within the scriptCode for computing the signature of every public key contained within the witness script.
For the primary one there was no CODESEPARATOR earlier than the CHECKSIGVERIFY, subsequently the scriptCode is the complete witness Script. For the second nonetheless there was a CODESEPARATOR executed earlier than the CHECKSIG, subsequently the scriptCode is the a part of the witness script beginning simply after the CODESEPARATOR as much as the tip.


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

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles