Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gregors/merkle_fun
Merkle Trees in Elixir
https://github.com/gregors/merkle_fun
merkle-proof merkle-root merkle-tree merkletree
Last synced: about 2 months ago
JSON representation
Merkle Trees in Elixir
- Host: GitHub
- URL: https://github.com/gregors/merkle_fun
- Owner: gregors
- License: mit
- Created: 2022-04-08T20:27:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-24T18:50:18.000Z (about 2 years ago)
- Last Synced: 2024-05-29T22:31:22.270Z (7 months ago)
- Topics: merkle-proof, merkle-root, merkle-tree, merkletree
- Language: Elixir
- Homepage:
- Size: 92.8 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MerkleFun
[Merkle tree](https://en.wikipedia.org/wiki/Merkle_tree) implementation using the excellent and fast rust-powered ex_keccak library under the hood.
If you'd like to know more about the basic algorithm, check out this great [introductory talk](https://youtu.be/HdGpG0kcEGU?t=132).[![CircleCI](https://circleci.com/gh/gregors/merkle_fun/tree/main.svg?style=svg)](https://circleci.com/gh/gregors/merkle_fun/tree/main)
## Installation
The package can be installed
by adding `merkle_fun` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:merkle_fun, "~> 0.6.0"}
]
end
```## Design
### binary tree
There are multiple ways to implement a binary tree. We decided to use an [array format](https://opendsa-server.cs.vt.edu/ODSA/Books/Everything/html/CompleteTree.html) approach to minimize storage requirements and make the sibling lookup easy. If it's been a while since you've done a basic data structures course, check out this [refresher](https://www.youtube.com/watch?v=zDlTxrEwxvg).
Wait a minute you say! Elixir doesn't have arrays? Well there is an [Erlang implementation](https://www.erlang.org/doc/man/array.html) as well as a nice [Elixir library](https://github.com/Qqwy/elixir-arrays). However, after thinking about the problem our use case didn't need updates. We build the tree and don't need to append further nodes. In such a case a tuple suits our [read only needs](https://stackoverflow.com/questions/16447921/arrays-implementation-in-erlang/16464349#16464349) perfectly. If we decide to add Merkle Mountain Ranges (in the future) we will need something with better append performance.
### leaf lookup
Initial leaf lookup is currently looking through the entire tree. Yeah I need to fix that.
## Warning
* second pre-image attack
* unbalanced trees attack## Todo's
* [x] Make tree
* [x] Make proof
* [x] Validate proof
* [ ] Pretty Print tree
* [ ] Fast leaf look up## Thanks
Thanks goes out to Rodger Maarfi (@acrite22) for pairing with me on this.
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at .