Overview
In Bitcoin, the witness is the data that proves authorization to spend a UTXO — typically consisting of digital signatures and public keys. With the introduction of Segregated Witness (SegWit), this authorization data was moved ("segregated") from the main transaction body into a separate witness structure, solving transaction malleability and enabling the witness discount.
Pre-SegWit vs. SegWit Transaction Structure
Pre-SegWit Transaction:
┌────────────────────────────────────┐
│ Version │
│ Inputs: │
│ Previous TXID + Index │
│ ScriptSig (signature + pubkey) │ ← Witness data
│ Sequence │ inside tx body
│ Outputs: │
│ Value + ScriptPubKey │
│ Locktime │
└────────────────────────────────────┘
TXID = Hash(entire structure above)
SegWit Transaction:
┌────────────────────────────────────┐
│ Version │
│ Marker + Flag (0x0001) │
│ Inputs: │
│ Previous TXID + Index │
│ ScriptSig (empty for native) │
│ Sequence │
│ Outputs: │
│ Value + ScriptPubKey │
│ Witness: │
│ [signature, pubkey] │ ← Separated!
│ Locktime │
└────────────────────────────────────┘
TXID = Hash(structure WITHOUT witness)
Why Segregation Matters
By moving witness data outside the TXID calculation:
- Malleability fix: Modifying witness data no longer changes the TXID, enabling reliable transaction chaining essential for the Lightning Network.
- Fee discount: Witness bytes are counted at one-quarter weight (the witness discount), incentivizing SegWit adoption and effectively increasing block capacity.
- Script versioning: The witness structure includes a version byte, enabling future script upgrades (like Tapscript) without disrupting existing transaction formats.
Witness in Taproot
Taproot transactions use witness version 1. For key-path spends, the witness contains a single 64-byte Schnorr signature. For script-path spends, the witness includes the script, a Merkle proof of the script's inclusion in the script tree, and the data satisfying the script's conditions.
Common Misconceptions
The witness is not optional for SegWit transactions — it is required for the transaction to be valid. The term "segregated" means the witness data is structurally separated from the part of the transaction used to compute the TXID, not that it can be discarded. Full nodes store and validate witness data; it is only excluded from the TXID hash.