Skip to content

calculate new mpt root without loading entire trie

License

Notifications You must be signed in to change notification settings

chainbound/partial-mpt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

partial merkle patricia trie

helps to calculate new root of a huge trie after changing few nodes without loading the entire trie.

usage

use partial_mpt::StateTrie;

// create a new trie
let mut state_trie = StateTrie::from_root(block.state_root);

// load proofs for keys to change
state_trie.load_proof(provider.get_proof(address, vec![slot], block.num))

// set value for the key, would give error if proof is not loaded already
state_trie.set_storage_value(address, slot, new_value)

// new root
state_trie.root()

examples

to run the example, clone this project and cargo run --example eth-burn.

tests

  • to run local tests use cargo test
  • to run specific tests e.g. cargo test trie::tests::test_node_data
  • to run all tests including live mainnet block tests use RPC="https://eth-mainnet.url" cargo test --features test-live

rationale

mainnet fork clients do not calculate state root since it's hardly required in smart contract development. but in a recent hackathon, i had to write a chunk of this code in a hurry. just seperating it out for convenience along with some bug fixes and more tests.

license

MIT

About

calculate new mpt root without loading entire trie

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%