Skip to content
DoS Audit finding Intermediate

accrueInterest is expected to revert when the rate is higher than the maximum allowed rate, which is possible since the utilization can be more than 1

The interest accrual function reverts when the calculated borrow rate exceeds a maximum, and this can happen because the utilisation rate can exceed 100% when reserves exceed cash. An attacker could cause the protocol's deposit, withdraw, borrow, and repay functions to fail, locking user funds.

0xWaitress Follow with 0xWaitress, ast3ros and 1 other

Originally disclosed on Code4rena

Submitted by 0xWaitress, also found by 0xWaitress, ast3ros, catellatech (1, 2), Nyx (1, 2), kodyvim, and nadin (1, 2)

accrueInterest is expected to revert when the rate is higher than the maximum allowed rate, which is possible since the utilization can be more than 1

accrueInterest is an essential function to keep updated of the global mToken interest payment from the borrower to the depositor. The function is called anytime there is a deposit/liquidate/borrow/repay/withdraw.

The function is set to revert when the borrowRateMantissa is bigger than the borrowRateMaxMantissa.

require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high");.

With proper configuration, this check should be fine since the real borrowRate should be calibrated to be within the maxRate. However, since the utilization could actually be bigger than 1 (when reserve is bigger than cash [issue-37] , the actual rate could be bigger than the expected unreachable max rate:

Example: Base: 1% multiplierPerTimestamp: 5% APR jumpMultiplier: 50% APR klink: 50% We could reasonably assume the max APR is 1% + 5% * 0.5 + 50% * (1-0.5) = 28.5%

However when reserve is more than cash it would cause the utilization be bigger than 1, let’say utilization is 101%: such that the actual rate would be:

1% + 5% * 0.5 + 50% * (1.01 - 0.5) = 29%

This would cause the accurueInterest to revert.

Impact: all deposit/withdraw/borrow/repay function would fail and severe brick the operation of the protocol and lock user funds. Interest accrual cannot work which impact both borrower for timely exit as well as deposit to collect their interest.

    function accrueInterest() virtual override public returns (uint) {
        /* Remember the initial block timestamp */
        uint currentBlockTimestamp = getBlockTimestamp();
        uint accrualBlockTimestampPrior = accrualBlockTimestamp;

        /* Short-circuit accumulating 0 interest */
        if (accrualBlockTimestampPrior == currentBlockTimestamp) {
            return uint(Error.NO_ERROR);
        }

        /* Read the previous values out of storage */
        uint cashPrior = getCashPrior();
        uint borrowsPrior = totalBorrows;
        uint reservesPrior = totalReserves;
        uint borrowIndexPrior = borrowIndex;

        /* Calculate the current borrow interest rate */
        uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior,
        borrowsPrior, reservesPrior);
        require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is
        absurdly high");

https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MToken.sol#L403

Utilization can be above 100% when reserve is more than cash

Note: per judge request, this information from duplicate issue 37 has been appended to M-16 for the final report.

Utilization is calculated as borrow / (cash + borrow - reserve). and the utilization would determine the interest rate in this classic jump/klink model.

Consider:

  1. both depositor and borrowers come in. Reserves accumulates as interest revenue paid by borrowers accrues.
  2. depositor withdraws. The protocol has only borrowers and the reserve.

When reserves becomes more than cash, the formula for utilizationRate would give a utilization rate above 1. This is different from the code comment which said to @return The utilization rate as a mantissa between [0, 1e18]

     * @return The utilization rate as a mantissa between [0, 1e18]
    function utilizationRate(uint cash, uint borrows, uint reserves) public pure returns (uint) {
        // Utilization rate is 0 when there are no borrows
        if (borrows == 0) {
            return 0;
        }

        return borrows.mul(1e18).div(cash.add(borrows).sub(reserves));
    }

https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/IRModels/JumpRateModel.sol#L66-L75

Recommended Mitigation Steps

  • Consider to cap the real-time borrowRate as the borrowRateMaxMantissa instead of reverting.
  • Consider put a cap of 1e18 to the final output.

ElliotFriedman (Moonwell) disputed and commented:

Reserves can be pulled back to admin address by admin, so this is a non issue.


The original report as published on Code4rena, by 0xWaitress. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the utilisation rate formula does not cap its output at 100%, so when reserves exceed cash the computed borrow rate can exceed the maximum and trigger a revert.

Impact

All deposit, withdraw, borrow, and repay functions would fail, bricking the protocol and locking user funds; the project disputed this, saying reserves can be pulled back by the admin.

What the attacker needed

Reserves exceed cash in the pool; borrowers remain after depositors withdraw

The fix

The report recommends capping the real-time borrow rate at the maximum instead of reverting, and capping the utilisation output at 1e18.

How it was found

  1. Depositors and borrowers interact so that reserves accumulate from interest.
  2. Depositors withdraw until only borrowers and reserves remain.
  3. Reserves become greater than cash, making utilisation exceed 1.
  4. The calculated borrow rate exceeds the maximum, so accrueInterest reverts.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A lending protocol calculates interest based on how much of the pool is borrowed. If the pool's reserves (interest set aside for the protocol) grow larger than the cash available, the formula can produce a utilisation above 100%, making the interest rate exceed a safety limit and causing the interest update to fail. That failure blocks all core actions like depositing or repaying.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xWaitress

View all

3 more disclosed reports, best first.

More from Moonwell

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.