From a99b31f990234b330098d8f7bd24e7c8ec704076 Mon Sep 17 00:00:00 2001 From: Michael <20623991+heueristik@users.noreply.github.com> Date: Tue, 7 Jan 2025 01:02:58 +0100 Subject: [PATCH] Optimize `MerkleTree` for loops by using `uint256` iterators (#5415) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ernesto GarcĂ­a --- contracts/utils/structs/MerkleTree.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/utils/structs/MerkleTree.sol b/contracts/utils/structs/MerkleTree.sol index 56f5bc672..a52cfc91d 100644 --- a/contracts/utils/structs/MerkleTree.sol +++ b/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;