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

Unoptimized `getAccountCollateralValue` function

Summary

Declaring the token and amount variables in the getAccountCollateralValue function outside the for loop can save considerable amount of gas, especially for large address arrays.

Vulnerability Details

See summary

Impact

Considerable amount of gas can be saved, making the protocol cheaper to use.

Tools Used

Remix

Recommendations

The optimized getAccountCollateralValue function:

function getAccountCollateralValue(address user) public view returns (uint256 totalCollateralValueInUsd) {
address token; // <-- Here
uint256 amount // <-- Here
uint256 length = s_collateralTokens.length;
for (uint256 index; index < length;) {
token = s_collateralTokens[index];
amount = s_collateralDeposited[user][token];
totalCollateralValueInUsd += _getUsdValue(token, amount);
unchecked {
++index;
}
}
return totalCollateralValueInUsd;
}

Support

FAQs

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