GithubHelp home page GithubHelp logo

mrkl's Introduction

Generic Merkle Tree

This crate provides a generic, composable, and parallelizable way to construct Merkle trees, also known as hash trees, from input data. The basic design is agnostic to the choice of the hashing algorithm, the type of input data, and what information derived from the input gets stored inside leaf nodes.

Design assumptions

  • Merkle trees are normally built once when the hashed content is "sealed". Appending to a previously calculated tree is only done by adding new levels on top of the sealed tree root. An application design that needs to repeatedly recalculate a Merkle tree over variable content has questionable usefulness and efficiency. Therefore, the data structures representing fully constructed trees can be made immutable.

  • Merkle trees are not generally used to contain the hashed input data. However, some information about the input may need to be stored in the leaf nodes. Therefore, the design should provide flexible choices for leaf data extraction, including trees without leaf data and trees taking ownership of the input as leaf data.

  • The application should have a choice in the hashing algorithm that is not restricted to a particular digest API. The Rust Crypto project's API, however, should be supported out of the box.

  • The application should have flexibility in how the hash over child nodes is calculated for their parent node. The popular way of prepending a byte value distinguishing a leaf node from a non-leaf node, to protect against second-preimage attacks, can be provided by default.

  • Building both left-filled, uniform-leaf-depth binary trees permitting rightmost "angle" internal nodes (as in Bitcoin), and full, but not necessarily balanced binary trees (as in Certificate Transparency), should be supported as primary use cases.

  • Calculation of Merkle trees is eminently parallelizable, so an implementation using a work-stealing thread pool should be provided as an optional feature.

Design notes

The design uses the builder pattern to separate the Merkle tree data model, which is immutable, from various construction facilities that are represented by tree::Builder, tree::parallel::Builder, and related types.

Future additions

Audit paths, consisting of the root hash and a chain of side node hashes needed to verify integrity of a leaf's data, need to be supported.

The input to make a leaf node cannot yet be provided incrementally. There is an idea how to implement this in an elegant way.

An extension can be provided to build trees from iterated input where data to hash is delivered multiplexed alongside the values to store as leaf data (like in the item values of std::iter::Enumerate).

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

mrkl's People

Contributors

mzabaluev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

suhasagg

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.