Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Picard78 on July 30, 2020, 04:37:27 AM



Title: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: Picard78 on July 30, 2020, 04:37:27 AM
Hello Bitcoin Expert,

I understand how Merkle trees are created and how they are used to quickly verify a transaction in a block but I don’t understand how or why they are used.

A google search presents the following:

Quote
Merkle trees enable SPV nodes on the blockchain to check if miners have verified the transactions in a block without downloading all the transactions in a block.

What I don’t understand is that once a Transaction is in a confirmed Block why does it have to be verified?  Once it is in a confirmed Block the transaction is verified and immutable. 

I watched this video by Andreas https://www.youtube.com/watch?v=OdjEhNdvTNM (https://www.youtube.com/watch?v=OdjEhNdvTNM) and he mentions Side Chains but I still don't understand why we need to confirm a transaction has been verified in a confirmed block.

Thank you.


Title: Re: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: ranochigo on July 30, 2020, 04:40:39 AM
SPV wallets do not download the entire block. They only download the block headers.

The block header contains the merkle root among other stuff. By downloading the block headers only, the SPV wallet saves a lot of bandwidth and space. With the block header, the SPV node can verify if the block has sufficient target and can also use the merkle root to verify if a transaction has indeed been included in that specific block.

Even if it isn't about SPV nodes, by constructing the merkle root, you're basically telling everyone all the transactions that has been included in the block. Only the block header is hashed, the individual transactions aren't. Merkle root is the way to include transactions in your block. Read up on how the bitcoin block is constructed to get a more in depth understanding.


Title: Re: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: nc50lc on July 30, 2020, 06:41:48 AM
I suggest you to read about "merkle path" in page 167-168 of Andreas M. Antonopoulos's Mastering Bitcoin.
You'll understand how SPV nodes can efficiently verify its transactions using the merkle root which is in the blockheader.

Here's the wiki page with links: https://en.bitcoin.it/wiki/Mastering_Bitcoin (https://en.bitcoin.it/wiki/Mastering_Bitcoin)


Title: Re: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: Husires on July 30, 2020, 03:17:58 PM
The Merklre Tree greatly interferes with this process since its hashes are compressed from roots to the top.  
Even changing one value for a transaction at the base of the tree, change to all the hash values, up to the root's hash value.
Thus a single value prove all the transactions under it and not need to hash the full list of transactions.


source:
https://github.com/bitcoinbook/bitcoinbook/blob/14a25a6fd9e97002c57a46f1fe9faf48cd5d6e46/ch07.asciidoc#merkle-trees


Title: Re: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: Picard78 on July 31, 2020, 04:00:38 AM
Quote
Even if it isn't about SPV nodes, by constructing the merkle root, you're basically telling everyone all the transactions that has been included in the block. Only the block header is hashed, the individual transactions aren't.


I see only the Block Header is hashed, so the Merkle Root confirms the data integrity of the Transactions Data.

My next question is why are the Transactions not included in the Block Header Hash as well. 

A decent answer is here https://bitcoin.stackexchange.com/questions/60676/why-is-only-the-block-header-sha256-hashed-and-not-the-whole-block (https://bitcoin.stackexchange.com/questions/60676/why-is-only-the-block-header-sha256-hashed-and-not-the-whole-block)

Quote
it makes the speed of mining independent from the number of transactions.


Title: Re: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: nc50lc on July 31, 2020, 05:08:55 AM
Quote
Even if it isn't about SPV nodes, by constructing the merkle root, you're basically telling everyone all the transactions that has been included in the block. Only the block header is hashed, the individual transactions aren't.
My next question is why are the Transactions not included in the Block Header Hash as well.  
Since you're talking about "Block Header Hash", it's about mining, then that quote from the "decent answer" is the answer.

In case you've missed this info from that link and from this thread as well:
the merkle root is part of the Block header and if you hash the block header, you indirectly hashed all the transactions in that block because the merkle root is the root hash of all the txs in the block.


Title: Re: What is the purpose of the Merkle Root in a Bitcoin block?
Post by: Picard78 on July 31, 2020, 05:54:34 AM
Quote
In case you've missed this info from that link and from this thread as well:
the merkle root is part of the Block header and if you hash the block header, you indirectly hashed all the transactions in that block because the merkle root is the root hash of all the txs in the block.


That's true.  Thanks for that further point.