1

I have some doubts about naming in witness script/transaction.

P2SH-P2WSH (multisig)

WITNESS_SCRIPT = OP_3 <public key1> <public key2> <public key3> <OP_2>

(is it witness script or redeem script? For now I will call Witness script)

SCRIPTHASH= SHA256 (WITNESS_SCRIPT)

is it Witness script Hash or redeem script Hash?

REDEEM_SCRIPT=0020+SCRIPTHASH

is it redeem script? Maybe it's the redeem script because it is in Scriptsig. (Witness version + Witness program)

In scriptPubKey hash160 of (0020+SCRIPTHASH).

What is its name? Hash160 of ?

And We have OP_HASH160 <Redeem script hash?> OP_EQUAL

P2SH-P2WPKH

KEYHASH = hash160(<public key>)

REDEEM_SCRIPT=0014+KEYHASH

is it redeem script or witness script? For now I Will call redeem script.

In scriptPubKey hash160 of (0020+SCRIPTHASH).

What is its name? Hash160 of ?

And We have OP_HASH160 <Redeem script hash?> OP_EQUAL

P2WPKH NATIVE

WITNESS SCRIPT = hash160(<public key>)

In scriptpubkey 0014+WITNESS_SCRIPT

OP_0 <20 bytes witness script hash>

P2WSH NATIVE

WITNESS SCRIPT = <OP_2> <pubkey1><pubkey2><pubkey3><OP_3> <OP_CHECKMULTISIG>

WITNESS_SCRIPT_HASH = HASH160 (WITNESS SCRIPT)

In scriptpubkey

0020+WITNESS_SCRIPT_HASH

OP_0 <32 bytes witness script hash>

P2WPKH NATIVE and P2WSH NATIVE should be ok

3

P2SH-P2WSH:

  • Witness script: OP_3 <public key1> <public key2> <public key3> OP_2 OP_CHECKMULTSIG
  • Witness program: SHA256(witness script)
  • redeemScript: OP_0 <witness program>
  • Script hash: Hash160(redeemScript)
  • scriptPubKey: OP_HASH160 <script hash> OP_EQUAL

P2SH-P2WPKH (I believe that's what you meant instead of "P2WSH-P2PKH"):

  • Witness program: Hash160(public key)
  • redeemScript: OP_0 <witness program>
  • Script hash: Hash160(redeemScript)
  • scriptPubKey: OP_HASH160 <script hash> OP_EQUAL

P2WSH-P2PKH (native P2WSH, but with a P2PKH script inside):

  • Witness script: OP_DUP OP_HASH160 <Hash160(pubkey)> OP_EQUALVERIFY OP_CHECKSIG
  • Witness program: SHA256(witness script)
  • scriptPubKey: OP_0 <witness program>

Note that you should use P2WPKH instead of this.

Native P2WPKH

  • Witness program: Hash160(public key)
  • scriptPubKey: OP_0 <witness program>

Native P2WSH

  • Witness script: OP_3 <public key1> <public key2> <public key3> OP_2 OP_CHECKMULTISIG
  • Witness program: SHA256(witness script)
  • scriptPubKey: OP_0 <witness program>
| improve this answer | |
  • Thanks again for your time, it's an amazing answer for me. I don't understand this script P2WSH-P2PKH the third one. I create a bash script to create P2WSH-P2PKH native (bc) where the Witness script is OP_DUP OP_HASH160 <Hash160(pubkey)> OP_EQUALVERIFY OP_CHECKSIG. But I have the last scenario (Native P2WSH), than I don't have redeem script and script hash.thanks for your advice (Note that you should use P2WPKH instead of this.) but my purpose now is to study, I don't use it :). – monkeyUser Apr 17 at 15:09
  • I have another question (sorry). You said "P2SH-P2WSH" redeemScript: OP_0 <witness program>. When I use signrawtransactionwithkey I need to put redeemScript in witnessScript value. Then why use the name redeemScript when I need to use in witnessScript value during signrawtransactionwithkey? – monkeyUser Apr 17 at 15:47
  • 1
    @monkeyUser signrawtransaction* secretly doesn't really care about what you name things; it just needs to know all the scripts involved in order to sign. – Pieter Wuille Apr 17 at 18:48
  • 1
    Oh, my mistake! Fixed. – Pieter Wuille Apr 17 at 19:25
  • 1
    thanks for your time, really. – monkeyUser Apr 17 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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