From Trezor Wiki
Jump to: navigation, search

P2WPKH-in-P2SH together with P2WSH-in-P2SH represents type of transaction which allows non-SegWit wallets to generate a SegWit transaction. It uses a P2SH transaction as the cornerstone and includes P2WPKH inside it. If a SegWit-aware node sees a P2SH which contains P2WPKH it interprets it in the native way.

ScriptPubKey: OP_HASH160 <20-byte-redeemScriptHash> OP_EQUAL 
ScriptSig:  <0 <20-byte-PublicKeyHash>> 
Witness:  <Signature> <PublicKey>
RedeemScript: 0 <20-byte-PublicKeyHash>

The P2SH redeem script is equal to 0 <20-byte-PublicKeyHash> which is exactly the same as P2WPKH scriptPubKey. The scriptSig is a canonical push of data, which contain another canonical push of data.

To understand how transactions work on basic technical level, check blog post Types of Bitcoin transactions: Part I, Part 2. More detailed description can be found in Bitcoin Wiki or in Bitcoin.org Developer guide.