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

Remove `success` check from `DSCEngine._burnDsc` to save gas

Summary

The transferFrom function of the DSC token always returns true, making it unnecessary to create an if statement and compare the result to false.

Vulnerability Details

In the DSCEngine._burnDsc function calls the DecentralizedStableCoin.transferFrom function to transfer tokens from msg.sender to the DSCEngine contract.

The return value of the transferFrom function is stored, and we check if it's false to revert the transaction. However, it's important to note that the transferFrom function in the DecentralizedStableCoin contract (inherited from OZ ERC20 v4.8.0) always returns true.

As a result, the additiond of an if statement to check for a false return value is redundant and unnecessary. Eliminating this check can help save gas for each burn operation, leading to more efficient contract execution.

Impact

Save gas for users anytime DSCEngine burn DSC tokens.

Tools Used

VSCode

Recommendations

Remove the following check to save gas:
https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/d1c5501aa79320ca0aeaa73f47f0dbc88c7b77e2/src/DSCEngine.sol#L276-L278

Support

FAQs

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