Optimize `MerkleTree` for loops by using `uint256` iterators (#5415)

Co-authored-by: Ernesto García <ernestognw@gmail.com>
pull/5420/head
Michael 2 months ago committed by GitHub
parent 45dd083602
commit a99b31f990
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      contracts/utils/structs/MerkleTree.sol

@ -88,7 +88,7 @@ library MerkleTree {
// Build each root of zero-filled subtrees
bytes32 currentZero = zero;
for (uint32 i = 0; i < treeDepth; ++i) {
for (uint256 i = 0; i < treeDepth; ++i) {
Arrays.unsafeAccess(self._zeros, i).value = currentZero;
currentZero = fnHash(currentZero, currentZero);
}
@ -143,7 +143,7 @@ library MerkleTree {
// Rebuild branch from leaf to root
uint256 currentIndex = index;
bytes32 currentLevelHash = leaf;
for (uint32 i = 0; i < treeDepth; i++) {
for (uint256 i = 0; i < treeDepth; i++) {
// Reaching the parent node, is currentLevelHash the left child?
bool isLeft = currentIndex % 2 == 0;

Loading…
Cancel
Save