15,000 USDC
View results
Submission Details
Severity: gas
Valid

Use unchecked on iterator for gas savings

Summary

Can save gas if unchecked and ++i are used.

Vulnerability Details

++i/i++ Should Be unchecked{++i}/unchecked{i++} When It Is Not Possible For Them To Overflow

Impact

++i costs less gas than i++, and will cost even less when put in an unchecked block.

Tools Used

Manual review

Recommendations

Change this:

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

To this:

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

Support

FAQs

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