@@ -146,7 +146,11 @@ library PartialMerkleTree {
146
146
}
147
147
148
148
function doesInclude (Tree storage tree , bytes key ) internal view returns (bool ) {
149
- bytes32 valueHash = _findNode (tree, key);
149
+ return doesIncludeHashedKey (tree, keccak256 (key));
150
+ }
151
+
152
+ function doesIncludeHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (bool ) {
153
+ bytes32 valueHash = _findNodeWithHashedKey (tree, hashedKey);
150
154
return (valueHash != bytes32 (0 ));
151
155
}
152
156
@@ -219,12 +223,21 @@ library PartialMerkleTree {
219
223
bytes32 potentialSiblingValue ,
220
224
uint branchMask ,
221
225
bytes32 [] _siblings
226
+ ) {
227
+ return getNonInclusionProofWithHashedKey (tree, keccak256 (key));
228
+ }
229
+
230
+ function getNonInclusionProofWithHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (
231
+ bytes32 potentialSiblingLabel ,
232
+ bytes32 potentialSiblingValue ,
233
+ uint branchMask ,
234
+ bytes32 [] _siblings
222
235
){
223
236
uint length;
224
237
uint numSiblings;
225
238
226
239
// Start from root edge
227
- D.Label memory label = D.Label (keccak256 (key) , 256 );
240
+ D.Label memory label = D.Label (hashedKey , 256 );
228
241
D.Edge memory e = tree.rootEdge;
229
242
bytes32 [256 ] memory siblings;
230
243
@@ -358,10 +371,14 @@ library PartialMerkleTree {
358
371
}
359
372
360
373
function _findNode (Tree storage tree , bytes key ) private view returns (bytes32 ) {
374
+ return _findNodeWithHashedKey (tree, keccak256 (key));
375
+ }
376
+
377
+ function _findNodeWithHashedKey (Tree storage tree , bytes32 hashedKey ) private view returns (bytes32 ) {
361
378
if (tree.rootEdge.node == 0 && tree.rootEdge.label.length == 0 ) {
362
379
return 0 ;
363
380
} else {
364
- D.Label memory k = D.Label (keccak256 (key) , 256 );
381
+ D.Label memory k = D.Label (hashedKey , 256 );
365
382
return _findAtEdge (tree, tree.rootEdge, k);
366
383
}
367
384
}
0 commit comments