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

Increment loop using unchecked block

Summary

Reduce 426 units of gas in execution cost by incrementing loop with a unchecked block in DSCEngine::getAccountCollateralValue. There's no possibility of overflow in this loop.

function getAccountCollateralValue(address user) public view returns (uint256 totalCollateralValueInUsd) {
// loop through each collateral token, get the amount they have deposited, and map it to
// the price, to get the USD value
for (uint256 i = 0; i < s_collateralTokens.length;) {
address token = s_collateralTokens[i];
uint256 amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += getUsdValue(token, amount);
unchecked {
i++;
}
}
return totalCollateralValueInUsd;
}

Tools Used

VS Code and Foundry

Support

FAQs

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