<blockquote>
  <p>Is data that hashed as txid includes witness?</p>
</blockquote>

<p>No, the txid is the hash of just <code>[nVersion][txins][txouts][nLockTime]</code> which is the same as a serialized non-witness transaction. That means the signature is not included in the transaction hash, removing the potential for TXID malleability due to mauling the signature. Only WTXID contains the witness, marker and flag as you wrote in your post.</p>

<blockquote>
  <p>And will txid be presented in block, e.g. be counted when building Merkle tree?</p>
</blockquote>

<p>Yes, the transaction ID is used in the same way that non-segwit TXIDs are used when building the merkle tree.</p>

CC BY-SA 3.0
2017-11-06T05:03:08.980Z
Are SegWit txins have different data structure with non-SegWit txins, like SegWit txins doesn't include ScriptSig but non-SegWit txins do?
fjchen
CC BY-SA 3.0
2017-11-06T05:57:34.593Z
Segwit inputs still have a ScriptSig as all inputs must have one. However those ScrtiptSigs will just be empty. Transactions that spend from Segwit outputs will have a slightly different structure; there will be an additional field following the outputs for the witness data. See BIP 144: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki
Ava Chow
CC BY-SA 3.0
2017-11-06T01:36:38.023Z
2017-11-06T01:36:38.023Z
meshcollider
<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="nofollow noreferrer">BIP141</a> says wtxid is SHA256 of [nVersion][marker][flag][txins][txouts][witness][nLockTime]. Is data that hashed as txid includes witness?</p>

<p>And will txid be presented in block, e.g. be counted when building Merkle tree?</p>

<segregated-witness><transaction-id>
How to compute SegWit txid?
fjchen
# How to compute SegWit txid?

(Asked by: username_0 on 2017-11-06)

[BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki) says wtxid is SHA256 of [nVersion][marker][flag][txins][txouts][witness][nLockTime]. Is data that hashed as txid includes witness?

And will txid be presented in block, e.g. be counted when building Merkle tree?

**Tags:** segregated-witness, transaction-id


---

## 1 answers

### Answer by username_1 on 2017-11-06. Score: 4

> Is data that hashed as txid includes witness?

No, the txid is the hash of just `[nVersion][txins][txouts][nLockTime]` which is the same as a serialized non-witness transaction. That means the signature is not included in the transaction hash, removing the potential for TXID malleability due to mauling the signature. Only WTXID contains the witness, marker and flag as you wrote in your post.

> And will txid be presented in block, e.g. be counted when building Merkle tree?

Yes, the transaction ID is used in the same way that non-segwit TXIDs are used when building the merkle tree.

> **Comments:**
> **username_0**: Are SegWit txins have different data structure with non-SegWit txins, like SegWit txins doesn't include ScriptSig but non-SegWit txins do?  
> **username_2**: Segwit inputs still have a ScriptSig as all inputs must have one. However those ScrtiptSigs will just be empty. Transactions that spend from Segwit outputs will have a slightly different structure; there will be an additional field following the outputs for the witness data. See BIP 144: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki  

---

