sherlock-audit / 2023-05-ironbank-judging

2 stars 2 forks source link

ni8mare - `accrueInterest` method is not called before updating `reserveFactor` of a market #492

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

ni8mare

medium

accrueInterest method is not called before updating reserveFactor of a market

Summary

In the softDelistMarket method, the accrueInterest method is not called before updating the reserveFactor of a market's configuration.

Vulnerability Detail

In the function, adjustMarketReserveFactor we see that the function accrueInterest is called before the reserve factor is updated to a new value. This is done to conclude the current accumulated interest with the original reserve factor. This logic is also seen in changeMarketInterestRateModel.

But, in the softDelistMarket method we do not call the accrueInterest method before updating the reserveFactor to MAX_RESERVE_FACTOR.

Impact

If accrueInterest is not called, the accumulated interest with the previous reserve factor is not taken into account.

Code Snippet

In softDelistMarket:

    function softDelistMarket(address market) external onlyOwner {
        DataTypes.MarketConfig memory config = getMarketConfiguration(market);
        require(config.isListed, "not listed");

        if (!config.isSupplyPaused()) {
            config.setSupplyPaused(true);
            emit MarketPausedSet(market, "supply", true);
        }
        if (!config.isBorrowPaused()) {
            config.setBorrowPaused(true);
            emit MarketPausedSet(market, "borrow", true);
        }
        if (config.reserveFactor != MAX_RESERVE_FACTOR) {
            config.reserveFactor = MAX_RESERVE_FACTOR;
            emit MarketReserveFactorSet(market, MAX_RESERVE_FACTOR);
        }
        ironBank.setMarketConfiguration(market, config);
    }

Tool used

Manual Review

Recommendation

Please update the code so that the accrueInterest method is called before updating the reserveFactor variable.