Author

Topic: Additional details and explanations regarding merkle trees (Read 345 times)

legendary
Activity: 3584
Merit: 5243
https://merel.mobi => buy facemasks with BTC/LTC
--snip--
one of the application of a merkle tree is the block header: you need to able to prove the transaction data inside a block didn't change just by looking at the block header... It's impossible to add all transaction hashes to the header, so we use a merkle tree.

This way, when a miner finds a block header whose sha256d hash is under the current target, the block can no longer be changed, since changing any transaction in the block will change the merkle tree and invalidate the block

After reading this, I wanted to understand how a block can be changed or edited if this process is entirely irreversible. Merkle tree as I am guessing is also a chain of blocks containing the info and it keeps growing as the new data is received. What makes it different from the block and its header?  So those are different components on the chain.

I'll try to simplify things a bit, but the nature of these things is rather complex, so it'll still require some effort to grasp the simplified explanation.

Let's assume the current blockchain height is 812460. This means, 812459 blocks have been found on top of the first block.
Block 812460 has a block header.

When i'm a miner trying add a block to the blockchain, i'm trying to find the block with height 812461.
In order to do so, i have to find a block header that, when hashed using the sha256 hash function twice, results in a hash that's under the current target.

I create a block header by taking the hash of the previous block's header (812460), the merkle root of 1 Mb of transactions from my mempool (excluding the witness data) and a nonce (next to some other data like the Version, Bits and Time, which i'm going to discard to simplify things a bit). I do a sha256d of this block header, and if my result is OVER the current target, i iterate the nonce and retry (untill i find a nonce for which my current hash is under the target... Offcourse the odds of finding such a header by myself is really small).

The merkle root in the block header i'm creating is built by building a merkle tree out of each of the transactions in the block. If i change anything about one of these transactions (even their order) the merkle root changes. This means that once i find a valid block header, both the previous block and all of the transactions in my current block become immutable. If i would change a transaction in a previous block, the merkle tree of the previous block would change, the block header would change and the odds of the new block header's sha256d still being under the target is really, really, really small... It also means my current block can no longer change (same logic about the merkle tree + the hash of the previous block header is also a part of the current block header).
The end result is an immutable blockchain..

If i ever wanted to change the history by removing a transaction from (for example) block 812360, it's merkle tree would change and i would need to find a completely new nonce that would make the sha256d hash of this header under the current target, and then i would need to re-mine block 812361, 812362,... And i would need to catch up (and exceed) the current tip because otherwise the rest of the network would just reject my alternative chain... In reality, this would cost billions in hardware and power, and it's just not possible economically... That's what makes our blockchain secure Smiley.
The network is programmed to, when faced with 2 alternative chains, pick the one with the most cumulative work... So if i wanted to change history, i'd have to exceed all the work in the current main chain.
hero member
Activity: 2114
Merit: 603
Sincerely it is deeper when you keep reading about the tech behind blockchain and how it works. I have tried to create a topic regarding blockchain and how it works in the beginner's section when I realized I needed more and more learning each time I created a new topic. It's still pending work right now but such discussion is always encouraging to me and definitely to those who need such info.

The way everyone is explaining it here is like legend-level. I got more hundred questions after reading all of them. Lolz.

one of the application of a merkle tree is the block header: you need to able to prove the transaction data inside a block didn't change just by looking at the block header... It's impossible to add all transaction hashes to the header, so we use a merkle tree.

This way, when a miner finds a block header whose sha256d hash is under the current target, the block can no longer be changed, since changing any transaction in the block will change the merkle tree and invalidate the block

After reading this, I wanted to understand how a block can be changed or edited if this process is entirely irreversible. Merkle tree as I am guessing is also a chain of blocks containing the info and it keeps growing as the new data is received. What makes it different from the block and its header?  So those are different components on the chain.
full member
Activity: 448
Merit: 163
But if I may ask why is Merkel trees essential to the block?
In a decentralized, trustless network like Bitcoin, participants need to be able to quickly check the authenticity of the data they receive, and one of the best ways to ensure data has not been altered is to use different cryptographic proofs. In the case of a Bitcoin block, for example, we need to verify the integrity and presence of particular transactions because this information takes up most of Bitcoin's block space and, most importantly, it carries financial significance. We could use other data structures like hash chains to verify the said integrity and authenticity, but Merkle Tree happens to be one of the most efficient for this purpose.

Thank you very much I sincerely appreciated. Before I was completely perplexed, but with your explanation, I have learned a lot from you. it's good for someone to bring out what they don't understand so that others can offer assistance.
full member
Activity: 161
Merit: 230
Note that Merkle trees are not actually strictly required for a Bitcoin like coin to function - you can just as well do a full single hash of all the concatenated transactions in a block and place that in the header. The disadvantage is that the proof required to prove if a transaction got included is the full block itself.
legendary
Activity: 2450
Merit: 4415
🔐BitcoinMessage.Tools🔑
But if I may ask why is Merkel trees essential to the block?
In a decentralized, trustless network like Bitcoin, participants need to be able to quickly check the authenticity of the data they receive, and one of the best ways to ensure data has not been altered is to use different cryptographic proofs. In the case of a Bitcoin block, for example, we need to verify the integrity and presence of particular transactions because this information takes up most of Bitcoin's block space and, most importantly, it carries financial significance. We could use other data structures like hash chains to verify the said integrity and authenticity, but Merkle Tree happens to be one of the most efficient for this purpose.
full member
Activity: 448
Merit: 163
For my research, I was looking into merkle trees today. This research taught me many things, but I also learned about merkle trees and how they relate to bitcoin. Since we have direct access to the database, I'm not sure why Merkle trees which are used to verify the data's integrity are necessary. Could someone please explain the real implementation of Merkle trees on the Bitcoin blockchain? Why are we unable to simply perform a database query to obtain the transaction data?
I need assistance with it in order to learn a lot and comprehend more clearly.

In my understanding Merkel tree is know as data structure which is commonly used in computer science, which is also associates with Blockchain technology data, and is more exclusive and securely in Bitcoin and others cryptocurrencies, and it's also be best in terms of represent  and distribute the list of transaction because it perform data verification fastly with out any issues.

But if I may ask why is Merkel trees essential to the block?
sr. member
Activity: 450
Merit: 220
In addition to the resources already supplied, I came across an MIT course titled "Blockchain Basics & Cryptography" that delves into the fundamentals of block headers and Merkle trees. I've included them in two different formats below:

Video format of lecture - Blockchain Basics & Cryptography
Text format of the lecture - Blockchain Basics & Cryptography



full member
Activity: 448
Merit: 202
Thank you so much, bosses. I appreciate what everyone has contributed, and I also want to take this opportunity to thank everyone for the time they took and the resources they shared with me to help me learn more about the Merkle Tree. I'm thrilled that you people gave me this information.
legendary
Activity: 2450
Merit: 4415
🔐BitcoinMessage.Tools🔑
For my research, I was looking into merkle trees today. This research taught me many things, but I also learned about merkle trees and how they relate to bitcoin. Since we have direct access to the database, I'm not sure why Merkle trees which are used to verify the data's integrity are necessary. Could someone please explain the real implementation of Merkle trees on the Bitcoin blockchain? Why are we unable to simply perform a database query to obtain the transaction data?
I need assistance with it in order to learn a lot and comprehend more clearly.
https://learnmeabitcoin.com/technical/merkle-root is one of the most valuable resources you should consult each time you struggle to understand something regarding Bitcoin's inner processes. Also, a Merkle tree is not an alternative to relational and No-SQL databases, it is just a very efficient data structure that makes it very easy to search for information and verify its integrity, it can be used by databases themselves to optimize different queries like insertions, searches, updates, etc.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Related with block header, it's also used by SPV wallet to verify whether a transaction iis in a block. Here's an illustration


Source: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch09.asciidoc

That way, SPV wallet doesn't have to download whole block to perform verification which improve time to sync the wallet.
sr. member
Activity: 700
Merit: 470
Hope Jeremiah 17vs7
In addition to what @mocacinno has stated, here is a post about this : Merkle Trees and Merkle Roots for dummies
legendary
Activity: 3584
Merit: 5243
https://merel.mobi => buy facemasks with BTC/LTC
one of the application of a merkle tree is the block header: you need to able to prove the transaction data inside a block didn't change just by looking at the block header... It's impossible to add all transaction hashes to the header, so we use a merkle tree.

This way, when a miner finds a block header whose sha256d hash is under the current target, the block can no longer be changed, since changing any transaction in the block will change the merkle tree and invalidate the block
full member
Activity: 448
Merit: 202
For my research, I was looking into merkle trees today. This research taught me many things, but I also learned about merkle trees and how they relate to bitcoin. Since we have direct access to the database, I'm not sure why Merkle trees which are used to verify the data's integrity are necessary. Could someone please explain the real implementation of Merkle trees on the Bitcoin blockchain? Why are we unable to simply perform a database query to obtain the transaction data?
I need assistance with it in order to learn a lot and comprehend more clearly.
Jump to: