P2WSH ScriptPubKey Structure
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]
-
0x00: The Witness Version (Version 0).
-
0x20: The push-data opcode for 32 bytes (hex
0x20). -
[32-Byte Hash]: The SHA256 hash of the full multisig script (the Witness Script).
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:
-
P2WPKH: Starts with
0014...(22 bytes total). -
P2WSH: Starts with
0020...(34 bytes total).
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.
-
This simplifies the mathematical verification process for nodes.
-
By using a 256-bit hash, Bitcoin ensures that even if one day computers become fast enough to crack 160-bit hashes, your multisig funds will remain secure.
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.
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: