TeachMeBitcoin

Witness Items & Count

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

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:

  1. The ECDSA Signature.

  2. 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.

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.

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.

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