P2WPKH ScriptPubKey Structure
P2WPKH ScriptPubKey Structure
The P2WPKH locking script is a "Witness Program." It is extremely minimalist and uses the new versioning system introduced by BIP 141. To an old node, it looks like a simple data push, but to a modern node, it is a high-priority instruction.
1. The Locking Script (ScriptPubKey)
A P2WPKH script is exactly 22 bytes long:
00 14 [20-Byte Public Key Hash]
-
0x00: The Witness Version. Version 0 is the current standard for SegWit.
-
0x14: The push-data opcode (20 bytes in decimal).
-
[20-Byte Hash]: The HASH160 of the public key.
2. No Opcodes
Notice that unlike P2PKH, there is no OP_DUP, OP_HASH160, OP_EQUALVERIFY, or OP_CHECKSIG in the locking script.
-
The logic for these opcodes is now Hardcoded into the SegWit validation rules for Version 0.
-
By removing the opcodes, the output saves 3 bytes of space (
76 a9 88 ac).
3. The "Anyone Can Spend" Compatibility
As we discussed in the Nested SegWit module, old nodes see 00 14 [Hash] as a valid script that simply leaves data on the stack.
-
Because the script doesn't contain a
1(Success) or0(Failure) opcode, old nodes consider it "True" by default. -
Upgraded nodes recognize the
00 14pattern as a Witness Program and perform the mandatory signature verification.
4. Raw Hex Comparison
| Type | Raw Hex ScriptPubKey | Length |
|---|---|---|
| Legacy (P2PKH) | 76a914[Hash]88ac |
25 Bytes |
| Native (P2WPKH) | 0014[Hash] |
22 Bytes |
This 3-byte saving per output might seem small, but across millions of transactions, it significantly slows down the growth of the UTXO Set.
In the next section, we will look at the Witness Stack and how a P2WPKH spend is actually authorized.
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: