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

Unnecessary checks

Summary

Some checks are redundant and unnecessary, they can be removed to save gas.

Vulnerability Details

DecentralizedStableCoin.sol

  • DecentralizedStableCoin.sol:60-62: The following code is unnecessary as super.burn(_amount); eventually triggers ERC20._burn(address, amount) from OpenZeppelin. This function already includes a revert for this condition. As a result, the error message defined on line 43 (DecentralizedStableCoin__BurnAmountExceedsBalance();) can also be removed.

  • DecentralizedStableCoin.sol:67-72: Those checks are already made by the _mint function or by the built in uint256 < 0 in solidity.

All the custom errors can be deleted

Impact

Significant amount of gas can be saved if the redundant checks are removed.

Tools Used

Manual review

Recommendations

contract DecentralizedStableCoin is ERC20Burnable, Ownable {
/*
In future versions of OpenZeppelin contracts package, Ownable must be declared with an address of the contract owner as a parameter.
For example:
constructor() ERC20("DecentralizedStableCoin", "DSC") Ownable(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) {}
Related code changes can be viewed in this commit:
https://github.com/OpenZeppelin/openzeppelin-contracts/commit/13d5e0466a9855e9305119ed383e54fc913fdc60
*/
constructor() ERC20("DecentralizedStableCoin", "DSC") {}
function burn(uint256 _amount) public override onlyOwner {
super.burn(_amount);
}
function mint(address _to, uint256 _amount) external onlyOwner returns (bool) {
_mint(_to, _amount);
return true;
}
}

Support

FAQs

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