15,000 USDC
View results
Submission Details
Severity: gas

Cache Storage Values && Unnecessary initialisation to default values

Summary

  1. When accessing same storage value (.length) multiple times, it is better to cache the value to save the gas, as reading from storage charges more gas.

function getAccountCollateralValue(address user) public view returns (uint256 totalCollateralValueInUsd) {
for (uint256 i = 0; i < s_collateralTokens.length; i++) {
...
}
...
}
  1. Unnecessary initialisation of the value i = 0 in loops.

constructor(address[] memory tokenAddresses, address[] memory priceFeedAddresses, address dscAddress) {
...
// For example ETH / USD, BTC / USD, MKR / USD, etc
for (uint256 i = 0; i < tokenAddresses.length; i++) {
...
}
...
}

Support

FAQs

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