@@ -33,7 +33,11 @@ library PatriciaTree {
33
33
}
34
34
35
35
function doesInclude (Tree storage tree , bytes key ) internal view returns (bool ) {
36
- bytes32 valueHash = _findNode (tree, key);
36
+ return doesIncludeHashedKey (keccak256 (key));
37
+ }
38
+
39
+ function doesIncludeHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (bool ) {
40
+ bytes32 valueHash = _findNodeWithHashedKey (tree, hashedKey);
37
41
return (valueHash != bytes32 (0 ));
38
42
}
39
43
@@ -114,12 +118,21 @@ library PatriciaTree {
114
118
bytes32 potentialSiblingValue ,
115
119
uint branchMask ,
116
120
bytes32 [] _siblings
121
+ ) {
122
+ return getNonInclusionProofWithHashedKey (tree, keccak256 (key));
123
+ }
124
+
125
+ function getNonInclusionProofWithHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (
126
+ bytes32 potentialSiblingLabel ,
127
+ bytes32 potentialSiblingValue ,
128
+ uint branchMask ,
129
+ bytes32 [] _siblings
117
130
){
118
131
uint length;
119
132
uint numSiblings;
120
133
121
134
// Start from root edge
122
- D.Label memory label = D.Label (keccak256 (key) , 256 );
135
+ D.Label memory label = D.Label (hashedKey , 256 );
123
136
D.Edge memory e = tree.rootEdge;
124
137
bytes32 [256 ] memory siblings;
125
138
@@ -268,10 +281,14 @@ library PatriciaTree {
268
281
}
269
282
270
283
function _findNode (Tree storage tree , bytes key ) private view returns (bytes32 ) {
284
+ return _findNodeWithHashedKey (tree, keccak256 (key));
285
+ }
286
+
287
+ function _findNodeWithHashedKey (Tree storage tree , bytes32 hashedKey ) private view returns (bytes32 ) {
271
288
if (tree.rootEdge.node == 0 && tree.rootEdge.label.length == 0 ) {
272
289
return 0 ;
273
290
} else {
274
- D.Label memory k = D.Label (keccak256 (key) , 256 );
291
+ D.Label memory k = D.Label (hashedKey , 256 );
275
292
return _findAtEdge (tree, tree.rootEdge, k);
276
293
}
277
294
}
0 commit comments