TeachMeBitcoin

P2WSH ScriptPubKey Structure

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

P2WSH ScriptPubKey Structure

The P2WSH locking script is a Witness Program for complex logic. Like P2WPKH, it is minimalist and uses versioning, but it is larger because it stores a 256-bit cryptographic hash.

1. The Locking Script (ScriptPubKey)

A P2WSH script is exactly 34 bytes long: 00 20 [32-Byte SHA256 Script Hash]

2. P2WPKH vs. P2WSH Length

It is very easy to tell the difference between a single-key and a multisig native SegWit output just by looking at the raw hex length:

3. SHA256 Directness

In P2SH, the 20-byte hash is a "Double Hash" (SHA256 then RIPEMD160). In P2WSH, the 32-byte hash is a Single SHA256.

4. The "No Opcodes" Rule

Just like in P2WPKH, there are no opcodes like OP_EQUAL in the ScriptPubKey. The node knows that because it is a 0020 script, it MUST hash the provided witness data and check for equality. This hardcoded logic saves space and prevents potential script-injection bugs.

Attribute P2WPKH P2WSH
Push Opcode 0x14 (20 bytes) 0x20 (32 bytes)
Data Type Public Key Hash Witness Script Hash
Total Script Size 22 Bytes 34 Bytes
Address Length 42 chars 62 chars

In the next section, we will examine the Witness Stack for P2WSH.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!