Gas optimization opportunity for the for loop
in getAccountCollateralValue().
n/a
Paying more gas than necessary, especially with a for loop, there's lots of room for optimization.
VSC, manual.
Instead of:
for (uint256 i = 0; i < s_collateralTokens.length; i++) {
address token = s_collateralTokens[i];
uint256 amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += getUsdValue(token, amount);
}
Recommend to implement this:
uint256 _collateralTokensLength = s_collateralTokens.length;
for (uint256 i; i < _collateralTokensLength; ) {
address token = s_collateralTokens[i];
uint256 amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += getUsdValue(token, amount);
unchecked {
i++;
}
}
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.