4

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 <PubKHash> 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?

Michael Folkson
  • 15,313
  • 3
  • 17
  • 53
monkeyUser
  • 984
  • 1
  • 7
  • 18

1 Answers1

11
  • 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 <Hash160(redeemScript)> 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 <witness_program>; for P2SH-wrapped segwit outputs the redeemScript is OP_0 <witness_program> (and thus the scriptPubKey is OP_HASH160 <Hash160(OP_0 <witness_script>)> OP_EQUAL.
Pieter Wuille
  • 105,497
  • 9
  • 194
  • 308