2

Based on https://en.bitcoin.it/wiki/Getblocktemplate :

Collect your coinbase transaction (modified or not) at the front of the "transactions" list provided by the server. Apply a double-SHA256 hash to each transaction in the list. Now, as long as the list has more than 1 hash remaining, go through each pair and hash them together. That is, concatenate the first two, double-SHA256 that, repeat for the next two, and so on. If you encounter an odd pair (that is, the hash list ends with a single item and no pairing), concatenate it with itself and hash that. Continue to do that until there is only one hash left: that is your merkle root.

But what if the block is empty? Since there is no other transaction other than the coinbase transaction, it means there is only one hash.

Is the merkle root of an empty block the double hash of the coinbase transaction? Or do I still need to do something other than double hashing the coinbase?

1 Answer 1

3

If the coinbase transaction is the only transaction in a block, then the block's transaction Merkle root is equal to the coinbase transaction's txid.

9
  • what is txid ? i cant find it on the getblocktemplate wiki . And do i need to hash the coinbase transaction txid or just straight up merkleroot = txid without hash ? Sep 27, 2021 at 14:20
  • The txid is the double-SHA256 hash of the serialized transaction. The merkle root is identical to the txid, without any further hashing. Sep 27, 2021 at 14:38
  • Oh thank you ! but i found this on google bitcoin.stackexchange.com/questions/97162/… , it says merkle root is equal to the double sha256 of txid0 + txid0 , which one is correct , your answer or the link i just give ? i'm confused Sep 27, 2021 at 14:40
  • For the third time: the Merkle root IS the txid, without further hashing. Your link is about the case where you have an odd number of elements in a level, but larger than 1, in order to compute the next level. When a level has only 1 element left, that is the Merkle root. If the coinbase is the only transaction, you already reached the end. Sep 27, 2021 at 14:42
  • So Merkle root = sha256d(txid0 + txid0) is incorrect ? Sep 27, 2021 at 14:43

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.