Skip to content
Business logic Audit finding Intermediate

Some bad debt will not be cleared when it should which will cause accrual of bad debt decreasing the protocol's solvency

The clearBadDebt function checks if the earnings accumulator is sufficient to cover bad debt before adding unassigned earnings, so it may fail to clear debt even when the accumulator would be sufficient after the addition. This causes bad debt to accrue, reducing the protocol's solvency.

0x73696d616f Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/74

The protocol has acknowledged this issue.

Found by

0x73696d616f

Summary

In Market::clearBadDebt(), it only clears bad debt if the earningsAccumulator is bigger than the bad debt to clear, but the fixed pool in question may have unassigned earnings which would be added to the earnings accumulator. Thus, the accumulator would have funds to handle the bad debt, but due to checking if it is enough before taking into account its increase, it will not clear the bad debt and will decrease protocol solvency.

Root Cause

In Market:641, it first checks if accumulator >= badDebt and then in Market:653 it increases the accumulator. This should be done in the opposite order as the accumulator may actual be big enough with the added unassigned earnings to clear the bad debt.

Internal pre-conditions

  1. Fixed pool has unassigned earnings.
  2. User is liquidated.
  3. Accumulator is bigger than the bad debt if it takes into account unassigned earnings.

External pre-conditions

None.

Attack Path

  1. User borrows maturities but lets them expire and accrues more debt than collateral.
  2. User is liquidated, but the accumulator is not enough to cover the bad debt without the unassigned earnings increase, so bad debt keeps accruing.

Impact

Bad debt accrual which harms protocol users as it increases the risk of insolvency.

PoC

The following code snippet can be verified to confirm the issue:

Solidity
function clearBadDebt(address borrower) external {
  {
    {
      ...
      if (accumulator >= badDebt) {
        ...
        if (fixedPools[maturity].borrowed == position.principal) {
          earningsAccumulator += fixedPools[maturity].unassignedEarnings;
          fixedPools[maturity].unassignedEarnings = 0;
        }
        ...
      }
    }
  }
  ...
}

Mitigation

Increase the earnings accumulator first and only then compare it against the bad debt.

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

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

Impact

Bad debt accrues, which harms protocol users by increasing the risk of insolvency.

What the attacker needed

Fixed pool has unassigned earnings; User is liquidated; Accumulator would be sufficient with unassigned earnings

The fix

The earnings accumulator should be increased first and only then compared against the bad debt.

How it was found

  1. User borrows maturities but lets them expire and accrues more debt than collateral.
  2. User is liquidated, but the accumulator is not enough to cover the bad debt without the unassigned earnings increase, so bad debt keeps accruing.

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 protocol, bad debt is money that borrowers cannot repay. The protocol tries to cover this bad debt using a pool of collected earnings. The bug is that the protocol checks if the pool has enough money before adding some extra earnings that are owed to it, so it sometimes thinks it doesn't have enough when it actually does. This leaves the bad debt unpaid, which can make the protocol less stable.

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 0x73696d616f

View all

172 more disclosed reports, best first.

More from Exactly Protocol Update - Staking Contract

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.