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.
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.
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
- Attacker notices a long position that can be liquidated.
- Attacker creates a short position.
- Attacker liquidates the long position, which swaps base asset to quote asset and reduces the base asset price.
- 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.