Skip to content
Business logic Audit finding Advanced

Withdrawing just before a bad debt event can increase losses for remaining liquidity providers

Liquidity providers in Panoptic can withdraw their shares immediately before a bad debt event is socialised, avoiding their share of the loss. The remaining liquidity providers then absorb the full deficit, so losses are distributed unfairly.

Valves Follow

Originally disclosed on Code4rena

Submitted by Valves

CollateralTracker.sol L1262

Summary

When large positions are heading toward bad debt, liquidity providers can withdraw just before loss socialization. This timing advantage lets exiting LPs avoid the loss, concentrating it on the remaining LPs and resulting in unfair loss distribution by front-running the bad debt event.

Impact

A malicious LP never incurs losses from bad debt socialization, while the remaining LPs bear the cost instead.

Finding description

In Panoptic’s liquidation flows, pool deficits are socialized when the liquidatee does not have enough funds (shares and assets) to cover the liquidator bonus. If an LP exits immediately before socialization, their shares are not impacted by the imminent deficit, shifting the entire loss burden onto LPs who remain.

Original code block has been omitted. View complete submission.

When a position becomes liquidatable and has accumulated bad debt and the liquidatee does not have enough funds to transfer to the liquidator, new shares are minted to the liquidator to cover the bonus for the liquidation. This way we see a increase of the totalShares meanwhile the totalAssets go down because it is also transferred out of the protocol to the liquidator. The ratio between shares and assets change which can be front-run by LPs to avoid the bad debt allocation event.

Recommended mitigation steps

Implement a mechanism to fairly distribute losses from bad debt among all liquidity providers, possibly by locking withdrawals for a short period or pro-rating losses based on withdrawal timing.

Proof of Concept

Add the helper and the test inside CollateralTracker.t.sol:

View detailed Proof of Concept

Output:

The withdrawal amount available to Charlie immediately before liquidation is greater than the amount available immediately after liquidation, demonstrating that exiting LPs avoid the deficit while remaining LPs bear its full impact.

  totalAssets before the liquidation:  1100000000000000000001
  totalShares before the liquidation:  1089910000000000000001000000
  Charlie can front run the bad debt and can withdraw:  1009257645126661834463
  Charlie missed the front run opportunity and now can withdraw 989327316140468395517
  totalAssets after the liquidation:   1000000000000000000002
  totalShares after the liquidation:   1010787818839539913079152234

Panoptic disputed


The original report as published on Code4rena, by Valves. 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 share-to-asset ratio is updated only at the moment of loss socialisation, so a withdrawal made just before that update escapes the loss entirely.

Impact

An exiting LP avoids the bad debt loss entirely, while the remaining LPs bear the full cost; the project disputed the finding.

What the attacker needed

Liquidity provider position in the pool; a position heading toward bad debt

The fix

Losses from bad debt should be distributed fairly among all liquidity providers, for example by locking withdrawals briefly or pro-rating losses by withdrawal timing.

How it was found

  1. Wait until a position is liquidatable and has accumulated bad debt.
  2. Withdraw liquidity immediately before the liquidation socialises the deficit.
  3. Observe that the withdrawal amount before liquidation is larger than after it.

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.

A liquidity pool holds money from many people. When a trader cannot repay and the pool loses money, that loss is normally shared among everyone in the pool. This report shows that someone can take their money out just before the loss is shared, so the people who stay lose more than they should.

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 Valves

View all

1 more disclosed report, best first.

More from Panoptic: Next Core

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.