code-423n4 / 2021-12-amun-findings

0 stars 0 forks source link

Internal call is more efficient than external call #227

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-12-amun/blob/cf890dedf2e43ec787e8e5df65726316fda134a1/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L148-L148

require(!this.getLock(), "POOL_LOCKED");

https://github.com/code-423n4/2021-12-amun/blob/cf890dedf2e43ec787e8e5df65726316fda134a1/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L282-L286

function getLock() external view override returns (bool) {
    LibBasketStorage.BasketStorage storage bs =
        LibBasketStorage.basketStorage();
    return bs.lockBlock == 0 || bs.lockBlock >= block.number;
}

getLock() is being defined and used as an external function (this.getLock()), which costs more gas than using it as an internal function.

We suggest change it to require(!getLock(), "POOL_LOCKED"); for gas saving.