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

Input checks are not necessary or can be improved

Summary

Some input checks are not necessary or they can be improved.

Vulnerability Details

Some input checks are not necessary or they can be improved. More details are provided in the "Recommendations" section.

Impact

Gas can be saved and code can be more clear by improving this. vice versa.

Tools Used

Manual review

Recommendations

Improve the input checks as follows:

constructor() ERC20("DecentralizedStableCoin", "DSC") {}
function burn(uint256 _amount) public override onlyOwner {
- uint256 balance = balanceOf(msg.sender); // @audit because ERC20Burnable will check this, so this is not necessary. @audit gas - put his after the `if` check to save gas.
- if (_amount <= 0) { // @audit this is not necessary, because uint is above zero by default. change this to `== 0`.
+ if (_amount == 0) {
revert DecentralizedStableCoin__MustBeMoreThanZero();
}
- if (balance < _amount) { // @audit this is not necessary, because ERC20Burnable will check this.
- revert DecentralizedStableCoin__BurnAmountExceedsBalance();
- }
super.burn(_amount);
}
function mint(address _to, uint256 _amount) external onlyOwner returns (bool) {
- if (_to == address(0)) { // @audit this is not necessary, because ERC20 will check this.
- revert DecentralizedStableCoin__NotZeroAddress();
- }
- if (_amount <= 0) {
+ if (_amount == 0) {
revert DecentralizedStableCoin__MustBeMoreThanZero();
}
_mint(_to, _amount);
return true;
}
}

Support

FAQs

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