All Projects → ameensol → Merkle Tree Solidity

ameensol / Merkle Tree Solidity

JS - Solidity sha3 merkle tree bridge. Generate proofs in JS; verify in Solidity.

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Projects that are alternatives of or similar to Merkle Tree Solidity

Merkle Patricia Tree
Project is in active development and has been moved to the EthereumJS VM monorepo.
Stars: ✭ 277 (+194.68%)
Mutual labels:  ethereum, merkle-tree
Merkletreejs
🌱 Construct Merkle Trees and verify proofs in JavaScript.
Stars: ✭ 238 (+153.19%)
Mutual labels:  ethereum, merkle-tree
Cated
CATEd - Cryptocurrency Analytics and Trading Engine for Django
Stars: ✭ 84 (-10.64%)
Mutual labels:  ethereum
Securify2
Securify v2.0
Stars: ✭ 92 (-2.13%)
Mutual labels:  ethereum
Eltwallet
Non-custodial decentralized mobile wallet
Stars: ✭ 88 (-6.38%)
Mutual labels:  ethereum
Kuberneteth
[ Ethereum + Kubernetes ] deploy a private ethereum blockchain network with kubernetes
Stars: ✭ 84 (-10.64%)
Mutual labels:  ethereum
Plasma Chamber
Plasma Chamber is a DApps development framework that guarantees security, scalability, and usability utilizing Plasma technology.
Stars: ✭ 91 (-3.19%)
Mutual labels:  ethereum
Chaingear
The consensus computer driven database framework
Stars: ✭ 83 (-11.7%)
Mutual labels:  ethereum
Abyss Daico
DAICO is an innovative fundraising model that merges some of the benefits of Decentralized Autonomous Organizations (DAOs), aimed at upgrading and making the initial ICO concept more transparent.
Stars: ✭ 94 (+0%)
Mutual labels:  ethereum
Awesome Ethereum
A Curated List of Awesome Ethereum Resources
Stars: ✭ 85 (-9.57%)
Mutual labels:  ethereum
Vue Ethereum Ipfs
Distributed Application Starter: Vue front-end, Ethereum / IPFS Backend
Stars: ✭ 1,312 (+1295.74%)
Mutual labels:  ethereum
Awesome Privacy On Blockchains
A curated list of privacy on blockchains resources
Stars: ✭ 86 (-8.51%)
Mutual labels:  ethereum
Cljs Web3
Clojurescript API for Ethereum Web3 API
Stars: ✭ 84 (-10.64%)
Mutual labels:  ethereum
Coincurve
Cross-platform Python bindings for libsecp256k1
Stars: ✭ 89 (-5.32%)
Mutual labels:  ethereum
Ethaddrgen
Custom Ethereum vanity address generator made in Rust
Stars: ✭ 84 (-10.64%)
Mutual labels:  ethereum
Deepblockchains
Deep Blockchains - reference implementation of Plasma, Stark, SMT and more
Stars: ✭ 93 (-1.06%)
Mutual labels:  ethereum
Abdk Libraries Solidity
Open-Source Libraries for Solidity by ABDK Consulting
Stars: ✭ 84 (-10.64%)
Mutual labels:  ethereum
Coin registry
A global registry of JSON formatted files on 1500+ cryptocurrency tokens. Provides information like chat rooms, communities, explorers, and contact information on each coin. Used by https://blockmodo.com, DEXs, developers, and exchanges.
Stars: ✭ 85 (-9.57%)
Mutual labels:  ethereum
Ethereum Etl Airflow
Airflow DAGs for exporting, loading, and parsing the Ethereum blockchain data. What datasets do you want to be added to Ethereum ETL? Vote here: https://blockchain-etl.convas.io.
Stars: ✭ 89 (-5.32%)
Mutual labels:  ethereum
Soltsice
Solidity & TypeScript Integration, Configuration and Examples
Stars: ✭ 94 (+0%)
Mutual labels:  ethereum

merkle-tree-solidity

