@@ -118,15 +118,17 @@ library IncrementalMerkleTree {
118118 * @param siblings_ The siblings of the leaf.
119119 * @param directionBits_ The direction bits of the leaf.
120120 * @param leaf_ The leaf.
121+ * @param root_ The root hash of the tree to verify against.
121122 * @return True if the proof is valid, false otherwise.
122123 */
123124 function verifyProof (
124125 UintIMT storage tree ,
125126 bytes32 [] memory siblings_ ,
126127 uint256 directionBits_ ,
127- bytes32 leaf_
128+ bytes32 leaf_ ,
129+ bytes32 root_
128130 ) internal view returns (bool ) {
129- return _verifyProof (tree._tree, siblings_, directionBits_, leaf_);
131+ return _verifyProof (tree._tree, siblings_, directionBits_, leaf_, root_ );
130132 }
131133
132134 /**
@@ -217,15 +219,36 @@ library IncrementalMerkleTree {
217219 * @param siblings_ The siblings of the leaf.
218220 * @param directionBits_ The direction bits of the leaf.
219221 * @param leaf_ The leaf.
222+ * @param root_ The root hash of the tree to verify against.
220223 * @return True if the proof is valid, false otherwise.
221224 */
222225 function verifyProof (
223226 Bytes32IMT storage tree ,
224227 bytes32 [] memory siblings_ ,
225228 uint256 directionBits_ ,
226- bytes32 leaf_
229+ bytes32 leaf_ ,
230+ bytes32 root_
227231 ) internal view returns (bool ) {
228- return _verifyProof (tree._tree, siblings_, directionBits_, leaf_);
232+ return _verifyProof (tree._tree, siblings_, directionBits_, leaf_, root_);
233+ }
234+
235+ /**
236+ * @notice The function to process the proof for inclusion or exclusion of a leaf in the tree.
237+ * Complexity is O(log(n)), where n is the number of elements in the tree.
238+ *
239+ * @param hash2_ The hash function that accepts two arguments.
240+ * @param siblings_ The siblings of the leaf.
241+ * @param directionBits_ The direction bits of the leaf.
242+ * @param leaf_ The leaf.
243+ * @return The calculated root hash from the proof.
244+ */
245+ function processProof (
246+ function (bytes32 , bytes32 ) view returns (bytes32 ) hash2_,
247+ bytes32 [] memory siblings_ ,
248+ uint256 directionBits_ ,
249+ bytes32 leaf_
250+ ) internal view returns (bytes32 ) {
251+ return _processProof (hash2_, siblings_, directionBits_, leaf_);
229252 }
230253
231254 /**
@@ -312,15 +335,17 @@ library IncrementalMerkleTree {
312335 * @param siblings_ The siblings of the leaf.
313336 * @param directionBits_ The direction bits of the leaf.
314337 * @param leaf_ The leaf.
338+ * @param root_ The root hash of the tree to verify against.
315339 * @return True if the proof is valid, false otherwise.
316340 */
317341 function verifyProof (
318342 AddressIMT storage tree ,
319343 bytes32 [] memory siblings_ ,
320344 uint256 directionBits_ ,
321- bytes32 leaf_
345+ bytes32 leaf_ ,
346+ bytes32 root_
322347 ) internal view returns (bool ) {
323- return _verifyProof (tree._tree, siblings_, directionBits_, leaf_);
348+ return _verifyProof (tree._tree, siblings_, directionBits_, leaf_, root_ );
324349 }
325350
326351 /**
@@ -462,12 +487,22 @@ library IncrementalMerkleTree {
462487 IMT storage tree ,
463488 bytes32 [] memory siblings_ ,
464489 uint256 directionBits ,
465- bytes32 leaf_
490+ bytes32 leaf_ ,
491+ bytes32 root_
466492 ) private view returns (bool ) {
467493 function (bytes32 , bytes32 ) view returns (bytes32 ) hash2_ = tree.isCustomHasherSet
468494 ? tree.hash2
469495 : _hash2;
470496
497+ return _processProof (hash2_, siblings_, directionBits, leaf_) == root_;
498+ }
499+
500+ function _processProof (
501+ function (bytes32 , bytes32 ) view returns (bytes32 ) hash2_,
502+ bytes32 [] memory siblings_ ,
503+ uint256 directionBits ,
504+ bytes32 leaf_
505+ ) private view returns (bytes32 ) {
471506 bytes32 computedHash_ = leaf_;
472507
473508 for (uint256 i = 0 ; i < siblings_.length ; ++ i) {
@@ -478,7 +513,7 @@ library IncrementalMerkleTree {
478513 }
479514 }
480515
481- return computedHash_ == _root (tree) ;
516+ return computedHash_;
482517 }
483518
484519 function _height (IMT storage tree ) private view returns (uint256 ) {
0 commit comments