Crates.io | polkadot-ckb-merkle-mountain-range |
lib.rs | polkadot-ckb-merkle-mountain-range |
version | |
source | src |
created_at | 2024-05-23 16:21:38.664451 |
updated_at | 2024-11-04 14:21:23.400239 |
description | A generalized merkle mountain range implementation (polkadot fork) |
homepage | |
repository | https://github.com/paritytech/merkle-mountain-range |
max_upload_size | |
id | 1249734 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A generalized merkle mountain range implementation.
# An 11 leaves MMR
14
/ \
6 13
/ \ / \
2 5 9 12 17
/ \ / \ / \ / \ / \
0 1 3 4 7 8 10 11 15 16 18
In MMR, we use the insertion order to reference leaves and nodes.
We insert a new leaf to MMR by the following:
For example, we insert a leaf to the example MMR:
19
.18
and calculate parent node: merge(mmr[18], mmr[19])
.20
.20
also has a left sibling 17
, calculate parent node: merge(mmr[17], mmr[20])
.21
.21
have no left sibling, complete the insertion.Example MMR after insertion of a new leaf:
14
/ \
6 13 21
/ \ / \ / \
2 5 9 12 17 20
/ \ / \ / \ / \ / \ / \
0 1 3 4 7 8 10 11 15 16 18 19
An MMR is constructed by one or more sub merkle trees (or mountains). Each sub merkle tree's root is a peak in MMR, we calculate the MMR root by bagging these peaks from right to left.
For example, in the 11 leaf MMR we have 3 peaks: 14, 17, 18
, we bag these peaks from right to left to get the root: merge(mmr[14], merge(mmr[17], mmr[18]))
.
The merkle proof is an array of hashes constructed with the following parts:
We can reconstruct the merkle root from the proofs. Pre-calculating the peak positions from the size of MMR may help us do the bagging.