TeachMeBitcoin

P2WPKH ScriptPubKey Structure

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

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]

2. No Opcodes

Notice that unlike P2PKH, there is no OP_DUP, OP_HASH160, OP_EQUALVERIFY, or OP_CHECKSIG in the locking script.

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.

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.

☕ 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!