Cyfrin / foundry-defi-stablecoin-cu

250 stars 117 forks source link

Sanity checks in the burn and mint functions #6

Closed noushkia closed 1 year ago

noushkia commented 1 year ago

You implemented some checks in the burn and mint functions.

if (_amount <= 0) {
    revert DecentralizedStableCoin__AmountMustBeMoreThanZero();
}
if (balance < _amount) {
    revert DecentralizedStableCoin__BurnAmountExceedsBalance();
}

In the burn function, you check whether the amount is negative or not. Isn't this checked via the type of amount argument i.e. uint256?

How about the DecentralizedStableCoin__BurnAmountExceedsBalance check? This is checked inside the ERC20 implementation as well.

    uint256 accountBalance = _balances[account];
    require(accountBalance >= amount, "ERC20: burn amount exceeds balance");

Are there any specific reasons for these extra validations?

Thank you for the great content!

panicd9 commented 1 year ago

What is answer to this? Arent those checks redundant?