Witness Items & Count
Witness Items and Count
The Witness section of a transaction is a list of lists. Every input has its own "Witness Field," and every witness field can contain multiple "Witness Items."
1. Defining a Witness Item
A witness item is a piece of data required for validation. In a standard P2WPKH transaction, there are exactly two items:
-
The ECDSA Signature.
-
The Public Key.
In more complex scripts, like a 2-of-3 Multi-sig, there might be four items (OP_0, Sig1, Sig2, and the Redeem Script).
2. Encoding the Count
Before the items for a specific input are listed, there is a Count byte.
-
If the input is Legacy, the count is
00. -
If the input is P2WPKH, the count is
02. -
If the input is Taproot, the count is usually
01(since the pubkey is in the output).
3. The "Itemized" Format
Each item in the list is prefixed by its length as a VarInt. This makes it incredibly efficient for nodes to "pop" items off the witness and push them onto the execution stack.
[Item Count]
[Item 1 Length][Item 1 Data]
[Item 2 Length][Item 2 Data]
4. The wTXID (Witness Transaction ID)
Because the witness data is required for full validation but is not part of the TXID, Bitcoin uses a second hash called the wTXID.
-
TXID: Hash of the transaction without Marker, Flag, or Witness.
-
wTXID: Hash of the entire transaction including Marker, Flag, and Witness.
Miners use the wTXID to build the Witness Merkle Tree, which is committed to the coinbase transaction of every block.
| Name | Includes Witness? | Purpose |
|---|---|---|
| TXID | No | Referencing inputs, double-spend protection. |
| wTXID | Yes | Block commitment, full validation. |
In the final section, we will build a Python Witness Parser.
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: