15,000 USDC
View results
Submission Details
Severity: gas

getUsdValue()- can be checked if amount is zero before calculation

Summary

In getUsdValue() function, the input parameter 'amount' can be checked if it is zero, then zero can be returned directly.

Vulnerability Details

In getUsdValue(), if the amount parameter value is zero, it still gets the price from the pricefeed, and does the calculation to anyways return zero.

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L361

Impact

Since the getUSDValue() is called inside the loop for each collateral tokens, whose balance might not be non-zero most times, unnecessary calls to price feed and the following calculation are made for each iteration.

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L356

Tools Used

Manual Review

Recommendations

The amount parameter in getUsdValue()fucntion can be checked if its zero, then zero value can be returned

Support

FAQs

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