JS - Solidity sha3 merkle tree bridge. Generate proofs in JS; verify in Solidity.

Install

npm install --save merkle-tree-solidity

Credit

This is partly a port of Raiden's merkle tree python module and the solidity code is a close copy.

Merkle Tree https://github.com/raiden-network/raiden/blob/master/raiden/mtree.py

Solidity https://github.com/raiden-network/raiden/blob/master/raiden/smart_contracts/NettingChannelLibrary.sol

Usage

import MerkleTree, { checkProof, merkleRoot, checkProofSolidityFactory } from 'merkle-tree-solidity'
import { sha3 } from 'ethereumjs-util'

// create merkle tree
// expects unique 32 byte buffers as inputs (no hex strings)
// if using web3.sha3, convert first -> Buffer(web3.sha3('a'), 'hex')
const elements = [1, 2, 3].map(e => sha3(e))
const merkleTree = new MerkleTree(elements)

// get the merkle root
// returns 32 byte buffer
const root = merkleTree.getRoot()

// for convenience if only the root is desired
// this creates a new MerkleTree under the hood
const easyRoot = merkleRoot(elements)

// generate merkle proof
// returns array of 32 byte buffers
const proof = merkleTree.getProof(elements[0])

// check merkle proof in JS
// returns bool
checkProof(proof, root, elements[0])

// create the contract abstraction
const merkleProof = await deployMerkleProofContract()

// then use the contract directly
// but the contract requires hex prefixed strings, not buffers
merkleProof.checkProof(proof, root, hash) // -> throws

// or create a helper function from the abstraction
// this function converts the buffers to hex prefixed strings
const checkProofSolidity = checkProofSolidityFactory(merkleProof.checkProof)

// check merkle proof in Solidity
// we can now safely pass in the buffers returned by previous methods
await checkProofSolidity(proof, root, elements[0]) // -> true

Ordered Merkle Trees

By default, generating the tree doesn't preserve leaf order, but we can optionally do so.

import MerkleTree, { checkProofOrdered, merkleRoot, checkProofOrderedSolidityFactory } from 'merkle-tree-solidity'
import { sha3 } from 'ethereumjs-util'

// create merkle tree
// expects 32 byte buffers as inputs (no hex strings)
// if using web3.sha3, convert first -> Buffer(web3.sha3('a'), 'hex')
const elements = [1, 2, 3].map(e => sha3(e))

// include the 'true' flag when generating the merkle tree
const merkleTree = new MerkleTree(elements, true)

// [same as above]
// get the merkle root
// returns 32 byte buffer
const root = merkleTree.getRoot()

// for convenience if only the root is desired
// this creates a new MerkleTree under the hood
// 2nd arg is "preserveOrder" flag
const easyRoot = merkleRoot(elements, true)

// generate merkle proof
// 2nd argugment is the 1-n index of the element
// returns array of 32 byte buffers
const index = 1
const proof = merkleTree.getProofOrdered(elements[0], index)

// this is useful if you have duplicates in your tree
const elements2 = [3, 2, 3].map(e => sha3(e))
const index2 = 3
const proof2 = merkleTree.getProof(sha3(3), 3)

// check merkle proof of ordered tree in JS
// expects 1-n indexed element position as last param
// returns bool
const index = 1
checkProofOrdered(proof, root, elements[0], index)

// create the contract abstraction
const merkleProof = await deployMerkleProofContract()

// then use the contract directly
// but the contract requires hex prefixed strings, not buffers
merkleProof.checkProofOrdered(proof, root, hash, index) // -> throws

// or create a helper function from the abstraction
// this function converts the buffers to hex prefixed strings
const checkProofOrderedSolidity = checkProofSolidityOrderedFactory(merkleProof.checkProofOrdered)

// check merkle proof in Solidity
// we can now safely pass in the buffers returned by previous methods
await checkProofOrderedSolidity(proof, root, elements[0], index) // -> true

Licence

This project is licensed under the MIT license, Copyright (c) 2016 Ameen Soleimani

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].