<blockquote>
<p><strong>the marker would need to be 0 for old nodes to treat the transaction as valid. [...] Is there something I'm missing?</strong></p>
</blockquote>
<p>What you may be missing is that old (pre-segwit) nodes never see segwit data, when segwit nodes send data to pre-segwit nodes they edit out all the segwit fields.</p>
<p>Part of the protocol handshake identifies segwit nodes</p>
<p>Consequently the marker is always zero and the only currently defined value for the flag is 1 (as far as I know). When parsing I rely on the marker being zero, to distinguish it from an input count, but I allow for any non zero value of flag.</p>
<hr />
<blockquote>
<p><strong>Rationale for not using just a single 0x00 byte as marker</strong>: that would lead to empty transactions (no inputs, no outputs, which are used in some tests) to be interpreted as new serialized data</p>
</blockquote>
<p>This says that the 0x00 marker <a href="https://en.wikipedia.org/wiki/Necessity_and_sufficiency" rel="nofollow noreferrer">is <em>necessary</em> but is <em>not sufficient</em></a> to reliably distinguish pre-segwit transaction serialisation from segwit transaction serialisation.</p>
<p>I believe it claims you need the additional flag to distinguish a segwit transaction (with any number of inputs) from a pre-segwit transaction that has no inputs (input count = 0).</p>
<p>I don't think this is actually true for mainnet†. I think there are no transactions using the pre-segwit serialisation that have no inputs. Perhaps it is true for one of the other Bitcoin networks (testnet etc). I wrote a parser that would fail if fed a pre-segwit transaction with no inputs - It hasn't failed but admittedly I haven't tested it against <em>every</em> transaction in the whole mainnet blockchain.</p>
<hr />
<p><strong>Related</strong></p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/q/84041/13866">What&#39;s the segwit transaction serialization &quot;flag&quot; field for?</a></li>
</ul>
<hr />
<p><strong>Footnotes</strong></p>
<p><strong>† Minimum number of inputs</strong></p>
<ol>
<li><p><a href="https://developer.bitcoin.org/devguide/transactions.html" rel="nofollow noreferrer">https://developer.bitcoin.org/devguide/transactions.html</a> says</p>
<blockquote>
<p>Each transaction has at least one input</p>
</blockquote>
</li>
<li><p><a href="https://bitcoin.stackexchange.com/q/91020/13866">How to create a bitcoin transaction without inputs</a></p>
<blockquote>
<p>Only the coinbase transaction is allowed to have a null, or non-existent input [...] Coinbase transactions have inputs. They just reference null outpoints</p>
</blockquote>
</li>
</ol>

CC BY-SA 4.0
2023-04-02T15:25:44.367Z
Thank you for your response. I understand why it needs to be 0.

The point I'm confused about is the 'not' in the "Rationale for not using just a single 0x00 bytes as marker." As English is not my first language and I'm newbie in Bitcoin dev space, so I'm not sure if I understood correctly. Is it correct that this word 'not' should be deleted?

Additionally, can you give me a hint to help me check it in the code?
Gildong.Hong
CC BY-SA 4.0
2023-04-02T15:44:28.523Z
The "not" applies to the "single" - I'll update my answer to elaborate a bit how I interpret this.
RedGrittyBrick
CC BY-SA 4.0
2023-04-02T23:03:07.143Z
This is correct. *Just* a zero byte marker would be insufficient, which is why there is a marker plus a flag byte. And @RedGrittyBrick is technically right that 0-input transaction are strictly speaking illegal anyway, however they are (or at least were) common when dealing with incomplete/unsigned transactions that were being passed around before people were done adding inputs/outputs to them. Even though these are never allowed on chain, we needed to be unambiguous w.r.t. those as well.
Pieter Wuille
CC BY-SA 4.0
2023-04-02T14:59:37.340Z
2023-04-02T16:34:36.517Z
2023-04-02T16:34:36.517Z
RedGrittyBrick
<p>Reading at the Specification chapter in the <a href="https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki" rel="nofollow noreferrer">BIP-0144</a> document, there seems to be conflicting statements.</p>
<p>The Description of the marker field in the table says &quot;Must be zero&quot;</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Field Size</th>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>1</td>
<td>marker</td>
<td>char</td>
<td><strong>Must be zero</strong></td>
</tr>
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
</div>
<p>However, what follows description is:</p>
<blockquote>
<p><strong>Rationale for not using just a single 0x00 byte as marker</strong>: that would lead to empty transactions (no inputs, no outputs, which are used in some tests) to be interpreted as new serialized data</p>
</blockquote>
<p>As I understand it, the marker would need to be 0 for old nodes to treat the transaction as valid. So it looks like the 'not' should be removed from this sentence. Is there something I'm missing?</p>
<p>Would you also point me in the direction of where to look in the Bitcoin Core code?</p>

