Skip to content
Business logic Audit finding Intermediate

Risk of mass liquidation after pool/asset pause and unpause, due to borrow interest compounding implementation

The borrow interest index continues to compound while a pool or asset is paused, even though users cannot repay during that time. When unpaused, many accounts could be immediately liquidated because their debt has grown without any chance to repay.

oakcobalt Follow

Originally disclosed on Code4rena

Submitted by oakcobalt

Current pausing features allow a pool to be globally paused (all assets borrow, repay, liquidation pausing) and asset pausing (specific asset borrow, repay, liquidation pausing). See validatePoolBasic() and validateAssetBasic() which are checked in borrow, repay, and will revert if the pool or the asset is paused.

The problem is the borrow interest compounding implementation (InterestLogic::_updateBorrowIndex) will not factor in the duration of pausing when a user cannot repay a loan.

//src/libraries/logic/InterestLogic.sol
  function _updateBorrowIndex(DataTypes.AssetData storage assetData, DataTypes.GroupData storage groupData) internal {
    // borrow index only gets updated if there is any variable debt.
    // groupData.borrowRate != 0 is not a correct validation,
    // because a positive base variable rate can be stored on
    // groupData.borrowRate, but the index should not increase
    if ((groupData.totalScaledCrossBorrow != 0) || (groupData.totalScaledIsolateBorrow != 0)) {
        //@audit Case: asset paused and unpaused, assetData.lastUpdateTimestamp will be a timestamp before paused, interests compound during pausing
|>      uint256 cumulatedBorrowInterest = MathUtils.calculateCompoundedInterest(
        groupData.borrowRate,
        assetData.lastUpdateTimestamp
      );
      uint256 nextBorrowIndex = cumulatedBorrowInterest.rayMul(groupData.borrowIndex);
      groupData.borrowIndex = nextBorrowIndex.toUint128();
    }
  }

https://github.com/code-423n4/2024-07-benddao/blob/117ef61967d4b318fc65170061c9577e674fffa1/src/libraries/logic/InterestLogic.sol#L281

Interests continuously compound with no repayment allowed. When unpaused, many accounts are vulnerable to immediate liquidation out of users’ control.

Recommended Mitigation Steps

Consider storing pause/unpause timestamp to allow skipping borrow interests compounding for the duration of the pause.

thorseldon (BendDAO) acknowledged and commented:

It’s our service design. Pause & unpause should be only used for emergency case, the accrued interest should be very small.

We suggest adjust the severity level to Informative.

0xTheC0der (judge) commented:

Although pause durations are intended to be small, they can be arbitrarily long and put users at risk on unpausing due to compounding in the meantime. This could be mitigated on contract level; therefore, leaning towards maintaining Medium severity.


The original report as published on Code4rena, by oakcobalt. 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 borrow interest index is updated using the last update timestamp without accounting for the pause duration, so interest compounds during the pause.

Impact

Users could be liquidated immediately after unpausing because their debt has grown during the pause, although the protocol team says pauses are meant to be short and the accrued interest should be small.

What the attacker needed

Pool or asset is paused; users cannot repay during pause; pause lasts long enough for interest to grow

The fix

The borrow interest calculation should skip compounding for the duration of the pause, for example by storing pause and unpause timestamps.

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.

In a lending system, interest on a loan keeps growing over time. If the system is paused for an emergency, users cannot repay their loans, but the interest still grows as if nothing happened. When the pause is lifted, some users may suddenly owe more than their collateral is worth and get liquidated (their collateral is sold off) without having had a chance to act.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by oakcobalt

View all

50 more disclosed reports, best first.

More from BendDAO Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.