Skip to content

Commit fdcc120

Browse files
authored
Merge pull request #1 from commitground/hotfix-1.0.2
Hotfix 1.0.2
2 parents 132c229 + d05cead commit fdcc120

File tree

6 files changed

+128
-118
lines changed

6 files changed

+128
-118
lines changed

.solcover.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
norpc: true,
3+
testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage',
4+
compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile --network coverage',
5+
skipFiles: [
6+
'contracts/Migrations.sol',
7+
'contracts/implementation.sol'
8+
]
9+
}

contracts/tree.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ library PatriciaTree {
6161
// where we have branch nodes (bit in key denotes direction)
6262
// - bytes32[] hashes - hashes of sibling edges
6363
function getProof(Tree storage tree, bytes key) internal view returns (uint branchMask, bytes32[] _siblings) {
64-
D.Label memory k = D.Label(keccak256(key), 256);
64+
return getProofWithHashedKey(tree, keccak256(key));
65+
}
66+
67+
function getProofWithHashedKey(Tree storage tree, bytes32 hashedKey) internal view returns (uint branchMask, bytes32[] _siblings) {
68+
D.Label memory k = D.Label(hashedKey, 256);
6569
D.Edge memory e = tree.rootEdge;
6670
bytes32[256] memory siblings;
6771
uint length;

contracts/utils.sol

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -83,119 +83,4 @@ library Utils {
8383
}
8484

8585

86-
contract UtilsTest {
87-
function test() public pure {
88-
testLowestBitSet();
89-
testChopFirstBit();
90-
testRemovePrefix();
91-
testCommonPrefix();
92-
testSplitAt();
93-
testSplitCommonPrefix();
94-
}
95-
96-
function testLowestBitSet() internal pure {
97-
require(Utils.lowestBitSet(0x123) == 0);
98-
require(Utils.lowestBitSet(0x124) == 2);
99-
require(Utils.lowestBitSet(0x11 << 30) == 30);
100-
require(Utils.lowestBitSet(1 << 255) == 255);
101-
}
102-
103-
function testChopFirstBit() internal pure {
104-
D.Label memory l;
105-
l.data = hex"ef1230";
106-
l.length = 20;
107-
uint bit1;
108-
uint bit2;
109-
uint bit3;
110-
uint bit4;
111-
(bit1, l) = Utils.chopFirstBit(l);
112-
(bit2, l) = Utils.chopFirstBit(l);
113-
(bit3, l) = Utils.chopFirstBit(l);
114-
(bit4, l) = Utils.chopFirstBit(l);
115-
require(bit1 == 1);
116-
require(bit2 == 1);
117-
require(bit3 == 1);
118-
require(bit4 == 0);
119-
require(l.length == 16);
120-
require(l.data == hex"F123");
121-
122-
l.data = hex"80";
123-
l.length = 1;
124-
(bit1, l) = Utils.chopFirstBit(l);
125-
require(bit1 == 1);
126-
require(l.length == 0);
127-
require(l.data == 0);
128-
}
129-
130-
function testRemovePrefix() internal pure {
131-
D.Label memory l;
132-
l.data = hex"ef1230";
133-
l.length = 20;
134-
l = Utils.removePrefix(l, 4);
135-
require(l.length == 16);
136-
require(l.data == hex"f123");
137-
l = Utils.removePrefix(l, 15);
138-
require(l.length == 1);
139-
require(l.data == hex"80");
140-
l = Utils.removePrefix(l, 1);
141-
require(l.length == 0);
142-
require(l.data == 0);
143-
}
144-
145-
function testCommonPrefix() internal pure {
146-
D.Label memory a;
147-
D.Label memory b;
148-
a.data = hex"abcd";
149-
a.length = 16;
150-
b.data = hex"a000";
151-
b.length = 16;
152-
require(Utils.commonPrefix(a, b) == 4);
15386

154-
b.length = 0;
155-
require(Utils.commonPrefix(a, b) == 0);
156-
157-
b.data = hex"bbcd";
158-
b.length = 16;
159-
require(Utils.commonPrefix(a, b) == 3);
160-
require(Utils.commonPrefix(b, b) == b.length);
161-
}
162-
163-
function testSplitAt() internal pure {
164-
D.Label memory a;
165-
a.data = hex"abcd";
166-
a.length = 16;
167-
D.Label memory x;
168-
D.Label memory y;
169-
(x, y) = Utils.splitAt(a, 0);
170-
require(x.length == 0);
171-
require(y.length == a.length);
172-
require(y.data == a.data);
173-
174-
(x, y) = Utils.splitAt(a, 4);
175-
require(x.length == 4);
176-
require(x.data == hex"a0");
177-
require(y.length == 12);
178-
require(y.data == hex"bcd0");
179-
180-
(x, y) = Utils.splitAt(a, 16);
181-
require(y.length == 0);
182-
require(x.length == a.length);
183-
require(x.data == a.data);
184-
}
185-
186-
function testSplitCommonPrefix() internal pure {
187-
D.Label memory a;
188-
D.Label memory b;
189-
a.data = hex"abcd";
190-
a.length = 16;
191-
b.data = hex"a0f570";
192-
b.length = 20;
193-
D.Label memory prefix;
194-
D.Label memory suffix;
195-
(prefix, suffix) = Utils.splitCommonPrefix(b, a);
196-
require(prefix.length == 4);
197-
require(prefix.data == hex"a0");
198-
require(suffix.length == 16);
199-
require(suffix.data == hex"0f57");
200-
}
201-
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidity-patricia-tree",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Patricia Tree solidity implemenation",
55
"directories": {
66
"test": "test"

test/TestUtils.sol

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
pragma solidity ^0.4.0;
2+
3+
import {D} from "../contracts/data.sol";
4+
import {Utils} from "../contracts/utils.sol";
5+
6+
contract TestUtils {
7+
function testLowestBitSet() internal pure {
8+
require(Utils.lowestBitSet(0x123) == 0);
9+
require(Utils.lowestBitSet(0x124) == 2);
10+
require(Utils.lowestBitSet(0x11 << 30) == 30);
11+
require(Utils.lowestBitSet(1 << 255) == 255);
12+
}
13+
14+
function testChopFirstBit() internal pure {
15+
D.Label memory l;
16+
l.data = hex"ef1230";
17+
l.length = 20;
18+
uint bit1;
19+
uint bit2;
20+
uint bit3;
21+
uint bit4;
22+
(bit1, l) = Utils.chopFirstBit(l);
23+
(bit2, l) = Utils.chopFirstBit(l);
24+
(bit3, l) = Utils.chopFirstBit(l);
25+
(bit4, l) = Utils.chopFirstBit(l);
26+
require(bit1 == 1);
27+
require(bit2 == 1);
28+
require(bit3 == 1);
29+
require(bit4 == 0);
30+
require(l.length == 16);
31+
require(l.data == hex"F123");
32+
33+
l.data = hex"80";
34+
l.length = 1;
35+
(bit1, l) = Utils.chopFirstBit(l);
36+
require(bit1 == 1);
37+
require(l.length == 0);
38+
require(l.data == 0);
39+
}
40+
41+
function testRemovePrefix() internal pure {
42+
D.Label memory l;
43+
l.data = hex"ef1230";
44+
l.length = 20;
45+
l = Utils.removePrefix(l, 4);
46+
require(l.length == 16);
47+
require(l.data == hex"f123");
48+
l = Utils.removePrefix(l, 15);
49+
require(l.length == 1);
50+
require(l.data == hex"80");
51+
l = Utils.removePrefix(l, 1);
52+
require(l.length == 0);
53+
require(l.data == 0);
54+
}
55+
56+
function testCommonPrefix() internal pure {
57+
D.Label memory a;
58+
D.Label memory b;
59+
a.data = hex"abcd";
60+
a.length = 16;
61+
b.data = hex"a000";
62+
b.length = 16;
63+
require(Utils.commonPrefix(a, b) == 4);
64+
65+
b.length = 0;
66+
require(Utils.commonPrefix(a, b) == 0);
67+
68+
b.data = hex"bbcd";
69+
b.length = 16;
70+
require(Utils.commonPrefix(a, b) == 3);
71+
require(Utils.commonPrefix(b, b) == b.length);
72+
}
73+
74+
function testSplitAt() internal pure {
75+
D.Label memory a;
76+
a.data = hex"abcd";
77+
a.length = 16;
78+
D.Label memory x;
79+
D.Label memory y;
80+
(x, y) = Utils.splitAt(a, 0);
81+
require(x.length == 0);
82+
require(y.length == a.length);
83+
require(y.data == a.data);
84+
85+
(x, y) = Utils.splitAt(a, 4);
86+
require(x.length == 4);
87+
require(x.data == hex"a0");
88+
require(y.length == 12);
89+
require(y.data == hex"bcd0");
90+
91+
(x, y) = Utils.splitAt(a, 16);
92+
require(y.length == 0);
93+
require(x.length == a.length);
94+
require(x.data == a.data);
95+
}
96+
97+
function testSplitCommonPrefix() internal pure {
98+
D.Label memory a;
99+
D.Label memory b;
100+
a.data = hex"abcd";
101+
a.length = 16;
102+
b.data = hex"a0f570";
103+
b.length = 20;
104+
D.Label memory prefix;
105+
D.Label memory suffix;
106+
(prefix, suffix) = Utils.splitCommonPrefix(b, a);
107+
require(prefix.length == 4);
108+
require(prefix.data == hex"a0");
109+
require(suffix.length == 16);
110+
require(suffix.data == hex"0f57");
111+
}
112+
}

0 commit comments

Comments
 (0)