Home › Glossary › Witness

Witness

Also called: witness data, scriptWitness, witness stack, segregated witness data, wtxid.

The witness is the part of a SegWit transaction that holds signatures and scripts, kept out of the txid so it can't be changed to alter the transaction ID.

The witness is the data that proves a transaction is allowed to spend its inputs: mainly signatures, public keys and scripts. SegWit (BIP 141) moved this data out of the main transaction body into a separate structure. Each input gets its own witness, a list (stack) of byte strings.

How witness data works

  • Not in the txid. The txid is still the double SHA-256 of the transaction without witness data, so changing a signature can't change it. This fixed third-party transaction malleability. A second ID, the wtxid, covers the witness too.
  • Serialization. BIP 144 adds a marker byte 0x00 and flag byte 0x01 after the version field, and puts the witnesses after the outputs.
  • Commitment. Each block commits to all wtxids through a Merkle tree whose root goes in an OP_RETURN output of the coinbase transaction, starting with the bytes 0x6a24aa21a9ed.
  • Discount. Each witness byte counts as 1 weight unit instead of 4 (block weight), so witness-heavy spends cost fewer vbytes.

Witness versions

An output's witness version (0 to 16) says how its witness is checked. Version 0 covers P2WPKH (witness: signature and public key) and P2WSH (witness: inputs plus the script). Version 1 is Taproot (BIP 341): a key path witness is a single 64- or 65-byte Schnorr signature, while a script path witness ends with the script and a control block. The remaining versions are reserved for future soft forks.

Signatures in version 0 witnesses use the BIP 143 sighash algorithm.

BIPs that define Witness

Related terms

  • SegWit (Segregated Witness): SegWit (Segregated Witness) is the 2017 soft fork that moved signatures into a separate witness, fixing malleability and introducing block weight.
  • Transaction malleability: Transaction malleability is the ability to change a transaction's ID without changing what it does, for example by re-encoding its signatures.
  • Block weight: Block weight is the SegWit-era measure of block size: non-witness bytes count 4 units and witness bytes 1, with a limit of 4,000,000 weight units.
  • Taproot: Taproot is the 2021 Bitcoin soft fork (BIPs 340, 341, 342) that added Schnorr signatures and P2TR outputs which hide unused spending conditions.

Learn more

Guides