TeachMeBitcoin

The Witness Stack for P2WPKH

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Witness Stack for P2WPKH

The most radical change in P2WPKH is the total elimination of the ScriptSig. In a Native SegWit transaction, the input contains Zero Bytes of script data. Instead, all authorization data is moved to the Witness Stack.

1. The Empty ScriptSig

In a legacy transaction, the Signature and PubKey are part of the transaction's "Body." In a P2WPKH transaction, the Input's script field is replaced with an empty 0x00 byte. This is why SegWit effectively "Fixes" Transaction Malleability—because the data that generates the TXID no longer contains the signature.

2. The Witness Area

The signature and public key are placed in a separate data structure at the end of the transaction: [Signature] [Public Key]

3. The Validation Process

When an upgraded node validates the spend:

  1. It sees the 00 14 in the ScriptPubKey.

  2. It looks at the Witness Stack.

  3. It pops the Signature and PubKey.

  4. It hashes the PubKey and ensures it matches the Hash from the ScriptPubKey.

  5. It verifies the Signature against the PubKey.

4. Why Compressed Keys Only?

To maximize efficiency, SegWit enforces the use of Compressed Public Keys.

Data Type Legacy Location Native SegWit Location
Previous TXID Body Body
Output Index Body Body
Signature ScriptSig (Body) Witness Stack
Public Key ScriptSig (Body) Witness Stack

In the next section, we will discuss Bech32 Encoding (BIP 173).

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