Skip to content

Commit a99b31f

Browse files
Optimize MerkleTree for loops by using uint256 iterators (#5415)
Co-authored-by: Ernesto García <ernestognw@gmail.com>
1 parent 45dd083 commit a99b31f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

contracts/utils/structs/MerkleTree.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ library MerkleTree {
8888

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

0 commit comments

Comments
 (0)