5

scriptPubKey, redeem script, witness script, witness program are defined in this StackExchange post.

What are the scriptPubKey, scriptSig, redeem script and witness for the various output types (P2PKH, P2SH, P2WPKH, P2WSH etc)?

2 Answers 2

8

This was answered during the Bitcoin Core PR review club on July 7th 2021 hosted by Gloria Zhao (who also provided this table).

enter image description here

The <public key> in the P2TR (key path) and P2TR (script path) scriptPubKey column is the tweaked public key rather than the internal key (assuming they aren't the same and the tweak is being used as recommended by BIP 341).

1
  • 3
    The first row should be labeled "P2PK".
    – Murch
    Aug 2, 2021 at 15:02
2

I thought it would be useful to have a text version of the image of a table in Michael Folkson's answer. If only for accessibility reasons.

(it initially proved rather too hard to edit into his answer due to the table's markup complexity and stackexchange having different rendering of the edit preview and final answer!)

Output type locking script unlocking script redeem script witness
P2PK <pubkey>
OP_CHECKSIG
<signature>
P2PKH OP_DUP
OP_HASH160
<pubKeyHash> OP_EQUALVERIFY
OP_CHECKSIG
<signature>
<public key>
P2SH OP_HASH160
<scripthash>
OP_EQUAL
<data pushes>
<redeem script>
<arbitrary>
P2WPKH 0
<pubKeyHash>
<signature>
<public key>
P2WSH 0
<witnessScriptHash>
<data pushes>
<witness script>
P2SH-P2WPKH OP_HASH160
<redeemScriptHash>
OP_EQUAL
<redeem script> 0
<pubKeyHash>
<signature>
<public key>
P2SH-P2WSH OP_HASH160
<redeemScriptHash>
OP_EQUAL
<redeem script> 0
<scriptHash>
<data pushes>
<witness script>
P2TR (key path) 1
<public key>
<signature>
P2TR (script path) 1
<public key>
<data pushes>
<script>
<control block>

Note that the redeem script for P2SH-P2WPKH is inside the unlocking script and its notation might be clearer as, for example <0 <pubKeyHash>> to show the nesting ("wrapping") of the data pushes.

The serialisation of unlocking script <0 <pubKeyHash>> would be

Hex meaning notes
16 push 22 byte wrapper -
00 0 first wrapped item inside wrapper
14 push 20 byte pubKeyHash -
... pubKeyHash second wrapped item inside same wrapper

Essentially, the wrapped types (P2SH-P2W..) require recursive parsing, though only to depth 1, so maybe it shouldn't be regarded as recursive.

The table currently omits some interesting types such as multisig as well as some trivial types such as OP_RETURN.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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