Redeem script. script hash, witness script and witness program
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 &lt;Hash160(redeemScript)&gt; 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 Hash256(witness_script) for P2WPKH. For native segwit outputs the scriptPubKey is OP_0 &lt;witness_program&gt;; for P2SH-wrapped segwit outputs the redeemScript is OP_0 &lt;witness_program&gt; (and thus the scriptPubKey is OP_HASH160 &lt;Hash160(OP_0 &lt;witness_script&gt;)&gt; OP_EQUAL.