<p>A segwit block's coinbase transaction must contain an output with a commitment to the <a href="https://bitcoin.stackexchange.com/a/79754/60443">witness root hash</a>, see <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure" rel="nofollow noreferrer">BIP141</a>.</p>

<blockquote>
  <p>The commitment is recorded in a scriptPubKey of the coinbase transaction. It must be at least 38 bytes, with the first 6-byte of <code>0x6a24aa21a9ed</code>, that is:</p>
</blockquote>

<pre><code>1-byte - OP_RETURN (0x6a)
   1-byte - Push the following 36 bytes (0x24)
   4-byte - Commitment header (0xaa21a9ed)
  32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)
</code></pre>

<blockquote>
  <p>39th byte onwards: Optional data with no consensus meaning</p>
  
  <p>and the coinbase's input's witness must consist of a single 32-byte array for the witness reserved value.</p>
  
  <p>If there are more than one scriptPubKey matching the pattern, the one with highest output index is assumed to be the commitment. </p>
</blockquote>

<p>At the transaction level, a segwit transaction must set the witness flag to 0001, and provide the witnesses before the locktime. A non-segwit transaction contains neither of these properties.</p>

<p><a href="https://i.sstatic.net/LGmaN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LGmaN.png" alt="Transaction Structure"></a></p>

<p>See <a href="https://en.bitcoin.it/wiki/Transaction#General_format_of_a_Bitcoin_transaction_.28inside_a_block." rel="nofollow noreferrer">Bitcoin Wiki - Transaction</a></p>

CC BY-SA 4.0
2019-01-15T21:24:03.603Z
2019-01-17T01:37:28.903Z
2019-01-17T01:37:28.903Z
JBaczuk
<p>A segwit block differs from a non-segwit block in that it is required to have the witness commitment in an OP_RETURN output of the coinbase transaction. Additionally, the block will contain witness data (duh!) which due to blocksize limit increase to 4,000,000 weight units allows  the block to exceed the former blocksize limit of 1 MB.</p>

<p>Segwit introduced the witness transaction id (wtxid) for each transaction in addition to the regular transaction id (txid). The txid does not cover witness data and thus prevents transactions that only use segwit inputs from being subject to third party transaction malleability (see <a href="/questions/tagged/transaction-malleability" class="post-tag" title="show questions tagged &#39;transaction-malleability&#39;" rel="tag">transaction-malleability</a>). The wtxid does cover the signature data contained in the witness and thus is still susceptible. For non-segwit transactions the wtxid equals the txid and they continue to be susceptible.</p>

<p>In order for the block to commit to the witness data of transactions which is not covered by the regular Merkle root in the block header, a second Merkle tree is calculated from the wtxids and committed to in the aforementioned witness commitment in the Coinbase output.</p>

<p>If a block does not contain any segwit transactions, the witness commitment is optional.</p>

<ul>
<li>You can read about the witness commitment structure here: <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure" rel="nofollow noreferrer">BIP0141</a></li>
<li><p>You can see the witness commitment of the latest block (558722) here:
<a href="https://i.sstatic.net/u9Z7b.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/u9Z7b.png" alt="Showing the commitment transaction of block height 558722"></a></p>

<p><sup>via <a href="https://blockstream.info/tx/94819ee73fe47480afaeb7a7696ee31fdc2e6039831944360555127e419c0be0#expand" rel="nofollow noreferrer">blockstream.info</a></sup></p></li>
</ul>

CC BY-SA 4.0
2019-01-16T03:32:21.113Z
2019-01-16T03:40:39.923Z
2019-01-16T03:40:39.923Z
Murch
<p>Is there any difference in the structure of a segwit block in comparison to a traditional non-segwit block? A diagram would be helpful if possible.</p>

<block><segregated-witness>
How does the structure of a segwit block differ from a non-segwit block?
Nathaniel Richardson
# How does the structure of a segwit block differ from a non-segwit block?

(Asked by: username_0 on 2019-01-15)

Is there any difference in the structure of a segwit block in comparison to a traditional non-segwit block? A diagram would be helpful if possible.

**Tags:** block, segregated-witness


---

## 2 answers

### Answer by username_1 on 2019-01-15. Score: 4

A segwit block's coinbase transaction must contain an output with a commitment to the [witness root hash](https://bitcoin.stackexchange.com/a/79754/60443), see [BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure).

> The commitment is recorded in a scriptPubKey of the coinbase transaction. It must be at least 38 bytes, with the first 6-byte of `0x6a24aa21a9ed`, that is:

```
1-byte - OP_RETURN (0x6a)
   1-byte - Push the following 36 bytes (0x24)
   4-byte - Commitment header (0xaa21a9ed)
  32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)

```

> 39th byte onwards: Optional data with no consensus meaning
>
> and the coinbase's input's witness must consist of a single 32-byte array for the witness reserved value.
>
> If there are more than one scriptPubKey matching the pattern, the one with highest output index is assumed to be the commitment.

At the transaction level, a segwit transaction must set the witness flag to 0001, and provide the witnesses before the locktime. A non-segwit transaction contains neither of these properties.

[![Transaction Structure](https://i.sstatic.net/LGmaN.png)](https://i.sstatic.net/LGmaN.png)

See [Bitcoin Wiki - Transaction](https://en.bitcoin.it/wiki/Transaction#General_format_of_a_Bitcoin_transaction_.28inside_a_block.)


---

### Answer by username_2 on 2019-01-16. Score: 3

A segwit block differs from a non-segwit block in that it is required to have the witness commitment in an OP\_RETURN output of the coinbase transaction. Additionally, the block will contain witness data (duh!) which due to blocksize limit increase to 4,000,000 weight units allows the block to exceed the former blocksize limit of 1 MB.

Segwit introduced the witness transaction id (wtxid) for each transaction in addition to the regular transaction id (txid). The txid does not cover witness data and thus prevents transactions that only use segwit inputs from being subject to third party transaction malleability (see [transaction-malleability](/questions/tagged/transaction-malleability "show questions tagged 'transaction-malleability'")). The wtxid does cover the signature data contained in the witness and thus is still susceptible. For non-segwit transactions the wtxid equals the txid and they continue to be susceptible.

In order for the block to commit to the witness data of transactions which is not covered by the regular Merkle root in the block header, a second Merkle tree is calculated from the wtxids and committed to in the aforementioned witness commitment in the Coinbase output.

If a block does not contain any segwit transactions, the witness commitment is optional.

* You can read about the witness commitment structure here: [BIP0141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure)
* You can see the witness commitment of the latest block (558722) here:
  [![Showing the commitment transaction of block height 558722](https://i.sstatic.net/u9Z7b.png)](https://i.sstatic.net/u9Z7b.png)

  via [blockstream.info](https://blockstream.info/tx/94819ee73fe47480afaeb7a7696ee31fdc2e6039831944360555127e419c0be0#expand)


---

