THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Witness Commitment Explained: Coinbase, Merkle Roots, and BIP141

permalink THAMER
#bip141#coinbase#witness-commitment#witness-merkle-root

Bitcoin block headers contain a Merkle root of transaction IDs, but that root alone does not commit to the witness data of SegWit transactions. BIP141 adds a witness commitment carried in the coinbase transaction.

Two different Merkle constructions

The conventional transaction Merkle tree is built from TXIDs and its root appears in the 80-byte block header. The witness Merkle tree uses WTXIDs, except that the coinbase leaf is defined as 32 zero bytes. These two roots serve different purposes.

Where the commitment lives

The coinbase transaction contains an output with an OP_RETURN script beginning with the witness commitment header bytes 6a24aa21a9ed, followed by a 32-byte commitment hash. That hash is double-SHA256 of the witness Merkle root concatenated with the 32-byte witness reserved value from the coinbase input witness. If multiple outputs match the witness commitment pattern, the highest output index is selected by the BIP141 rules.

Why a coinbase output can commit to witness data

The coinbase TXID is included in the ordinary Merkle root, which is in the block header. By placing the witness commitment in the coinbase output, the block's proof-of-work header indirectly commits to the witness tree as well. This links witness validation to the mined block without putting the witness root directly in the header.

Validation is more than checking a hash

A matching commitment does not by itself establish that signatures are valid or that all spending rules were followed. Fully validating nodes also check transaction inputs, scripts, consensus limits, and other block rules.

Primary references

Bitcoin Developer Reference — Transactions: https://developer.bitcoin.org/reference/transactions.html
BIP141 — Segregated Witness: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki
BIP144 — Segregated Witness Peer Services: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects