Where are Merkle trees used in Bitcoin and why are they important?
I've been trying to understand how Merkle trees are used in bitcoin and why they are important. There's a very nice explanation in the answer provided here: Why is the full Merkle path needed to verify a transaction, but what's missing from that explanation is some context about which entities have which information they can trust.
So I created a scenario to attempt to understand it, provided below. My question is: Do I have this right, and if not, what am I missing?
Scenario:
Let's say Alice wants to hire Bob to murder Chuck. No, just kidding, Alice wants to hire Bob to perform some perfectly legal service, which Bob is willing to do for a certain price, in Bitcoin.
First, Alice tells her wallet to create a transaction in which she gives that amount to Bob, let's call that transaction TxAB, and (skipping a bunch of steps) that transaction eventually gets included in a block on the chain, and then subsequently additional blocks get added, so that TxAB is in a block that is at depth D. So far, no use of Merkle trees. (Is that right?)
Alice sends Bob a copy of the transaction TxAB to Bob, and asks him to go ahead and provide the agreed service or goods. But first, Bob needs to check that Alice is not trying to cheat him by sending a bogus transaction. So Bob needs to check that TxAB has been accepted onto the blockchain. There are a couple of ways that Bob could do this.
One way Bob could check the validity of the transaction would be to run a full Bitcoin node, which would have a copy of the complete blockchain containing ALL transactions. In this case, Bob could just go through all the blocks and find TxAB in there. Again, no Merkle trees used here. (Am I right?)
Another way Bob could check the validity of the transaction would be to run a Simplified Payment Verification (SPV) node, which requires much less resources (processing and storage) than a full node. Bob's SPV node can connect to any randomly selected full node and ask it to verify TxAB. In our scenario, TxAB is valid, and is already in a block buried D deep in the chain, so the full node will confirm that the transaction is valid. If Bob trusted the node, then that would be all that's needed. But, Bob does not need to trust the node, because it can provide PROOF that the transaction is valid. It does this by providing a branch of the Merkle tree that contains the transaction. Bob's SPV software can compute the hash of the transaction, and the hashes of the hash pairs all the way up the branch, until coming up with the root hash. If this computation results in the Merkle tree root hash of the block, Bob's SPV software knows that the transaction is valid. One thing I'm uncertain about here is how Bob's SPV software gets the root hash of the block containing the transaction. Is this something received by listening to the blockchain P2P network? Or can Bob independently determine that it really is a valid root hash?
Do I have it right? Thanks!
https://ift.tt/2PQFsbP
Comments
Post a Comment