<p>If the client is SegWit enabled, the full transaction including witness data can be stored in the same format as the transaction is received over the wire. There is no need for separate storage - it can all be included in the block.</p>

<p>If the client is not SegWit enabled, SegWit transactions are stripped of their witness and the witness marker/flag before sending/receiving, so these clients will not receive witness data, and therefore will not store it at all and will only use the legacy format.</p>

<p>This means the block storage between the two clients is different, but they are still sharing the same blockchain and transaction history.</p>

<p>Compatibility is made possible because even when SegWit is used and the witness is present, the SegWit client will calculate a <code>txid</code> by stripping the transaction back to its legacy format (removing the witness parts) before hashing. The <code>txid</code> is common between the SegWit and non-SegWit clients as a means to identify which transaction is being referred to. SegWit clients can identify data by a <code>wtxid</code> too, which is the hash of the serialized transaction with witness format - but this <code>wtxid</code> is not used as part of a <code>txOutPoint</code> to refer to a previous transaction - the <code>txid</code> is always used.</p>

<p>SegWit transactions are forward compatible with non-supporting software clients because the transaction with its witness data stripped from it appears as though it is an ANYONECANSPEND transaction - the stack is left with a non-zero value on top after evaluating the <code>scriptPubKey</code>, which is indicates successful evaluation.</p>

CC BY-SA 4.0
2020-11-02T14:42:36.683Z
I read @Guillaume07 question as more related to the [block serialization structure](https://en.bitcoin.it/wiki/Block) rather than the TXN serialization structure.  Obviously the witness data is thunked into the TXN after the fact and must exist outside of the normal block serialization to exist at all.

To Guillaume07 question, I think it is just concatenated on to the end of the block.  Non-segwit clients will just stop parsing after the last TXN, and segwit clients would keep scanning.

The witness merkel tree is stored in the coinbase TXN as an OP_RETURN UTXO.
Dan
CC BY-SA 4.0
2019-08-30T10:35:35.200Z
2019-08-30T10:35:35.200Z
Mark H
<p>Since segregated witness is in place inside Bitcoin blockchain, my understanding is that witness data are no longer stored inside the blocks, so if blocks are linked to each other where theirs corresponding witness data are stored ? There is a parallel block chain ?</p>

<blockchain><segregated-witness>
Witness data storage localisation in the blockchain
Guillaume Paris
# Witness data storage localisation in the blockchain

(Asked by: username_0 on 2019-08-30)

Since segregated witness is in place inside Bitcoin blockchain, my understanding is that witness data are no longer stored inside the blocks, so if blocks are linked to each other where theirs corresponding witness data are stored ? There is a parallel block chain ?

**Tags:** blockchain, segregated-witness


---

## 1 answers

### Answer by username_1 on 2019-08-30. Score: 1

If the client is SegWit enabled, the full transaction including witness data can be stored in the same format as the transaction is received over the wire. There is no need for separate storage - it can all be included in the block.

If the client is not SegWit enabled, SegWit transactions are stripped of their witness and the witness marker/flag before sending/receiving, so these clients will not receive witness data, and therefore will not store it at all and will only use the legacy format.

This means the block storage between the two clients is different, but they are still sharing the same blockchain and transaction history.

Compatibility is made possible because even when SegWit is used and the witness is present, the SegWit client will calculate a `txid` by stripping the transaction back to its legacy format (removing the witness parts) before hashing. The `txid` is common between the SegWit and non-SegWit clients as a means to identify which transaction is being referred to. SegWit clients can identify data by a `wtxid` too, which is the hash of the serialized transaction with witness format - but this `wtxid` is not used as part of a `txOutPoint` to refer to a previous transaction - the `txid` is always used.

SegWit transactions are forward compatible with non-supporting software clients because the transaction with its witness data stripped from it appears as though it is an ANYONECANSPEND transaction - the stack is left with a non-zero value on top after evaluating the `scriptPubKey`, which is indicates successful evaluation.

> **Comments:**
> **username_2**: I read @Guillaume07 question as more related to the [block serialization structure](https://en.bitcoin.it/wiki/Block) rather than the TXN serialization structure.  Obviously the witness data is thunked into the TXN after the fact and must exist outside of the normal block serialization to exist at all.  To Guillaume07 question, I think it is just concatenated on to the end of the block.  Non-segwit clients will just stop parsing after the last TXN, and segwit clients would keep scanning.  The witness merkel tree is stored in the coinbase TXN as an OP_RETURN UTXO.  

---

