Skip to content
Business logic Audit finding Advanced

Liquidating maturies with unassigned earnings will not take into account floating assets increase leading to loss of funds

The liquidation calculation in the Exactly protocol ignores floating assets that accrue from unassigned earnings when a maturity is repaid. As a result, a liquidator may seize less collateral than entitled, leaving funds with the borrower or preventing bad debt clearance.

0x73696d616f Follow

Originally disclosed on Sherlock

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

The protocol has acknowledged this issue.

Found by

0x73696d616f

Summary

Market::liquidate() calculates the amount to liquidate in Auditor::checkLiquidation(), which does not take into account floating assets accrual due to unassigned earnings in Market::noTransferRepayAtMaturity(). Thus, it will underestimate the collateral a certain account has and liquidate less than it should, either giving these funds to the liquidatee or in case the debt is bigger than the collateral, leave this extra untracked collateral in the account which will not enable clearBadDebt() to work.

Root Cause

In Auditor::checkLiquidation(), the collateral is computed just by looking at the shares of an account, without taking into account maturities accruing unassigned earnings. In Market::noTransferRepayAtMaturity(), maturities are repaid and floating assets are increased due to backup earnings. Thus, when it seizes the collateral, it will seize at most the collateral without taking into account the new amount due to the floating assets sudden increase, as Auditor::checkLiquidation() is called prior the floating assets increase.

Internal pre-conditions

  1. Pool has unassigned earnings and user is liquidated.

External pre-conditions

None.

Attack Path

  1. Users borrow at maturity and generate unassigned earnings.
  2. One of these users is liquidated but the collateral preview is incorrect and the liquidation is incomplete and the funds are lost.

Impact

If the user has less debt than collateral but the debt would require most of its collateral, it would not be possible to seize it all. If the user has more debt than collateral a portion of the collateral will be leftover which will not allow bad debt to be cleared right away via clearBadDebt() and stays accruing.

PoC

Add the following test to Market.t.sol, confirming that the user should have all its collateral seized given that debt > collateral but some collateral remains due to the increase in floating assets.

Solidity
function test_POC_FloatingAssetsIncrease() external {
  uint256 maxVal = type(uint256).max;

  market.deposit(10000 ether, address(this));

  vm.startPrank(BOB);
  market.deposit(100 ether, BOB);
  market.borrowAtMaturity(4 weeks, 60e18, maxVal, BOB, BOB);
  vm.stopPrank();

  skip(10 weeks);

  (uint256 coll, uint256 debt) = market.accountSnapshot(BOB);
  assertEq(coll, 100e18);
  assertEq(debt, 111.246904109483404820e18);

  vm.startPrank(ALICE);
  market.liquidate(BOB, 100_000 ether, market);
  vm.stopPrank();

  (coll, debt) = market.accountSnapshot(BOB);
  assertEq(coll, 4.557168045571680e15);
  assertEq(debt, 20.337813200392495730e18);
}

Mitigation

Auditor::checkLiquidation() should compute the increase in collateral by previewing the floating assets increase due to accrued unassigned earnings in a fixed pool or instead of increasing floating assets these earnings could increase the earnings accumulator.

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

The liquidator may seize less collateral than allowed, leaving funds with the borrower or preventing bad debt from being cleared immediately, and the leftover collateral continues to accrue.

What the attacker needed

Pool has unassigned earnings; User is liquidated

The fix

The liquidation check should preview the floating assets increase from accrued unassigned earnings, or those earnings should increase the earnings accumulator instead of floating assets.

How it was found

  1. Users borrow at maturity, generating unassigned earnings.
  2. One of these users is liquidated, but the collateral preview is incorrect.
  3. The liquidation is incomplete and funds are lost.

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.

When a borrower is liquidated, the protocol calculates how much collateral to take based on the borrower's current collateral. However, if the pool has unassigned earnings, repaying a maturity increases the pool's floating assets, which should also increase the borrower's collateral value. The calculation happens before this increase, so the liquidator takes too little collateral, leaving value behind.

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.