3

What is the relationship between transaction data and transaction id (which is used at mempool to generate Merkle root)?

Note : when we query the getblock with verbosity 2, we get raw block in json format. at the transactions part, each transaction have 3 suspicious part :

  1. txid (transaction id)
  2. hash
  3. hex (which is raw transaction in hex string format)

I am looking for a relatio between these three parameters.

1 Answer 1

7

Since BIP144, transaction data consists of two parts (normal data and witness data). There are also two distinct transaction serialization formats:

  • The legacy serialization format, which stores version number, transaction inputs, transaction outputs, and locktime.
  • The extended serialization format, which also has a flag/marker to indicate the extended format is in use, and has witness data for every transaction input.

The extended format must be used if witness data is present. The legacy format must be used if no witness data is present.

The txid is the double-SHA256 hash of the serialized transaction in legacy format, meaning that any witness data has to be stripped out (as the legacy format does not support witness data). If the transaction had no witness data in the first place (as pre-segwit transaction do), the txid is just the hash of the serialized transaction.

The hash (or wtxid) of a transaction is the double-SHA256 hash of the serialization including potential witness data. If the transaction contains no witness data, this is identical to the txid.

2
  • 1
    Pieter Wuille, Thanks for your knowledge. But now which on of them (txid or wtxid) is used for merkle root ? (Which is on output of getrawmempool when transaction is on mempool)
    – Ali
    Mar 4, 2023 at 20:34
  • 5
    Both. The txid is included in the normal Merkle tree (whose root is in the block header). The wtxids are also included in another Merkle tree (whose root is included in the coinbase transaction output in an OP_RETURN; see BIP141). Mar 4, 2023 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.