1
- pragma solidity ^ 0.4.24 ;
1
+ pragma solidity >= 0.5.0 < 0.6.0 ;
2
2
3
3
import {Utils} from "./utils.sol " ;
4
4
import {D} from "./data.sol " ;
@@ -27,7 +27,13 @@ library PartialMerkleTree {
27
27
tree.root = root;
28
28
}
29
29
30
- function commitBranch (Tree storage tree , bytes key , bytes value , uint branchMask , bytes32 [] siblings ) internal {
30
+ function commitBranch (
31
+ Tree storage tree ,
32
+ bytes memory key ,
33
+ bytes memory value ,
34
+ uint branchMask ,
35
+ bytes32 [] memory siblings
36
+ ) internal {
31
37
D.Label memory k = D.Label (keccak256 (key), 256 );
32
38
D.Edge memory e;
33
39
e.node = keccak256 (value);
@@ -66,11 +72,11 @@ library PartialMerkleTree {
66
72
67
73
function commitBranchOfNonInclusion (
68
74
Tree storage tree ,
69
- bytes key ,
75
+ bytes memory key ,
70
76
bytes32 potentialSiblingLabel ,
71
77
bytes32 potentialSiblingValue ,
72
78
uint branchMask ,
73
- bytes32 [] siblings
79
+ bytes32 [] memory siblings
74
80
) internal {
75
81
D.Label memory k = D.Label (keccak256 (key), 256 );
76
82
D.Edge memory e;
@@ -114,7 +120,11 @@ library PartialMerkleTree {
114
120
tree.rootEdge = e;
115
121
}
116
122
117
- function insert (Tree storage tree , bytes key , bytes value ) internal {
123
+ function insert (
124
+ Tree storage tree ,
125
+ bytes memory key ,
126
+ bytes memory value
127
+ ) internal {
118
128
D.Label memory k = D.Label (keccak256 (key), 256 );
119
129
bytes32 valueHash = keccak256 (value);
120
130
tree.values[valueHash] = value;
@@ -134,18 +144,18 @@ library PartialMerkleTree {
134
144
tree.rootEdge = e;
135
145
}
136
146
137
- function get (Tree storage tree , bytes key ) internal view returns (bytes ) {
147
+ function get (Tree storage tree , bytes memory key ) internal view returns (bytes memory ) {
138
148
return getValue (tree, _findNode (tree, key));
139
149
}
140
150
141
- function safeGet (Tree storage tree , bytes key ) internal view returns (bytes value ) {
151
+ function safeGet (Tree storage tree , bytes memory key ) internal view returns (bytes memory value ) {
142
152
bytes32 valueHash = _findNode (tree, key);
143
153
require (valueHash != bytes32 (0 ));
144
154
value = getValue (tree, valueHash);
145
155
require (valueHash == keccak256 (value));
146
156
}
147
157
148
- function doesInclude (Tree storage tree , bytes key ) internal view returns (bool ) {
158
+ function doesInclude (Tree storage tree , bytes memory key ) internal view returns (bool ) {
149
159
return doesIncludeHashedKey (tree, keccak256 (key));
150
160
}
151
161
@@ -154,7 +164,7 @@ library PartialMerkleTree {
154
164
return (valueHash != bytes32 (0 ));
155
165
}
156
166
157
- function getValue (Tree storage tree , bytes32 valueHash ) internal view returns (bytes ) {
167
+ function getValue (Tree storage tree , bytes32 valueHash ) internal view returns (bytes memory ) {
158
168
return tree.values[valueHash];
159
169
}
160
170
@@ -181,11 +191,11 @@ library PartialMerkleTree {
181
191
// - uint branchMask - bitmask with high bits at the positions in the key
182
192
// where we have branch nodes (bit in key denotes direction)
183
193
// - bytes32[] hashes - hashes of sibling edges
184
- function getProof (Tree storage tree , bytes key ) internal view returns (uint branchMask , bytes32 [] _siblings ) {
194
+ function getProof (Tree storage tree , bytes memory key ) internal view returns (uint branchMask , bytes32 [] memory _siblings ) {
185
195
return getProofWithHashedKey (tree, keccak256 (key));
186
196
}
187
197
188
- function getProofWithHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (uint branchMask , bytes32 [] _siblings ) {
198
+ function getProofWithHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (uint branchMask , bytes32 [] memory _siblings ) {
189
199
D.Label memory k = D.Label (hashedKey, 256 );
190
200
D.Edge memory e = tree.rootEdge;
191
201
bytes32 [256 ] memory siblings;
@@ -218,11 +228,11 @@ library PartialMerkleTree {
218
228
}
219
229
}
220
230
221
- function getNonInclusionProof (Tree storage tree , bytes key ) internal view returns (
231
+ function getNonInclusionProof (Tree storage tree , bytes memory key ) internal view returns (
222
232
bytes32 potentialSiblingLabel ,
223
233
bytes32 potentialSiblingValue ,
224
234
uint branchMask ,
225
- bytes32 [] _siblings
235
+ bytes32 [] memory _siblings
226
236
) {
227
237
return getNonInclusionProofWithHashedKey (tree, keccak256 (key));
228
238
}
@@ -231,7 +241,7 @@ library PartialMerkleTree {
231
241
bytes32 potentialSiblingLabel ,
232
242
bytes32 potentialSiblingValue ,
233
243
uint branchMask ,
234
- bytes32 [] _siblings
244
+ bytes32 [] memory _siblings
235
245
){
236
246
uint length;
237
247
uint numSiblings;
@@ -275,7 +285,13 @@ library PartialMerkleTree {
275
285
}
276
286
}
277
287
278
- function verifyProof (bytes32 rootHash , bytes key , bytes value , uint branchMask , bytes32 [] siblings ) public pure {
288
+ function verifyProof (
289
+ bytes32 rootHash ,
290
+ bytes memory key ,
291
+ bytes memory value ,
292
+ uint branchMask ,
293
+ bytes32 [] memory siblings
294
+ ) public pure {
279
295
D.Label memory k = D.Label (keccak256 (key), 256 );
280
296
D.Edge memory e;
281
297
e.node = keccak256 (value);
@@ -294,7 +310,14 @@ library PartialMerkleTree {
294
310
require (rootHash == edgeHash (e));
295
311
}
296
312
297
- function verifyNonInclusionProof (bytes32 rootHash , bytes key , bytes32 potentialSiblingLabel , bytes32 potentialSiblingValue , uint branchMask , bytes32 [] siblings ) public pure {
313
+ function verifyNonInclusionProof (
314
+ bytes32 rootHash ,
315
+ bytes memory key ,
316
+ bytes32 potentialSiblingLabel ,
317
+ bytes32 potentialSiblingValue ,
318
+ uint branchMask ,
319
+ bytes32 [] memory siblings
320
+ ) public pure {
298
321
D.Label memory k = D.Label (keccak256 (key), 256 );
299
322
D.Edge memory e;
300
323
for (uint i = 0 ; branchMask != 0 ; i++ ) {
@@ -317,12 +340,12 @@ library PartialMerkleTree {
317
340
require (rootHash == edgeHash (e));
318
341
}
319
342
320
- function newEdge (bytes32 node , D.Label label ) internal pure returns (D.Edge memory e ){
343
+ function newEdge (bytes32 node , D.Label memory label ) internal pure returns (D.Edge memory e ){
321
344
e.node = node;
322
345
e.label = label;
323
346
}
324
347
325
- function _insertAtNode (Tree storage tree , bytes32 nodeHash , D.Label key , bytes32 value ) private returns (bytes32 ) {
348
+ function _insertAtNode (Tree storage tree , bytes32 nodeHash , D.Label memory key , bytes32 value ) private returns (bytes32 ) {
326
349
// require(key.length > 1);
327
350
D.Node memory n = tree.nodes[nodeHash];
328
351
uint head;
@@ -332,7 +355,7 @@ library PartialMerkleTree {
332
355
return _replaceNode (tree, nodeHash, n);
333
356
}
334
357
335
- function _insertAtEdge (Tree storage tree , D.Edge e , D.Label key , bytes32 value ) private returns (D.Edge) {
358
+ function _insertAtEdge (Tree storage tree , D.Edge memory e , D.Label memory key , bytes32 value ) private returns (D.Edge memory ) {
336
359
// require(e.hasNode());
337
360
require (key.length >= e.label.length );
338
361
D.Label memory prefix;
@@ -370,7 +393,7 @@ library PartialMerkleTree {
370
393
return _insertNode (tree, n);
371
394
}
372
395
373
- function _findNode (Tree storage tree , bytes key ) private view returns (bytes32 ) {
396
+ function _findNode (Tree storage tree , bytes memory key ) private view returns (bytes32 ) {
374
397
return _findNodeWithHashedKey (tree, keccak256 (key));
375
398
}
376
399
@@ -383,7 +406,7 @@ library PartialMerkleTree {
383
406
}
384
407
}
385
408
386
- function _findAtNode (Tree storage tree , bytes32 nodeHash , D.Label key ) private view returns (bytes32 ) {
409
+ function _findAtNode (Tree storage tree , bytes32 nodeHash , D.Label memory key ) private view returns (bytes32 ) {
387
410
require (key.length > 1 );
388
411
D.Node memory n = tree.nodes[nodeHash];
389
412
uint head;
@@ -392,7 +415,7 @@ library PartialMerkleTree {
392
415
return _findAtEdge (tree, n.children[head], tail);
393
416
}
394
417
395
- function _findAtEdge (Tree storage tree , D.Edge e , D.Label key ) private view returns (bytes32 ){
418
+ function _findAtEdge (Tree storage tree , D.Edge memory e , D.Label memory key ) private view returns (bytes32 ){
396
419
require (key.length >= e.label.length );
397
420
D.Label memory prefix;
398
421
D.Label memory suffix;
0 commit comments