Skip to content
Business logic Audit finding Advanced

Any borrower with bad debt can be liquidated multiple times to lock funds in the lending pair

Leftover shares in liquidateClean are only subtracted from pair totals, not from the borrower's borrowed shares, so a borrower with bad debt can be liquidated repeatedly with zero shares to write off debt and corrupt pair accounting. This can lock the pool, prevent borrowers from repaying, and severely reduce lenders' withdrawals.

panprog Follow

Originally disclosed on Code4rena

Submitted by panprog, also found by 0xA5DF and Lambda

Leftover shares in liquidateClean are only subtracted from pair totals, but not from user’s borrowed shares. This means that after liquidateClean, borrower’s shares will be greater than 0 (leftover shares after liquidations), but the user is still insolvent and can be liquidated again and again (with _sharesToLiquidate set to 0). Each subsequent liquidation will write off the bad debt (reduce pair totals by borrower leftover shares/amounts), but doesn’t take anything from liquidator nor borrower (since _sharesToLiquidate == 0).

This messes up the whole pair accounting, with total asset amounts reducing and total borrow amounts and shares reducing. This will make it impossible for borrowers to repay debt (or be liquidated), because borrow totals will underflow, and lenders amount to withdraw will reduce a lot (they will share non-existant huge bad debt).

Reducing pair totals scenario:

  1. Alice borrows 1000 FRAX (1000 shares) against 1.5 ETH collateral (1 ETH = 1000, Max LTV = 75%)
  2. ETH drops to 500 very quickly with liquidators being unable to liquidate Alice due to network congestion
  3. At ETH = 500, Alice collateral is worth 750 against 1000 FRAX debt, making Alice insolvent and in a bad debt
  4. Liquidator calls liquidateClean for 800 shares, which cleans up all available collateral of 1.5 ETH.
  5. At this point Alice has 200 shares debt with 0 collateral
  6. Liquidator repeatedly calls liquidateClean with 0 shares to liquidate. Each call pair totals are reduced by 200 shares (and total borrow amount by a corresponding amount).
  7. When pair totals reach close to 0, the pool is effectively locked. Borrowers can’t repay, lenders can withdraw severly reduced amounts.

Proof of Concept

Copy this to src/test/e2e/LiquidationBugTest.sol

https://gist.github.com/panprog/cbdc1658d63c30c9fe94127a4b4b7e72

Recommended Mitigation Steps

After the line

https://github.com/code-423n4/2022-08-frax/blob/c4189a3a98b38c8c962c5ea72f1a322fbc2ae45f/src/contracts/FraxlendPairCore.sol#L1012

add

    _sharesToLiquidate += _sharesToAdjust;

amirnader-ghazvini (Frax) marked as duplicate and commented:

Duplicate of #112

gititGoro (judge) commented:

Setting to original in set.

DrakeEvans (Frax) confirmed


The original report as published on Code4rena, by panprog. 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

Impact

The pool accounting is corrupted, making it impossible for borrowers to repay or be liquidated normally, and lenders can withdraw only severely reduced amounts.

What the attacker needed

A borrower with bad debt; a liquidator calls liquidateClean; network congestion prevents timely liquidation

The fix

The liquidation logic should add the leftover shares to the shares to liquidate so the borrower's debt is properly reduced.

How it was found

  1. Alice borrows 1000 FRAX against 1.5 ETH collateral at 75% max LTV.
  2. ETH price drops to 500, making Alice insolvent with bad debt.
  3. A liquidator calls liquidateClean for 800 shares, clearing all collateral.
  4. Alice still has 200 shares of debt with zero collateral.
  5. The liquidator repeatedly calls liquidateClean with 0 shares, each time reducing pair totals by 200 shares.
  6. Pair totals approach zero, locking the pool and preventing repayment or normal withdrawal.

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 pool, when a borrower's collateral is worth less than their debt, a liquidator can step in to clear the debt. This report found that after one such cleanup, the borrower still appears to owe the leftover amount, so a liquidator can call the cleanup again and again with zero shares. Each call wrongly reduces the pool's totals without taking any real money, eventually breaking the pool so nobody can repay or withdraw properly.

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 panprog

View all

66 more disclosed reports, best first.

More from Frax Ether Liquid Staking contest

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.