@@ -146,7 +146,11 @@ library PartialMerkleTree {
146146 }
147147
148148 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);
150154 return (valueHash != bytes32 (0 ));
151155 }
152156
@@ -219,12 +223,21 @@ library PartialMerkleTree {
219223 bytes32 potentialSiblingValue ,
220224 uint branchMask ,
221225 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
222235 ){
223236 uint length;
224237 uint numSiblings;
225238
226239 // Start from root edge
227- D.Label memory label = D.Label (keccak256 (key) , 256 );
240+ D.Label memory label = D.Label (hashedKey , 256 );
228241 D.Edge memory e = tree.rootEdge;
229242 bytes32 [256 ] memory siblings;
230243
@@ -358,10 +371,14 @@ library PartialMerkleTree {
358371 }
359372
360373 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 ) {
361378 if (tree.rootEdge.node == 0 && tree.rootEdge.label.length == 0 ) {
362379 return 0 ;
363380 } else {
364- D.Label memory k = D.Label (keccak256 (key) , 256 );
381+ D.Label memory k = D.Label (hashedKey , 256 );
365382 return _findAtEdge (tree, tree.rootEdge, k);
366383 }
367384 }
0 commit comments