P2SH

From Trezor Wiki
Jump to: navigation, search

Pay to script hash (P2SH) is an advanced type of transaction used in Bitcoin and other similar cryptocurrencies. Unlike P2PKH, it allows sender to commit funds to a hash of an arbitrary valid script. Currently, P2SH is mainly used for MultiSig and non-native SegWit transactions (P2WPKH-in-P2SH).

See also BIP16, BIP49, Transaction types

Transaction scripts[edit]

An output that pays to a P2SH scriptPubKey is spent by an input with a scriptSig that provides the correct redeem script along with all the data (like signatures and corresponding public keys) necessary for the successfull script evaluation:

scriptPubKey: OP_HASH160 <redeemScriptHash> OP_EQUAL
scriptSig: <singatures> <publicKeys> <redeemScript>

For P2SH transaction examples, check P2WPKH-in-P2SH and P2SH-multisig.

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.

Address and version bytes [edit]

A P2SH address is an base58check-encoded form of a redeem script hash prefixed by corresponding version bytes:

P2SH address = Base58Check ( <versionBytes> <redeemScriptHash> )

Version bytes for P2SH addresses are listed in Trezor coins definitions under address_type_p2sh field of a particular JSON file. For example in Bitcoin, P2SH addresses start with "3" (version bytes 5), while in Litecoin they start with "M" (version bytes 50) etc.

Trezor support[edit]

Trezor supports P2SH transactions for the following forms of redeem scripts: P2WPKH-in-P2SH and multisig-in-P2SH. Other P2SH scripts are not supported.

In Trezor Wallet P2WPKH-in-P2SH transactions are supported and organized using BIP49. For P2SH-multisig other wallet interface has to be used with Trezor, see Apps.

Like Trezor? Get one here!