2

When downloading the Merkle Tree, are all branches from the root downloaded in order?

Are the individual pieces of the tree cataloged in such a way so that the position of each piece is known?

In short, how does one know what piece of the tree goes where?

  • bitcoin wiki has some information on this. i have some notes elsewhere too that i can dig up. en.bitcoin.it/wiki/Protocol_specification#Merkle_Trees – Joe White Jan 5 '14 at 21:39
  • @JoeWhite Thank you for looking Joe White! I must be missing something because I don't understand how having the hashes in the tree allows one to know where they are in the tree unless if the program simply trials and errors until it is reconstructed. Please add your notes in an answer if it can explain how, per your link, d5 is co-branched with d6 and contains d1 concat d2 before trying every possible combination. Thank you very much in advance! – user5107 Jan 5 '14 at 22:41
3

The Merkle tree isn't included in the download data. Just the root hash is included in the block header. The client has to reconstruct the tree in order to verify the root hash. It does this by going through the transaction list as it appears in the block data. Each transaction hash is a node at the top of the tree. So, if you have 6 transactions, you have 6 nodes (the last transaction hash is repeated if you have an odd number of nodes). Then the next level of the tree is computed where each node is formed by hashing the two nodes above it (again, the last node is duplicated if you have an odd number). This process continues until you have just one node - the root node. It is checked against the root in the header to make sure it matches. If it does, you know the transactions have not been modified. Note that the block hash is only over the block header and does not include the transactions themselves.

Here is an example with 6 transactions (Tx1-Tx6)

Tx1    Tx2    Tx3    Tx4    Tx5    Tx6
    \   /        \    /        \   /
     L2A -      -  L2B          L2C -     - L2C (repeated)
          \    /                     \   /
            L3A  ---            ----  L3B
                    \          /
                         Root
  • Thank you ScripterRon! You've helped me so much to understand the intricacies of cryptos! – user5107 Jan 5 '14 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy