TXID vs. wTXID Calculation
TXID vs. wTXID Calculation
The difference between a TXID and a wTXID comes down to exactly which bytes are fed into the hashing algorithm. Bitcoin uses Double SHA256 (hash256) for both.
1. Calculating the TXID
To calculate the TXID of a SegWit transaction, a node must first "strip" the witness data.
-
Data Stream: [Version] [Inputs (minus witness)] [Outputs] [Locktime]
-
Algorithm:
SHA256(SHA256(Stripped_Bytes)) -
Result: The 32-byte identifier used to spend the transaction's outputs.
2. Calculating the wTXID
To calculate the wTXID, the node uses the full, unstripped serialization.
-
Data Stream: [Version] [Marker (00)] [Flag (01)] [Inputs] [Outputs] [Witness Stack] [Locktime]
-
Algorithm:
SHA256(SHA256(Full_Bytes)) -
Result: The 32-byte identifier used to verify the integrity of the witnesses in the block.
3. The "Identity Trap"
Because the TXID ignores the witness, two transactions with different signatures but identical inputs and outputs will have the exact same TXID.
-
In the legacy model, this would be a "TXID Collision."
-
In the SegWit model, this is a feature. It means that even if a miner "malleates" your signature, the TXID remains the same, so any "child" transactions you sent that reference that TXID will still be valid.
4. Why exclude Marker/Flag from TXID?
The Marker (00) and Flag (01) bytes are excluded from the TXID to ensure that SegWit transactions look like valid legacy transactions to old nodes. If those bytes were included, old nodes would see a version mismatch or a corrupted input list.
| Field | In TXID? | In wTXID? |
|---|---|---|
| Version | Yes | Yes |
| Marker/Flag | No | Yes |
| Input TXIDs | Yes | Yes |
| Outputs | Yes | Yes |
| Witness Data | No | Yes |
| Locktime | Yes | Yes |
In the next section, we will look at the Witness Merkle Tree.
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: