This report aggregates findings from multiple Solidity smart contracts, focusing on opportunities for optimization through caching array lengths in loops. These improvements are aimed at enhancing gas efficiency across different functions.
The identified issues across various contracts involve the absence of caching for array lengths in for-loops, which can lead to unnecessary gas consumption. Each instance is detailed below:
File: SDLPoolCCIPControllerPrimary.sol
Line: 56
Function: distributeRewards
Description: Cache tokens.length
File: SDLPoolCCIPControllerPrimary.sol
Line: 68
Function: distributeRewards
Description: Cache tokens.length
File: SDLPoolCCIPControllerPrimary.sol
Line: 174
Function: removeWhitelistedChain
Description: Cache whitelistedChains.length
File: SDLPoolCCIPControllerPrimary.sol
Line: 192
Function: approveRewardTokens
Description: Cache _tokens.length
File: SDLPoolCCIPControllerPrimary.sol
Line: 253
Function: _distributeRewards
Description: Cache _rewardTokens.length
File: SDLPoolCCIPControllerPrimary.sol
Line: 264
Function: _distributeRewards
Description: Cache _rewardTokens.length
File: SDLPoolCCIPControllerPrimary.sol
Line: 354
Function: _buildCCIPMessage
Description: Cache _tokenAmounts.length
File: WrappedTokenBridge.sol
Line: 143
Function: recoverTokens
Description: Cache _tokens.length
File: SDLPoolSecondary.sol
Line: 454
Function: _executeQueuedLockUpdates
Description: Cache _lockIds.length
File: SDLPool.sol
Line: 160
Function: getLocks
Description: Cache _lockIds.length
In some of these cases the gas savings achieved dealing with this is not that much but since it's such a simple change to make it might be worth to consider.
Manual Review
For each of the above instances, it is recommended to cache the array length in a local variable before the loop begins, and use this cached value within the loop's conditional statement. This change will reduce the number of state reads from the EVM, leading to reduced gas consumption and improved contract performance.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.