coperlm

coperlm

github

Tree in Blockchain

Merkle Tree#

Problem: Hashing an array (n elements)

Traditional solution: Concatenate each data and then hash, with both time and space complexity being $O(n)$.

Using Merkle tree: Only need to compute the hashes along the path, with both time and space complexity being $O(logn)$; the cost is that the total storage space increases (needs to store the hash tree), but it is still $O(n)$.

![](Trees in Blockchain\image-20251005203401710.png)

Trie Tree#

Indexing based on prefixes, suitable for storing data with similar prefixes.

The worst depth is the length of the longest string (which is the time complexity), but it is not necessarily a binary tree.

Suitable for prefix dictionary lookups.

![](Trees in Blockchain\image-20251005203731340.png)

Merkle Patricia Tree#

Transforms the binary Merkle tree into a 16-way tree.

The parent node records pointers to 16 branches, plus a value field representing its own value.

Here, the pointers are the hash values of the child nodes, stored in a key-value DB to assist with reverse lookups.

![](Trees in Blockchain\image-20251005204621556.png)

Simultaneously responsible for both hashing and indexing functions.

16-way reduces depth -> reduces the number of database requests.

Rollup's State Tree#

Separates map and value.

![](Trees in Blockchain\image-20251006195437245.png)

Verkle Tree#

Based on KZG.

![](Trees in Blockchain\image-20251006200043767.png)

Constructs a 16-way tree accordingly.

![](Trees in Blockchain\image-20251006200227515.png)

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.