Home › Glossary › P2WSH

P2WSH

Also called: Pay to Witness Script Hash, native SegWit multisig, P2SH-P2WSH, witnessScript, witness script hash.

P2WSH (Pay to Witness Script Hash) is the native SegWit output for scripts such as multisig: a 32-byte script hash with a 62-character bc1q address.

P2WSH, Pay to Witness Script Hash, is the SegWit counterpart of P2SH. Coins are locked to the hash of a script, and the spender reveals the script (the witnessScript) and the data that satisfies it in the witness. It is the usual home for SegWit multisig and other custom scripts.

How it works

BIP 141 defines it as a version 0 witness program of exactly 32 bytes, the SHA-256 of the witnessScript:

scriptPubKey: 0 <32-byte script hash>    (0x0020{32 bytes}, 34 bytes)
witness:      <inputs...> <witnessScript>

Nodes hash the last witness item, compare it with the program, and run it with the other items as input. The witnessScript can be up to 10,000 bytes, because the 520-byte push limit that constrains P2SH redeemScripts doesn't apply. That raises the OP_CHECKMULTISIG limit to 20 keys. Signatures use BIP 143 hashing.

Why 32 bytes?

P2SH uses a 20-byte hash. BIP 141 chose a full 32-byte SHA-256 for P2WSH to improve security against collision attacks, noting that 2^80 work was no longer infeasible.

Addresses

P2WSH addresses use Bech32 (BIP 173) and are 62 characters long, for example bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3. That length tells them apart from 42-character P2WPKH addresses. A wrapped form, P2SH-P2WSH, puts the program inside P2SH for older senders.

Multisig wallets use the BIP 48 path m/48'/0'/0'/2' and describe P2WSH policies with wsh() output descriptors (BIP 382), often written in Miniscript. Read the SegWit guide for the bigger picture.

BIPs that define P2WSH

Related terms

  • P2SH: P2SH (Pay to Script Hash), defined in BIP 16, locks bitcoin to the hash of a script. Its addresses start with 3, and it carried most early multisig.
  • Multisig: Multisig (multi-signature) locks bitcoin so that M of N chosen keys must sign to spend it, for example any 2 of 3 keys kept in different places.
  • P2WPKH: P2WPKH (Pay to Witness Public Key Hash) is the native SegWit single-key output type. Its bc1q addresses are always 42 characters long.
  • Witness: The witness is the part of a SegWit transaction that holds signatures and scripts, kept out of the txid so it can't be changed to alter the transaction ID.
  • Miniscript: Miniscript is a structured way to write Bitcoin Script, specified in BIP 379, that makes complex spending conditions easy to analyze, combine and sign.

Learn more

Guides