https://github.com/blockscout/blockscout-verkle-tree
Module for visualizing Verkle tree proofs
https://github.com/blockscout/blockscout-verkle-tree
Last synced: about 2 months ago
JSON representation
Module for visualizing Verkle tree proofs
- Host: GitHub
- URL: https://github.com/blockscout/blockscout-verkle-tree
- Owner: blockscout
- License: gpl-3.0
- Created: 2022-06-23T18:43:09.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-16T12:40:07.000Z (over 2 years ago)
- Last Synced: 2024-04-14T10:36:30.624Z (about 1 year ago)
- Language: Rust
- Size: 235 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# blockscout-verkle-tree
Module for visualizing Verkle tree proofs## Usage
```
cargo run --release
```
Service contains only one route:
**GET** `/blocks/{block_number}`
- Service send a svg-image of verkle tree by `block_number` in **condriua** test-net
## Theory
Verkle trie is quite similar to **Modified Merkle Patricia Trie**. To understand how this data structure works, let's look at each modification separately.
#### Merkle Tree
The binary tree that is used like **hash function** for any split data.
Recursively taking the hash function and concatenating, we get the Top Hash, which serves as a digital signature of the data.
The *Merkle Proof* requires storing a path for each leaf. This proof is used in Bitcoin blockchain (`merkle_root` in the header).
But there is the main *Merkle tree traversal problem*: it is too expensive to store all the auth-paths in memory.[Wiki_ru](https://ru.wikipedia.org/wiki/Дерево_хешей). Algorithm complexity: *O(ln(N))* (proof).
### Trie
This is k-ary search tree. Also called *prefix-tree* for strings.
*Example for set of words: "A", "to", "tea", "ted", "ten", "i", "in", and "inn".inside *Sample of *Node* struct:
```
template
class className {
Node children[ALPHABET_SIZE];
bool is_terminal;
T value;
};
```
Algorithm complexity: *O(N2)* : create; *O(m)* : find, where m - lenght of word;#### Patricia trie

This is a prefix tree in which prefixes are binary — that is, each key node stores information about one bit. In Ethereum the transition takes place according to the heximal number system (wich called nibble).### Modified Merkle Patricia Trie
Here it is. The main features that distinguish Ethereum from Bitcoin are implemented by realization of ***this data structure***.
Modified Merkle Patricia Trie (MPT) provides opportunities to store account statuses, smart-contracts and almost anything dynamically stored data ***inside the blockchain***.
There are a lot of optimizations which currently Ethereum use, I'll keep it out in context of this README.
You can find Ethereum docs about MPT [here](https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie).

In short, we combine everything that we talked about above.
We dynamically store the key-value, and verify their authenticity with a digital signature at the root (as Merkle Tree).
Asymptotics of methods like in prefix tree. There are a few difficult parts in realization, but not critical ([article with realization](https://habr.com/ru/post/446558/)).### Verkle Tree
I find [Vitalik 's article](https://vitalik.ca/general/2021/06/18/verkle.html) great for beginning.
Verkle Trees are very similar to *Modified Merkle Patricia Trie*. The main difference is complexity of cryptographic part.
There are the same constuction of tree: a leaf nodes with key-value, intermediate nodes with `width` number of children (in MPT is constantly 16). The main idea of creating this data structure is ***reduce the size of all data***. Let's take a look at some pictures:
Nothing new for us yet, but let's see what will *Merkle tree* require for a single proof.

That's a lot of nodes! Meanwhile *Verkle Tree* require only 3 (!) nodes.
That's impressive! So, how it works?*Merkle tree* and *Merkle proof* is algorithm that we can relate to **vector commitment**. And not to go into the depths of group theory, we can assume this is one of the easiest one. In turn, *Verkle Tree* use **polynomial commitment**.
>Polynomial commitments let you hash a polynomial, and make a proof for the evaluation of the hashed polynomial at *any* point.There are two the easiest polynomial commitment schemes: [KZG commitmens](https://dankradfeist.de/ethereum/2020/06/16/kate-polynomial-commitments.html), [ bulletproof-style commitments](https://twitter.com/VitalikButerin/status/1371844878968176647).
Using these schemes already have a big win, but the math we use here provide us opportunity to **merge** different proofs (like on the last picture).
**Time Complexities** (from [this](https://math.mit.edu/research/highschool/primes/materials/2018/Kuszmaul.pdf) paper)

k here - is `width`. Because *Verkle Tree* doesn't have multiplier `width - 1` while proof (we don't have to get sisters), **proof** will be much better.
#### Usefull links
I consider there's no point in implementation of *verkle tree* (i found it).
So, if someone comes back here in the future, I'll leave **a bunch** of links here, which helped me a lot.| links | description |
| --- | --- |
| [crate-crypto/rust-verkle](https://github.com/crate-crypto/rust-verkle) | **Implementation** of verkle tree in *rust* (special crate) |
| [gballet/verkle-block-sample](https://github.com/gballet/verkle-block-sample) | **Example** of verklee proof in rust |
| [condrieu](https://condrieu.ethdevops.io/) | **Testnet** with usage of verkle tree |
| [gballet/go-verkle](https://github.com/gballet/go-verkle) | **Test client** of verkle tree in go |
| [Ethereum Meeting](https://www.youtube.com/watch?v=1hTscLYsaIg&t=1167s&ab_channel=EthereumCatHerders) | recording a meeting, where Vitalik talks about verkle tree (beginning) |
| [Guillaume Ballet on *ETH PRAGUE 2020*](https://www.youtube.com/watch?v=4fL7hi8SZMs&ab_channel=ParallelPolis) | Speech by Guillaume Ballet about transition to verkle-networks |
| [eth research](https://ethresear.ch/t/a-minimum-viable-kzg-polynomial-commitment-scheme-implementation/7675) | **KZG commitments** research |
| [MIT paper](https://math.mit.edu/research/highschool/primes/materials/2018/Kuszmaul.pdf) | **Intro-paper** to verkle trees (beginning) |
| [Vitalik's paper](https://vitalik.ca/general/2021/06/18/verkle.html) | **Post** a bit harder than previous (beginning) |
| [verkle-trie-for-eth1](https://dankradfeist.de/ethereum/2021/06/18/verkle-trie-for-eth1.html) | **Post** to read (beginning) |
| [KZG commitments](https://dankradfeist.de/ethereum/2020/06/16/kate-polynomial-commitments.html) | **Post** about Kate commitments (some math) |
| [Math](https://vitalik.ca/general/2017/01/14/exploring_ecp.html) | Elliptic Curve usage |
| [@vbuterin/verkle_tree_eip](https://notes.ethereum.org/@vbuterin/verkle_tree_eip) | **Post** about work and influence of verkle tree |