Skip to content
Business logic Audit finding Intermediate

Insurance slippage reimbursement can be used to steal insurance fund

The liquidation contract's claimReceipt function does not check for duplicate orders, allowing a liquidator to submit the same bad trade multiple times and receive excessive slippage reimbursement from the insurance fund. An attacker can drain the insurance fund by repeatedly exploiting this.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The Liquidation contract allows the liquidator to submit “bad” trade orders and the insurance reimburses them from the insurance fund, see Liquidation.claimReceipt. The function can be called with an orders array, which does not check for duplicate orders. An attacker can abuse this to make a profit by liquidating themselves, making a small bad trade and repeatedly submitting this bad trade for slippage reimbursement.

Example:

  • Attacker uses two accounts, one as the liquidator and one as the liquidatee.

  • They run some high-leverage trades such that the liquidatee gets liquidated with the next price update. (If not cash out and make a profit this way through trading, and try again.)

  • Liquidator liquidates liquidatee

  • They now do two trades:

    • One “good” trade at the market price that fills 99% of the liquidation amount. The slippage protection should not kick in for this trade
    • One “bad” trade at a horrible market price that fills only 1% of the liquidation amount. This way the slippage protection kicks in for this trade
  • The liquidator now calls claimReceipt(orders) where orders is an array that contains many duplicates of the “bad” trade, for example 100 times. The calcUnitsSold function will return unitsSold = receipt.amountLiquidated and a bad avgPrice. They are now reimbursed the price difference on the full liquidation amount (instead of only on 1% of it) making an overall profit

This can be repeated until the insurance fund is drained.

The attacker has an incentive to do this attack as it’s profitable and the insurance fund will be completely drained.

Recommend disallowing duplicate orders in the orders argument of claimReceipt. This should make the attack at least unprofitable, but it could still be a griefing attack. A quick way to ensure that orders does not contain duplicates is by having liquidators submit the orders in a sorted way (by order ID) and then checking in the calcUnitsSold for loop that the current order ID is strictly greater than the previous one.

BenjaminPatch (Tracer) confirmed:

Valid issue. The recommended mitigation step would also work.

The original report as published on Code4rena, by cmichel. 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 attacker can drain the insurance fund completely, as the attack is profitable and can be repeated.

What the attacker needed

Two accounts: liquidator and liquidatee; ability to perform high-leverage trades; liquidatee gets liquidated

The fix

Disallow duplicate orders in the orders argument of claimReceipt, for example by requiring orders to be sorted by ID and checking strict increase.

How it was found

  1. Attacker uses two accounts, one as the liquidator and one as the liquidatee.
  2. They run some high-leverage trades such that the liquidatee gets liquidated with the next price update.
  3. Liquidator liquidates liquidatee
  4. They now do two trades: one good trade at market price filling 99% of liquidation amount, and one bad trade at horrible price filling 1%.
  5. The liquidator calls claimReceipt(orders) with many duplicates of the bad trade, e.g., 100 times.
  6. The calcUnitsSold function returns unitsSold = receipt.amountLiquidated and a bad avgPrice, reimbursing the price difference on the full liquidation amount.

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 trading system, when a trade executes at a worse price than expected, the insurance fund can cover the difference. This report shows that a malicious user could claim that same bad trade many times, getting paid multiple times for one loss, and empty the fund.

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 cmichel

View all

196 more disclosed reports, best first.

More from Tracer 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.