code-423n4 / 2022-06-badger-findings

0 stars 0 forks source link

Gas Optimizations #83

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Require instead of &&

IMPACT

Require statements including conditions with the && operator can be broken down in multiple require statements to save gas.

PROOF OF CONCEPT

Instances include:

MyStrategy.sol(line 182-187)

    function _withdrawAll() internal override {
        require(
            balanceOfPool() == 0 && LOCKER.balanceOf(address(this)) == 0,
            "You have to wait for unlock or have to manually rebalance out of it"
        );

MITIGATION

Breakdown each condition in a separate require statement (though require statements should be replaced with custom errors

Mitigated Code

    function _withdrawAll() internal override {
        require(balanceOfPool() == 0); 
        require(LOCKER.balanceOf(address(this) == 0,
            Error.WAIT)

            // Use CUSTOM ERROR instead "You have to wait for unlock or have to manually rebalance out of it"
        );
JeeberC4 commented 2 years ago

Warden submitted multiple Gas Optimizations. Will not be judged.