stake.link

stake.link
DeFiHardhatBridge
27,500 USDC
View results
Submission Details
Severity: low
Invalid

Optimization Opportunities in Various Solidity Contracts

Summary

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.

Vulnerability Details

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:

  1. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 56

    • Function: distributeRewards

    • Description: Cache tokens.length

  2. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 68

    • Function: distributeRewards

    • Description: Cache tokens.length

  3. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 174

    • Function: removeWhitelistedChain

    • Description: Cache whitelistedChains.length

  4. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 192

    • Function: approveRewardTokens

    • Description: Cache _tokens.length

  5. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 253

    • Function: _distributeRewards

    • Description: Cache _rewardTokens.length

  6. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 264

    • Function: _distributeRewards

    • Description: Cache _rewardTokens.length

  7. File: SDLPoolCCIPControllerPrimary.sol

    • Line: 354

    • Function: _buildCCIPMessage

    • Description: Cache _tokenAmounts.length

  8. File: WrappedTokenBridge.sol

    • Line: 143

    • Function: recoverTokens

    • Description: Cache _tokens.length

  9. File: SDLPoolSecondary.sol

    • Line: 454

    • Function: _executeQueuedLockUpdates

    • Description: Cache _lockIds.length

  10. File: SDLPool.sol

    • Line: 160

    • Function: getLocks

    • Description: Cache _lockIds.length

Impact

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.

Tools Used

Manual Review

Recommendations

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.

Updates

Lead Judging Commences

0kage Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.