From 21940c369b1216ea2d537ec1bea0976a16e5e09d Mon Sep 17 00:00:00 2001 From: uri margalit Date: Fri, 8 Mar 2024 18:21:05 +0200 Subject: [PATCH] Reduce gas in getApkIndicesAtBlockNumber --- src/BLSApkRegistry.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BLSApkRegistry.sol b/src/BLSApkRegistry.sol index 9d145ddd..5ffa9286 100644 --- a/src/BLSApkRegistry.sol +++ b/src/BLSApkRegistry.sol @@ -215,9 +215,9 @@ contract BLSApkRegistry is BLSApkRegistryStorage { } // Loop backward through apkHistory until we find an entry that preceeds `blockNumber` - for (uint256 j = quorumApkUpdatesLength; j > 0; j--) { - if (apkHistory[quorumNumber][j - 1].updateBlockNumber <= blockNumber) { - indices[i] = uint32(j - 1); + for (uint256 j = quorumApkUpdatesLength - 1; j >= 0 ; j--) { + if (apkHistory[quorumNumber][j].updateBlockNumber <= blockNumber) { + indices[i] = uint32(j); break; } }