Cyfrin / 2023-07-foundry-defi-stablecoin

38 stars 33 forks source link

Using unchecked blocks to save gas #1068

Open codehawks-bot opened 1 year ago

codehawks-bot commented 1 year ago

Using unchecked blocks to save gas

Severity

Gas Optimization / Informational

Summary

Increments in for loop can be unchecked ( save 30-40 gas per loop iteration)

Vulnerability Details

In line 119, the following is used

 for (uint256 i = 0; i < tokenAddresses.length; i++) {  
            s_priceFeeds[tokenAddresses[i]] = priceFeedAddresses[i]; 
            s_collateralTokens.push(tokenAddresses[i]);
        }

Impact

Increase in runtime gas costs

Tools Used

Manual review

Recommendations

Consider using the following.

for(uint256 i; i < tokenAddresses.length;) {
  // loop logic
  unchecked { ++i; }
}