<segregated-witness>
Which value is appropriate for the MARKER field of a segwit tx messages: 0x00 or nonzero?
Gildong.Hong
# Which value is appropriate for the MARKER field of a segwit tx messages: 0x00 or nonzero?

(Asked by: username_0 on 2023-04-02)

Reading at the Specification chapter in the [BIP-0144](https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki) document, there seems to be conflicting statements.

The Description of the marker field in the table says "Must be zero"

| Field Size | Name | Type | Description |
| --- | --- | --- | --- |
| ... | ... | ... | ... |
| 1 | marker | char | **Must be zero** |
| ... | ... | ... | ... |

However, what follows description is:

> **Rationale for not using just a single 0x00 byte as marker**: that would lead to empty transactions (no inputs, no outputs, which are used in some tests) to be interpreted as new serialized data

As I understand it, the marker would need to be 0 for old nodes to treat the transaction as valid. So it looks like the 'not' should be removed from this sentence. Is there something I'm missing?

Would you also point me in the direction of where to look in the Bitcoin Core code?

**Tags:** segregated-witness


---

## 1 answers

### Answer by username_1 on 2023-04-02. Score: 2 | Accepted answer

> **the marker would need to be 0 for old nodes to treat the transaction as valid. [...] Is there something I'm missing?**

What you may be missing is that old (pre-segwit) nodes never see segwit data, when segwit nodes send data to pre-segwit nodes they edit out all the segwit fields.

Part of the protocol handshake identifies segwit nodes

Consequently the marker is always zero and the only currently defined value for the flag is 1 (as far as I know). When parsing I rely on the marker being zero, to distinguish it from an input count, but I allow for any non zero value of flag.

---

> **Rationale for not using just a single 0x00 byte as marker**: that would lead to empty transactions (no inputs, no outputs, which are used in some tests) to be interpreted as new serialized data

This says that the 0x00 marker [is *necessary* but is *not sufficient*](https://en.wikipedia.org/wiki/Necessity_and_sufficiency) to reliably distinguish pre-segwit transaction serialisation from segwit transaction serialisation.

I believe it claims you need the additional flag to distinguish a segwit transaction (with any number of inputs) from a pre-segwit transaction that has no inputs (input count = 0).

I don't think this is actually true for mainnet†. I think there are no transactions using the pre-segwit serialisation that have no inputs. Perhaps it is true for one of the other Bitcoin networks (testnet etc). I wrote a parser that would fail if fed a pre-segwit transaction with no inputs - It hasn't failed but admittedly I haven't tested it against *every* transaction in the whole mainnet blockchain.

---

**Related**

* [What's the segwit transaction serialization "flag" field for?](https://bitcoin.stackexchange.com/q/84041/13866)

---

**Footnotes**

**† Minimum number of inputs**

1. <https://developer.bitcoin.org/devguide/transactions.html> says

   > Each transaction has at least one input
2. [How to create a bitcoin transaction without inputs](https://bitcoin.stackexchange.com/q/91020/13866)

   > Only the coinbase transaction is allowed to have a null, or non-existent input [...] Coinbase transactions have inputs. They just reference null outpoints

> **Comments:**
> **username_0**: Thank you for your response. I understand why it needs to be 0.  The point I'm confused about is the 'not' in the "Rationale for not using just a single 0x00 bytes as marker." As English is not my first language and I'm newbie in Bitcoin dev space, so I'm not sure if I understood correctly. Is it correct that this word 'not' should be deleted?  Additionally, can you give me a hint to help me check it in the code?  
> **username_1**: The "not" applies to the "single" - I'll update my answer to elaborate a bit how I interpret this.  
> **username_2**: This is correct. *Just* a zero byte marker would be insufficient, which is why there is a marker plus a flag byte. And @username_1 is technically right that 0-input transaction are strictly speaking illegal anyway, however they are (or at least were) common when dealing with incomplete/unsigned transactions that were being passed around before people were done adding inputs/outputs to them. Even though these are never allowed on chain, we needed to be unambiguous w.r.t. those as well.  

---

