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

== 0 better than <= 0 for unsigned integer comparisons

Summary

Use of == 0 is considered better than <= 0 for unsigned integer comparisons.

Vulnerability Details

The use of == 0 is better than <= 0 for unsigned integer comparison because if you're checking < 0, the comparison will be always false because unsigned integers will always be non-negative. Instances :

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DecentralizedStableCoin.sol#L48

    if (_amount <= 0) {
        revert DecentralizedStableCoin__MustBeMoreThanZero();
    }

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DecentralizedStableCoin.sol#L61

    if (_amount <= 0) {
        revert DecentralizedStableCoin__MustBeMoreThanZero();
    }

Impact

Improves readability and avoids any confusion.

Tools Used

Manual review

Recommendations

Use == 0 instead of <= 0.

Support

FAQs

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