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.
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.
Have an undercollateralized position. This can be caused naturally due to market movements.
Frontrun challenger’s transaction with a repayment and adjustPrice call lowering the price.
Challenger’s call gets included, where they now put up collateral for bids.
Backrun challenger’s call with a bid such that it triggers the avert.
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.
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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
Have an undercollateralized position.
Frontrun challenger’s transaction with a repayment and `adjustPrice` call lowering the price.
Challenger’s call gets included, where they now put up collateral for bids.
Backrun challenger’s call with a bid such that it triggers the avert.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.