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

Incorrect checks

Summary

Unnecessary checks that are redundant

Vulnerability Details

DecentralizedStableCoin.sol lines 48 and 61 have an if statement that checks if (_amount <= 0)
However the above is not useful as uint256 values will never be less than zero so there is no way a user or functions will allow inputs less than zero

Impact

Gas Savings: By using if (_amount <= 0) which is irrelevant vs if(_amount ==0) an additional opcodes is used since in the <= case complier does not have a LESS THAN OR EQUAL TO OPCODE or GREATER THAN OR EQUAL TO OPCODES so relies on combining LT & EQ or GT & EQ in cases where less than or equal or greater than or equal are needed. Wheres if(_amount ==0) will use single OPCODE EQ

Tools Used

Manual Analysis

Recommendations

  1. DecentralizedStableCoin.sol line 48
    if (_amount <= 0) {
    revert DecentralizedStableCoin__MustBeMoreThanZero();
    }

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

  1. DecentralizedStableCoin.sol line 61
    if (_amount <= 0) {
    revert DecentralizedStableCoin__MustBeMoreThanZero();
    }
    Rewrite to
    if (_amount == 0) {
    revert DecentralizedStableCoin__MustBeMoreThanZero();
    }
    the above saves from using 2 opcodes to using a single opcode

Support

FAQs

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