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

Redundant balance check in burn method of DecentralizedStableCoin contract

Summary

The burn method in DecentralizedStableCoin contract reads the user's balance from the storage and reverts with custom error if the amount of DSC to burn exceeds it.

function burn(uint256 _amount) public override onlyOwner {
uint256 balance = balanceOf(msg.sender);
if (_amount <= 0) {
revert DecentralizedStableCoin__MustBeMoreThanZero();
}
if (balance < _amount) {
revert DecentralizedStableCoin__BurnAmountExceedsBalance();
}
super.burn(_amount);
}

This check is already being performed in the _burn method of ERC20 contract. The method can therefore be simplified for gas savings:

function burn(uint256 _amount) public override onlyOwner {
if (_amount <= 0) {
revert DecentralizedStableCoin__MustBeMoreThanZero();
}
super.burn(_amount);
}

The custom error DecentralizedStableCoin__BurnAmountExceedsBalance can be removed.

Vulnerability Details

n/a

Impact

Unnecessary gas consumption

Tools Used

Manual review

Recommendations

Please consider removing redundant lines of code as suggested in summary.

Support

FAQs

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