We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for loop
Gas Optimization / Informational
https://github.com/Cyfrin/foundry-defi-stablecoin-codehawks/blob/c573394cf3f21f73ef974388138193609f432c7f/src/DSCEngine.sol#L353-L357
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 text was updated successfully, but these errors were encountered:
No branches or pull requests
Gas optimization opportunity for the
for loop
in getAccountCollateralValue()Severity
Gas Optimization / Informational
Relevant GitHub Links
https://github.com/Cyfrin/foundry-defi-stablecoin-codehawks/blob/c573394cf3f21f73ef974388138193609f432c7f/src/DSCEngine.sol#L353-L357
Summary
Gas optimization opportunity for the
for loop
in getAccountCollateralValue().Vulnerability Details
n/a
Impact
Paying more gas than necessary, especially with a for loop, there's lots of room for optimization.
Tools Used
VSC, manual.
Recommendations
Instead of:
Recommend to implement this:
The text was updated successfully, but these errors were encountered: