https://github.com/commitground/solidity-patricia-tree
Wrap patricia-trie implementation as a solidity library
https://github.com/commitground/solidity-patricia-tree
merkle patricia proof solidity tree
Last synced: 10 months ago
JSON representation
Wrap patricia-trie implementation as a solidity library
- Host: GitHub
- URL: https://github.com/commitground/solidity-patricia-tree
- Owner: commitground
- License: mit
- Created: 2018-10-25T12:21:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-09T06:15:52.000Z (almost 7 years ago)
- Last Synced: 2025-04-08T20:07:55.370Z (10 months ago)
- Topics: merkle, patricia, proof, solidity, tree
- Language: JavaScript
- Homepage: https://commitground.github.io/patricia-tree-demo
- Size: 264 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Solidity Patricia Tree
## Credits
This is a rewritten version of [Christian Reitwießner](https://github.com/chriseth)'s [patricia-trie](https://github.com/chriseth/patricia-trie) to use his patricia tree implementation as a solidity library through npm.
##### latest released version
[](https://www.npmjs.com/package/solidity-patricia-tree)
[](https://travis-ci.org/commitground/solidity-patricia-tree)
[](https://coveralls.io/github/commitground/solidity-patricia-tree?branch=develop)
##### in progress
[](https://www.npmjs.com/package/solidity-patricia-tree)
[](https://travis-ci.org/commitground/solidity-patricia-tree)
[](https://coveralls.io/github/commitground/solidity-patricia-tree?branch=develop)
[](https://github.com/standard/standard)
## Usage
```bash
npm i solidity-patricia-tree
```
```solidity
pragma solidity ^0.4.25;
import {PatriciaTree} from "solidity-patricia-tree/contracts/tree.sol";
contract TestPatriciaTree {
using PatriciaTree for PatriciaTree.Tree;
PatriciaTree.Tree tree;
function test() public {
// testInsert();
testProofs();
}
function testInsert() internal {
tree.insert("one", "ONE");
tree.insert("two", "ONE");
tree.insert("three", "ONE");
tree.insert("four", "ONE");
tree.insert("five", "ONE");
tree.insert("six", "ONE");
tree.insert("seven", "ONE");
// update
tree.insert("one", "TWO");
}
function testProofs() internal {
tree.insert("one", "ONE");
uint branchMask;
bytes32[] memory siblings;
(branchMask, siblings) = tree.getProof("one");
PatriciaTree.verifyProof(tree.root, "one", "ONE", branchMask, siblings);
tree.insert("two", "TWO");
(branchMask, siblings) = tree.getProof("one");
PatriciaTree.verifyProof(tree.root, "one", "ONE", branchMask, siblings);
(branchMask, siblings) = tree.getProof("two");
PatriciaTree.verifyProof(tree.root, "two", "TWO", branchMask, siblings);
}
}
```
## Development
### Pre-requisites
```bash
npm install -g truffle
npm install -g ganache
npm install
```
### Tests
Test cases include the information about how the functions work, but also includes a demo scenario.
Running and reading the test cases will help you understand how it works.
```bash
npm run test
```
## Contributors
- Original author: [Christian Reitwießner](https://github.com/chriseth)
- [Wanseob Lim](https://github.com/james-lim)<[email@wanseob.com](mailto:email@wanseob.com)>
## License
[MIT LICENSE](./LICENSE)