code-423n4 / 2022-01-sherlock-findings

0 stars 0 forks source link

cheaper to use `!active()` #251

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Fitraldys

Vulnerability details

Impact

in line https://github.com/code-423n4/2022-01-sherlock/blob/main/contracts/SherBuy.sol#L126 is cheaper ~20 gas to use !active() than using active() == false.

Proof of Concept

https://github.com/code-423n4/2022-01-sherlock/blob/main/contracts/SherBuy.sol#L126

contract holmes {

    error InvalidState();

    function active() public view returns (bool) {
    return true;
  }

    function coba() public {

       if (active() == false) revert InvalidState();
    }
}

to :

contract holmes {

    error InvalidState();

    function active() public view returns (bool) {
    return true;
  }

    function coba() public {

       if (!active()) revert InvalidState();
    }
}
jack-the-pug commented 2 years ago

Dup #132