Skip to content
Business logic Audit finding Intermediate

liquidate() doesn’t mark off bad debt, leading to a ‘last lender to withdraw loses’ scenario

The liquidate() function does not mark off bad debt, so totalAssets.amount remains higher than the actual solvent assets. Lenders who redeem early can withdraw more than their fair share, leaving later lenders to absorb the loss.

0xA5DF Follow

Originally disclosed on Code4rena

Submitted by 0xA5DF, also found by cccz and Lambda

When there’s bad debt which wasn’t marked off yet, the totalAssets.amount is higher than the actual (solvent) amount the pair has, meaning that lenders who redeem their tokens earlier will get more in return, at the expense of lenders who leave later. Therefore bad debt should be marked off as soon as possible, the later it’s done the more interest it accumulates and the higher the chances are that some of the lenders will notice and redeem their shares before the bad debt is subtracted from the total assets amount.

Having the option to liquidate via the liquidate() function (which doesn’t mark off bad debt) can lead to users using that function and leaving bad debt alongside zero collateral or near-zero collateral (giving no motivation for other users to liquidate the rest).

Marking off the remaining of the bad debt via liquidateClean() with 0 shares might be possible (not always, some tokens don’t allow 0 transfers), however there’s no motivation for outside users to do so. And as for the lenders - redeeming their tokens before the bad debt is subtracted from the total amount might be more profitable than staying and marking off the bad debt.

Impact

Some lenders might be able to dodge the loss of the bad debt (+ interest), while the last one(s) will have to absorb the lost of the lenders who left too.

Proof of Concept

Consider the following scenario:

  • A pair has 10 lenders with 1K$ from each one (10K total)
  • Borrower borrowed that 10K
  • The collateral price went down and now it’s worth only 7K
  • A liquidator notices that and liquidates it via liquidate()
  • The totalAssets.amount is 10K + interest, but the total asset amount is actually less than 7K (subtracting liquidator fees)
  • 6 lenders notice that and redeem their shares, getting back their money + interest
  • The 7th lender to redeem will only be able to get back part of his money
  • The remaining 3 lenders will loose all of their money

Recommended Mitigation Steps

Mark off bad debt when remaining collateral reaches zero or near-zero value.

(if only liquidateClean() was available then there would be a motivation to not leave near-zero collateral, but as long as this isn’t the case consider marking off also in case of near-zero collateral left).

DrakeEvans (Frax) confirmed

gititGoro (judge) commented:

Setting to original in set. Severity will be maintained as the wardens couldn’t know that only one liquidate function would be included in the final release.


The original report as published on Code4rena, by 0xA5DF. 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 liquidate() function does not reduce totalAssets.amount to reflect bad debt, so the pool's accounting overstates its assets.

Impact

Some lenders could avoid the loss of bad debt and interest, while the last lenders have to absorb the losses of those who left.

What the attacker needed

A lending pair with multiple lenders; A borrower defaults leaving bad debt; Liquidate() is called without marking off bad debt

The fix

Bad debt should be marked off when remaining collateral reaches zero or near-zero value.

How it was found

  1. A pair has 10 lenders each contributing 1K, total 10K.
  2. A borrower borrows the 10K.
  3. Collateral price drops so it is worth only 7K.
  4. A liquidator liquidates via liquidate(), which does not mark off bad debt.
  5. totalAssets.amount remains 10K plus interest, but actual assets are less than 7K.
  6. Six lenders redeem early and get their money plus interest; later lenders lose part or all of their money.

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, people deposit money and borrowers take loans. If a borrower defaults, the pool has less money than it claims. If the loss is not recorded immediately, early withdrawers get paid in full while those who wait lose out.

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

View all

35 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.