TeachMeBitcoin

The Witness Stack for P2WSH

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Witness Stack for P2WSH

In a P2WSH spend, the ScriptSig is empty, and the entire logic of the multisig contract is moved to the Witness Stack. This includes the threshold, the keys, and the signatures.

1. The Stack Sequence

For a 2-of-3 multisig spend, the Witness Stack contains the following items in order:

  1. OP_0 (The Multisig Dummy Value)

  2. Signature 1

  3. Signature 2

  4. Witness Script (OP_2 [Key1] [Key2] [Key3] OP_3 OP_CHECKMULTISIG)

2. The Verification Loop

  1. Extraction: The node extracts the last item (the Witness Script) and hashes it.

  2. Comparison: It compares the hash to the target in the ScriptPubKey.

  3. Unwrapping: If they match, it "unwraps" the Witness Script and places the remaining stack items (Dummy, Sig1, Sig2) into it for execution.

3. The Discount Advantage

Because the Witness Script (containing the bulky public keys) is now in the Witness area, it only costs 1 Weight Unit per byte.

4. Size Limits

Even though it is discounted, P2WSH still has limits:

Stack Position Data Cost (WU)
Bottom Witness Script 1 per byte
Middle Signatures 1 per byte
Top Dummy Value 1 per byte

In the next section, we will compare the Fee Efficiency of different multisig types.

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