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

Use unchecked keyword in loops when incrementing i value

Summary

For the fairly innocuous i++ or ++i Solidity will insert extra code to handle the case i would overflow when incremented. This is useless in our case since we know as a fact that the i value is based on the length of an array which will never overflow.

There are 2 instances of for loops where this can be implemented:

-for (uint256 i = 0; i < s_collateralTokens.length; i++) {
+for (uint256 i; i < cachedLength;) {
+ unchecked {
+ ++i;
+ }
address token = s_collateralTokens[i];
uint256 amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += getUsdValue(token, amount);
}

Support

FAQs

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