blockchainmerkle-tree

How is a Merkle tree path generated?


I was trying to understand how Merkle tree works in SPV and many other scenarios in blockchain technologies and couldn't get my head around this one question: how the Merkle path is generated in validating a transaction.

In the graph below, suppose I'd like to validate the transaction 2, I understand the hashes of 3, 01, 4567 and the root are needed, however, I'm wondering how this Merkel path is generated at the first place.

When the transaction 2 is given to the server/node, how does the server/node know which path to return for validating 2? If the server already knew this path, why doesn't the server validate it and why bother to return this path?

Thanks,


(source: codeproject.com)


Solution

  • The confusing part to me was in the graph above, 1,2,...,8 are used to represent transactions, however this over-simplified representation made me think a transaction has just one component, hence ordering and validating can happen in one action, i.e., being sorted is being validated.

    As a matter of fact, the two graphs below show the details of a piece of transaction data where it is the txid that serves as the index like 1, 2,..., 8 above, and there's a lot more in a transaction than a single txid.

    In a Merkle tree, transaction IDs (txid) are checked to place the incoming transaction at the right location at the bottom of the Merkle tree, and the Merkle path is returned to the SPV for checking the content.

    It's easier for the servers to return the Merkle path than to check very transaction to reduce the work-load. Hence, the whole process works out.

    enter image description here enter image description here