code-423n4 / 2021-11-streaming-findings

0 stars 0 forks source link

Remove unnecessary function can make the code simpler and save some gas #265

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L253-L261

    function lockInternal() internal {
        require(unlocked == 1, "re");
        unlocked = 2;
    }
    modifier lock {
        lockInternal();
        _;
        unlocked = 1;
    }

lockInternal() is unnecessary as it's used only once. Therefore they can be inlined in lock to make the code simpler and save gas.

Recommendation

Change to:

    modifier lock {
        require(unlocked == 1, "re");
        unlocked = 2;
        _;
        unlocked = 1;
    }