[Ethereum] Ethereum Merkle Tree Explanation

merkle-patricia-triesstate-trie

Here is my basic understanding about how Ethereum stores transactions

  1. A hash is generated for each transaction
  2. Then pairs are selected and a hash is generated for each pair
  3. This way the last remaining hash becomes the root
  4. Block header contains three Merkle trees
    • To maintain the state
    • To maintain the transactions
    • To maintain the receipts
  5. Each block refers to its previous block's hash
  6. I am attaching the very common diagram showing this structure

enter image description here

Questions:
1. The state root of Block 180994 is pointing to Block 180993's first left child
of the state root. What does it mean and why is it needed?
2. Lets take an example
– First block 180993 is having a transaction where Account 98 is
passing 30 ethers ether to Account 100
– Second block 180994 is
having a transaction where Account 99 is passing 20 ethers to Account
100

How this will be reflected in the tree? Will there be similar kind of cross mapping of Merkle trees like shown in the diagram? Please explain

Added more Detail

enter image description here

Best Answer

The state has the information of all accounts in the blockchain, it is not stored in each block. The state is generated processing each block since the genesis block. Each block will only modify parts of the state.

How to generate the state is defined in the yellow paper (pdf). It is defined in such a way that it can be implemented in any programming language, and all such implementations will generate the same representation.

  1. It means the left side was not modified in block 180994. It is only a representation, remember the whole state is not stored, only the root hash.

  2. There's an article about Merkle Trees in Ethereum, I probably can't do better. The basic idea of merkle trees is that for a single operation it will only modify the minimum amount of nodes to recalculate the root hash.

Related Topic