1
- # Solidity Sparse Tree
1
+ # Solidity Partial Merkle Tree
2
2
3
3
## Credits
4
4
5
5
This implementation is based on [ Christian Reitwießner] ( https://github.com/chriseth ) 's [ patricia-tree] ( https://github.com/chriseth/patricia-tree )
6
6
7
7
8
8
##### latest released version
9
- [ ![ npm] ( https://img.shields.io/npm/v/solidity-sparse -tree/latest.svg )] ( https://www.npmjs.com/package/solidity-sparse -tree )
10
- [ ![ Build Status] ( https://travis-ci.org/commitground/solidity-sparse -tree.svg?branch=master )] ( https://travis-ci.org/commitground/solidity-sparse -tree )
11
- [ ![ Coverage Status] ( https://coveralls.io/repos/github/commitground/solidity-sparse -tree/badge.svg?branch=master )] ( https://coveralls.io/github/commitground/solidity-sparse -tree?branch=develop )
9
+ [ ![ npm] ( https://img.shields.io/npm/v/solidity-partial -tree/latest.svg )] ( https://www.npmjs.com/package/solidity-partial -tree )
10
+ [ ![ Build Status] ( https://travis-ci.org/commitground/solidity-partial -tree.svg?branch=master )] ( https://travis-ci.org/commitground/solidity-partial -tree )
11
+ [ ![ Coverage Status] ( https://coveralls.io/repos/github/commitground/solidity-partial -tree/badge.svg?branch=master )] ( https://coveralls.io/github/commitground/solidity-partial -tree?branch=develop )
12
12
13
13
##### in progress
14
- [ ![ npm] ( https://img.shields.io/npm/v/solidity-sparse -tree/next.svg )] ( https://www.npmjs.com/package/solidity-sparse -tree )
15
- [ ![ Build Status] ( https://travis-ci.org/commitground/solidity-sparse -tree.svg?branch=develop )] ( https://travis-ci.org/commitground/solidity-sparse -tree )
16
- [ ![ Coverage Status] ( https://coveralls.io/repos/github/commitground/solidity-sparse -tree/badge.svg?branch=develop )] ( https://coveralls.io/github/commitground/solidity-sparse -tree?branch=develop )
14
+ [ ![ npm] ( https://img.shields.io/npm/v/solidity-partial -tree/next.svg )] ( https://www.npmjs.com/package/solidity-partial -tree )
15
+ [ ![ Build Status] ( https://travis-ci.org/commitground/solidity-partial -tree.svg?branch=develop )] ( https://travis-ci.org/commitground/solidity-partial -tree )
16
+ [ ![ Coverage Status] ( https://coveralls.io/repos/github/commitground/solidity-partial -tree/badge.svg?branch=develop )] ( https://coveralls.io/github/commitground/solidity-partial -tree?branch=develop )
17
17
18
18
[ ![ JavaScript Style Guide] ( https://cdn.rawgit.com/standard/standard/master/badge.svg )] ( https://github.com/standard/standard )
19
19
@@ -22,27 +22,27 @@ This implementation is based on [Christian Reitwießner](https://github.com/chri
22
22
## Usage
23
23
24
24
``` bash
25
- npm i solidity-sparse -tree
25
+ npm i solidity-partial -tree
26
26
npm i solidity-patricia-tree
27
27
```
28
28
29
29
``` solidity
30
30
pragma solidity ^0.4.24;
31
31
32
- import {SparseTree} from "solidity-sparse-tree/contracts/tree.sol";
33
32
import {PatriciaTree} from "solidity-patricia-tree/contracts/tree.sol";
33
+ import {PartialMerkleTree} from "solidity-partial-tree/contracts/tree.sol";
34
34
35
- contract TestSparseTree {
36
- using SparseTree for SparseTree .Tree;
35
+ contract TestPartialMerkleTree {
36
+ using PartialMerkleTree for PartialMerkleTree .Tree;
37
37
using PatriciaTree for PatriciaTree.Tree;
38
38
39
39
PatriciaTree.Tree patriciaTree;
40
- SparseTree .Tree sparseTree ;
40
+ PartialMerkleTree .Tree partialTree ;
41
41
42
42
/**
43
43
* @dev we can reenact merkle tree transformation by submitting only referred siblings instead of submitting all nodes
44
44
*/
45
- function testSparseTree () public {
45
+ function testOnChainProof () public {
46
46
// update merkle root
47
47
patriciaTree.insert("key1", "val1");
48
48
patriciaTree.insert("key2", "val2");
@@ -56,23 +56,23 @@ contract TestSparseTree {
56
56
bytes32[] memory siblings;
57
57
(branchMask, siblings) = patriciaTree.getProof("key1");
58
58
59
- // Init sparse tree with the root hash
60
- sparseTree .initialize(phaseAOfPatriciaTree);
59
+ // Init partial tree with the root hash
60
+ partialTree .initialize(phaseAOfPatriciaTree);
61
61
// commit branch (we submit sibling data here)
62
- sparseTree .commitBranch("key1", "val1", branchMask, siblings);
62
+ partialTree .commitBranch("key1", "val1", branchMask, siblings);
63
63
64
64
// Update key1 of patricia tree
65
65
patriciaTree.insert("key1", "val4");
66
66
67
- // Update key1 of sparse tree
68
- sparseTree .insert("key1", "val4");
67
+ // Update key1 of partial tree
68
+ partialTree .insert("key1", "val4");
69
69
70
70
// get updated root hashes of each tree
71
71
bytes32 phaseBOfPatriciaTree = patriciaTree.getRootHash();
72
- bytes32 phaseBOfSparseTree = sparseTree .getRootHash();
72
+ bytes32 phaseBOfPartialTree = partialTree .getRootHash();
73
73
74
74
// We have succeeded to reenact merkle tree transformation without submitting all node data
75
- require(phaseBOfPatriciaTree == phaseBOfSparseTree );
75
+ require(phaseBOfPatriciaTree == phaseBOfPartialTree );
76
76
}
77
77
}
78
78
```
@@ -90,9 +90,6 @@ npm install
90
90
91
91
### Tests
92
92
93
- Test cases include the information about how the functions work, but also includes a demo scenario.
94
- Running and reading the test cases will help you understand how it works.
95
-
96
93
``` bash
97
94
npm run test
98
95
```
0 commit comments