Coder Social home page Coder Social logo

aiken-lang / merkle-patricia-forestry Goto Github PK

View Code? Open in Web Editor NEW
24.0 1.0 1.0 1.16 MB

🌳 Libraries (Aiken & Node.js) for working with Merkle Patricia Tries on Cardano.

Home Page: https://aiken-lang.github.io/merkle-patricia-forestry/aiken/merkle_patricia_forestry.html

License: Mozilla Public License 2.0

JavaScript 100.00%
aiken cardano merkle-patricia-trie merkle-tree sparse-merkle-tree

merkle-patricia-forestry's Introduction

Merkle Patricia Forestry

Merkle Patricia Forestry

A set of (on-chain & off-chain) libraries for working with Merkle Patricia Tries on Cardano.


Licence Continuous Integration NPM


Overview

A Merkle Patricia Trie is a persistent & authenticated data structure to map between arbitrary keys and values. It's like a hashmap on steroids, which isn't tamperable. The items are represented in a space-optimized trie (a.k.a prefix tree) of radix 16. The hash digest of their keys gives the path to values in the trie. For more details, read the wiki.

The use cases are numerous, such as maintaining large on-chain registries (e.g. domains) or providing unreasonably large oracled datasets of intrinsic data (e.g. a map of delegators/delegatees) or extrinsic data (e.g. GitHub data pertaining to an ecosystem of projects). It's also perfectly suited for long-running datasets that grow at a slow rate (e.g. a PoW blockchain).

Features

Using only a root hash digest (32 bytes) and a succinct proof (<1KB), Merkle Patricia Tries provides rapid:

  • membership
  • insertion
  • deletion

...of any key/value item in a large (billions) store.

Getting Started

Off-chain (JavaScript / Node.js)

yarn add @aiken-lang/merkle-patricia-forestry

See off-chain for usage.

On-chain (Aiken)

aiken use aiken-lang/merkle-patricia-forestry --version 1.0.0

See on-chain for usage.

Performances

This library implements a few optimizations. We borrow ideas from the Ethereum's Modified Merkle Patricia Trie (MPT) and also introduce a novel approach for organizing nodes as tiny Sparse Merkle Trees that result in much smaller proof sizes, and gives the name to the structure: Merkle Patricia Forestry. This optimization and overall approach are covered in more detail in the wiki.

While this optimization sacrifices some memory and CPU execution units for smaller proof sizes, the library ultimately achieves a good trade-off. The table below summarizes the proof size, memory units, and CPU units for various sizes of tries. Note that the numbers in the table correspond to one proof verification (e.g., membership). Insertion and deletion in the trie both require two proof verifications, so double the numbers!

trie size avg proof size (bytes) avg proof mem units avg proof cpu units
10² 250 70K 28M
10³ 350 100K 42M
10⁴ 460 130K 56M
10⁵ 560 160K 70M
10⁶ 670 190K 84M
10⁷ 780 220K 98M
10⁸ 880 250K 112M
10⁹ 990 280K 126M

Note

On current mainnet, 140K mem units and 100M cpu units corresponds respectively to 1% of the maximum transaction mem and cpu budgets.

merkle-patricia-forestry's People

Contributors

ktorz avatar quantumplation avatar

Stargazers

ash avatar keyanm avatar Sean Sherman avatar Lorenzo Giovenali avatar Mad Orkestra avatar Robertino avatar  avatar paluh avatar Miklos Suveges avatar TKnott avatar Ross Spencer avatar Shaquille Powiesnik avatar Samuel Slinger avatar  avatar KlarkC avatar luna avatar Rodrigo Molina avatar Matthieu Pizenberg avatar Carlos Souza avatar  avatar Angel Castillo avatar Thomas Vellekoop avatar Lucas avatar Juan Salvador Magán Valero avatar

Watchers

Lucas 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.