Skip to content
Race condition Audit finding Advanced

Challenges can be frontrun with de-leveraging to cause lossses for challengers

A position owner can front-run a challenge by repaying the debt and setting the position price to zero, so the challenger's bid passes the collateral check with almost no value and the owner can then back-run with a tiny bid to take the challenger's collateral. This sandwich attack causes challengers to lose their collateral.

carrotsmuggler Follow with mov, bin2chen and 7 others

Originally disclosed on Code4rena

Submitted by carrotsmuggler, also found by mov, bin2chen, juancito, KIntern_NA, Ace-30, cccz, Nyx, nobody2018, and mahdikarimi

Challenges, once created, cannot be closed. Thus once a challenge is created, the challenger has already transferred in a collateral amount and is thus open for losing their collateral to a bidding war which will most likely close below market price, since otherwise buying from the market would be cheaper for bidders.

Position owners can take advantage of this fact and frontrun a launchChallenge transaction with an adjustPrice transaction. The adjustPrice function lets the user lower the price of the position, and can pass the collateral check by sending collateral tokens externally.

As a worst case scenario, consider a case where a position is open with 1 ETH collateral and 1500 ZCHF minted. A challenger challenges the position and the owner frontruns the challenger by sending the contract 1500 ZCHF and calling repay() and then calling adjustPrice with value 0, all in one transaction with a contract. Now, the price in the contract is set to 0, and the collateral check passes since the outstanding minted amount is 0. The challenger’s transaction gets included next, and they are now bidding away their collateral, since any amount of bid will pass the avert collateral check.

The position owner themselves can backrun the same transaction with a bid of 1 wei and take all the challenger’s collateral, since every bid checks for the tryAvertChallenge condition.

if (_bidAmountZCHF * ONE_DEC18 >= price * _collateralAmount)

Since price is set to 0, any bid passes this check. This sandwich attack causes immense losses to all challengers in the system, baiting them with bad positions and then sandwiching their challenges.

Since sandwich attacks are extremely commonplace, this is classified as high severity.

Proof of Concept

The attack can be performed the following steps.

  1. Have an undercollateralized position. This can be caused naturally due to market movements.
  2. Frontrun challenger’s transaction with a repayment and adjustPrice call lowering the price.
  3. Challenger’s call gets included, where they now put up collateral for bids.
  4. Backrun challenger’s call with a bid such that it triggers the avert.
  5. Attacker just claimed the challenger’s collateral at their specified bid price, which can be as little as 1 wei if price is 0.

Recommended Mitigation Steps

When launching a challenge, ask for a expectedPrice argument. If the actual price does not match this expected price, that means that transaction was frontrun and should be reverted. This acts like a slippage check for challenges.

0xA5DF (lookout) commented:

I have some doubts about severity, since the auction’s final bid is expected to be at about the worth of the collateral. So the challenger isn’t expected to lose anything but the challenge reward.

luziusmeisser (Frankencoin) confirmed and commented:

This is actually a high risk issue as the challenge is ended early as soon as the highest bid reaches the liquidation price.

I would even say that this is one of the most valuable findings I’ve seen so far!

The fix is to add front-running protection to the launchChallenge function:

function launchChallenge(address _positionAddr, uint256 _collateralAmount, uint256 expectedPrice) external validPos(_positionAddr) returns (uint256) {
        IPosition position = IPosition(_positionAddr);
        if (position.price() != expectedPrice) revert UnexpectedPrice();

hansfriese (judge) commented:

Since the owner lowers the price of the position, the collateral for a challenge is worth nothing, and the challengers might lose their collateral. So I agree with the sponsor.


The original report as published on Code4rena, by carrotsmuggler. 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

The challenge function does not check the position's price at the time of the challenge, allowing the owner to manipulate the price before the challenge is processed.

Impact

The challenger loses their collateral to the position owner, who can bid as little as 1 wei if the price is zero.

What the attacker needed

An undercollateralized position exists; Attacker controls the position owner; Attacker can front-run and back-run transactions

The fix

The fix is to add front-running protection to the launchChallenge function by requiring an expected price argument and reverting if the actual price does not match.

How it was found

  1. Have an undercollateralized position.
  2. Frontrun challenger’s transaction with a repayment and `adjustPrice` call lowering the price.
  3. Challenger’s call gets included, where they now put up collateral for bids.
  4. Backrun challenger’s call with a bid such that it triggers the avert.
  5. Attacker just claimed the challenger’s collateral at their specified bid price.

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 challenger puts up collateral to start an auction on a loan position that is undercollateralised. The position owner can quickly change the position's price to zero just before the challenge, so the challenger's bid is accepted even if it is tiny. Then the owner bids a tiny amount and takes the challenger's collateral.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by carrotsmuggler

View all

42 more disclosed reports, best first.

More from Frankencoin

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.