Marker and Flag Bytes
Marker and Flag Bytes
To maintain backward compatibility with old nodes, SegWit transactions use a clever trick involving two special bytes: the Marker and the Flag.
1. The Backward Compatibility Problem
Old nodes (pre-2017) don't know about SegWit. If they see a transaction with an empty ScriptSig and a massive block of data at the end, they might crash or reject the transaction as invalid.
2. The Solution: The "Empty Input" Trick
In a SegWit transaction, the bytes 00 01 are placed immediately after the 4-byte Version number.
-
00 (Marker): To an old node, this looks like an input count of zero.
-
01 (Flag): To an old node, this looks like a non-empty flag that it doesn't recognize.
Because old nodes see "zero inputs," they assume the transaction is some kind of special "Anyone Can Spend" output and they ignore the data at the end. Modern nodes, however, recognize 00 01 as the signal to look for the Witness.
3. The 0x00 Marker
The Marker is always 0x00. It ensures that the transaction structure is fundamentally different from a legacy transaction, which would have an input count of at least 1 at that position.
4. The 0x01 Flag
The Flag is currently 0x01. This allows for future upgrades to the Witness structure. If Bitcoin ever introduces a second type of witness data, it could use 0x02.
5. Visualizing the Byte Stream
[Version: 01000000]
[Marker: 00]
[Flag: 01]
[Inputs...]
[Outputs...]
[Witness...]
[Locktime: 00000000]
The Marker and Flag are stripped when calculating the TXID. This is why SegWit transactions can have a different "Hash" (TXID) than their "Witness Hash" (wTXID).
In the next section, we will discuss the Witness Items and Count.
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: