Skip to content
Business logic Audit finding Intermediate

Liquidation is vulnerable to sandwich attacks

When a position is liquidated, the swap has no minimum output amount, so an attacker can sandwich the liquidation swap to profit from the price impact. The attacker opens a short position, triggers the liquidation, then redeems the short to gain from the reduced price.

danb Follow

Originally disclosed on Code4rena

Submitted by danb, also found by leastwood

When an account is liquidated, there is no minimum amount of the swap, which makes it vulnerable for sandwich attacks.

Proof of Concept

Alice’s long position can be liquidated, bob notices it and creates a short position, then liquidates her position, thus swapping the base asset to the quote asset, therefore reducing the base asset price, then he redeems his short position and profits because the price went down.

Recommended Mitigation Steps

Set quoteAssetLimit in _reducePosition to prevent the attack.

atvanguard (Hubble) disputed and commented:

This is a known issue and is already documented as a @todo in the code.

moose-code (judge) decreased severity to Medium and commented:

After long discussion we are going to side with warden on this one. The todo is a bit sparse and the warden really digs on what precautions need to be put in place and the ramifications if they are not adhered. In general, think sprinkle of todos should not indemnify issues related around them as this might let things slip through cracks as wardens will ignore these critical pieces.

With the caveat of putting this in the medium and not high risk category.


The original report as published on Code4rena, by danb. 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 liquidation function performs a swap without setting a minimum output amount (quoteAssetLimit), allowing the swap to be manipulated.

Impact

An attacker could profit at the expense of the liquidated account by manipulating the swap price, though the judge rated this as medium severity.

What the attacker needed

A liquidatable position exists; attacker can open a short position; attacker can trigger liquidation

How it was found

  1. Attacker notices a long position that can be liquidated.
  2. Attacker creates a short position.
  3. Attacker liquidates the long position, which swaps base asset to quote asset and reduces the base asset price.
  4. Attacker redeems the short position and profits from the price decrease.

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 sandwich attack is when someone sees a trade coming and places their own trades before and after it to profit from the price change. Here, the liquidation swap has no minimum amount, so an attacker can push the price down, let the liquidation happen at a worse price, then profit from the drop.

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 danb

View all

12 more disclosed reports, best first.

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