<ul>
<li>The scriptPubKey is the script as it is placed in the transaction output.</li>
<li>The redeemScript (P2SH only) is the script pushed as the last scriptSig item. In P2SH scripts, the scriptPubKey is equal to <code>OP_HASH160 &lt;Hash160(redeemScript)&gt; OP_EQUAL</code>.</li>
<li>The witness script (P2WSH only) is the script in the last witness stack position.</li>
<li>The witness program is <code>Hash160(pubkey)</code> for P2WPKH, and <code>SHA256(witness_script)</code> (not <code>Hash256(witness_script)</code>!) for P2WSH. For native segwit outputs the scriptPubKey is <code>OP_0 &lt;witness_program&gt;</code>; for P2SH-wrapped segwit outputs the redeemScript is <code>OP_0 &lt;witness_program&gt;</code> (and thus the scriptPubKey is <code>OP_HASH160 &lt;Hash160(OP_0 &lt;witness_script&gt;)&gt; OP_EQUAL</code>.</li>
</ul>

CC BY-SA 4.0
2020-04-12T10:53:25.983Z
In P2SH-wrapper is `OP_0 <witness_program>` where OP_0 is the witness version?
monkeyUser
CC BY-SA 4.0
2020-04-12T17:08:21.043Z
Yes, indeed. The OP_0 is the witness version. So far only witness v0 is defined.
Pieter Wuille
CC BY-SA 4.0
2020-04-13T10:52:32.607Z
the fourth bullet point. `The witness program is Hash160(pubkey) for P2WPKH, and Hash256(witness_script) for P2WPKH` maybe I think you mean `The witness program is Hash160(pubkey) for P2WPKH, and Hash256(witness_script) for P2WSH` ?
monkeyUser
CC BY-SA 4.0
2020-04-13T15:56:48.037Z
Yes indeed, fixed.
Pieter Wuille
CC BY-SA 4.0
2022-03-08T19:54:30.900Z
@PieterWuille I caught what monkeyUser caught too. It doesn't look like the post has been edited with the fix.
Sam
CC BY-SA 4.0
2024-02-01T21:51:41.910Z
Now actually fixed. It's SHA256 too, not Hash256.
Pieter Wuille
CC BY-SA 4.0
2020-04-11T18:50:19.653Z
2024-02-01T21:51:07.947Z
2024-02-01T21:51:07.947Z
Pieter Wuille
<p>I have a little confusion about naming in Bitcoin.</p>

<p><strong>Redeem script</strong> is the conditions that will be satisfy. 
For example P2PKH inside P2SH </p>

<pre><code>OP_DUP OP_HASH160 &lt;PubKHash&gt; OP_EQUALVERIFY OP_CHECKSIG == redeem script
</code></pre>

<p><a href="https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address" rel="nofollow noreferrer">In P2SH-P2WPKH the <strong>redeem script</strong> is:</a></p>

<blockquote>
  <p>The P2SH redeemScript is always 22 bytes. It starts with a OP_0,
  followed by a canonical push of the keyhash (i.e. 0x0014{20-byte
  keyhash}).</p>
</blockquote>

<p>Sometime It call script hash, and during the transaction I need to insert the redeem script in witnessScript. <code>"witnessScript": "hex",    (string) (required for P2WSH or P2SH-P2WSH) witness script</code></p>

<p>Then the redeem script in segwit environment is called redeem script, script hash or witness script?</p>

<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Witness_program" rel="nofollow noreferrer">Witness program</a></p>

<blockquote>
  <p>A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that consists of a 1-byte push opcode (for 0 to 16) followed by a data push between 2 and 40 bytes gets a new special meaning.</p>
</blockquote>

<p>Witness program depends on script could be scriptPubkey or redeem script?</p>

<transactions><segregated-witness><script><terminology><witness-data>
Redeem script. script hash, witness script and witness program
monkeyUser
# Redeem script. script hash, witness script and witness program

(Asked by: username_0 on 2020-04-11)

I have a little confusion about naming in Bitcoin.
Redeem script is the conditions that will be satisfy. 
For example P2PKH inside P2SH 
OP_DUP OP_HASH160  OP_EQUALVERIFY OP_CHECKSIG == redeem script

In P2SH-P2WPKH the redeem script is:

The P2SH redeemScript is always 22 bytes. It starts with a OP_0,
  followed by a canonical push of the keyhash (i.e. 0x0014{20-byte
  keyhash}).

Sometime It call script hash, and during the transaction I need to insert the redeem script in witnessScript. "witnessScript": "hex",    (string) (required for P2WSH or P2SH-P2WSH) witness script
Then the redeem script in segwit environment is called redeem script, script hash or witness script?
Witness program

A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that consists of a 1-byte push opcode (for 0 to 16) followed by a data push between 2 and 40 bytes gets a new special meaning.

Witness program depends on script could be scriptPubkey or redeem script?

**Tags:** transactions, segregated-witness, script, terminology, witness-data


---

## 1 answers

### Answer by username_1 on 2020-04-11. Score: 11 | Accepted answer

* The scriptPubKey is the script as it is placed in the transaction output.
* The redeemScript (P2SH only) is the script pushed as the last scriptSig item. In P2SH scripts, the scriptPubKey is equal to `OP_HASH160  OP_EQUAL`.
* The witness script (P2WSH only) is the script in the last witness stack position.
* The witness program is `Hash160(pubkey)` for P2WPKH, and `SHA256(witness_script)` (not `Hash256(witness_script)`!) for P2WSH. For native segwit outputs the scriptPubKey is `OP_0` ; for P2SH-wrapped segwit outputs the redeemScript is `OP_0`  (and thus the scriptPubKey is `OP_HASH160 )> OP_EQUAL`.

> **Comments:**
> **username_0**: In P2SH-wrapper is `OP_0 <witness_program>` where OP_0 is the witness version?  
> **username_1**: Yes, indeed. The OP_0 is the witness version. So far only witness v0 is defined.  
> **username_0**: the fourth bullet point. `The witness program is Hash160(pubkey) for P2WPKH, and Hash256(witness_script) for P2WPKH` maybe I think you mean `The witness program is Hash160(pubkey) for P2WPKH, and Hash256(witness_script) for P2WSH` ?  
> **username_1**: Yes indeed, fixed.  
> **username_2**: @PieterWuille I caught what username_0 caught too. It doesn't look like the post has been edited with the fix.  
> **username_1**: Now actually fixed. It's SHA256 too, not Hash256.  

---

