Code Monkey home page Code Monkey logo

partial-mpt's Introduction

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

partial-mpt's People

Contributors

zemse avatar thedevbirb avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.