Cyfrin / 2023-07-foundry-defi-stablecoin

37 stars 32 forks source link

Can save gas we by changing less or equal to just equal #1132

Open codehawks-bot opened 1 year ago

codehawks-bot commented 1 year ago

Can save gas we by changing less or equal to just equal

Severity

Gas Optimization / Informational

Relevant GitHub Links

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

Summary

Can save gas we change less or equal to just equal.

Vulnerability Details

A <= 0 check is done on a uint, which can not be negative. We can save gas if we just do an equality check

Impact

== 0 costs less gas than <= 0

Tools Used

Manual review

Recommendations

Change this:

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

To this:

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