Later challengers can bid on the previous challenge to extend the expiration time of the previous challenge, so that their own challenge can succeed before the previous challenge and get challenge rewards
A later challenger can bid on an earlier challenge to extend its expiration time, causing the later challenge to succeed first and take the reward. The earlier challenger then cannot claim the reward because the collateral is already gone.
cccz Follow with RaymondFam
Originally disclosed on Code4rena
Submitted by cccz, also found by RaymondFam
When bidders bid, if the expiration time of the challenge is less than 30 minutes, the expiration time will be extended.
uint256 earliestEnd = block.timestamp + 30 minutes;
if (earliestEnd >= challenge.end) {
// bump remaining time like ebay does when last minute bids come in
// An attacker trying to postpone the challenge forever must increase the bid by 0.5%
// every 30 minutes, or double it every three days, making the attack hard to sustain
// for a prolonged period of time.
challenge.end = earliestEnd;
}
However, extending the expiration time will break the order of the challenges, so that the later challenges will succeed before the previous ones, thus affecting the challenger’s reward expectations.
Consider the following scenario:
- There is a collateral of 2 WETH in a position, and as the actual price of WETH drops, challengers are attracted to challenge it.
- In block 1, alice uses 2 WETH to challenge the position, and the expiration time is block 7201
- At block 2, bob challenges the position with 2 WETH, expiring at block 7202
- The bidder then bids 4000 ZCHF each for alice’s and bob’s challenges.
- In block 7200, bob finds that if alice’s challenge is successful, then bob will not be able to get the challenge reward, so bob bids 4200 ZCHF to alice’s challenge. Alice’s challenge expiration time is extended to block 7351.
- At block 7201, alice cannot call end to make the challenge successful because the expiration time is extended
- At block 7202, bob successfully calls end to make his challenge successful and gets the challenge reward.
- In block 7351, alice calls the end function. Since the collateral in the position is 0 at this time, alice will not be able to get the challenge reward, and bob’s 4200 zchf will be returned.
function notifyChallengeSucceeded(address _bidder, uint256 _bid, uint256 _size) external onlyHub returns (address, uint256, uint256, uint256, uint32) {
challengedAmount -= _size;
uint256 colBal = collateralBalance();
if (_size > colBal){
// Challenge is larger than the position. This can for example happen if there are multiple concurrent
// challenges that exceed the collateral balance in size. In this case, we need to redimension the bid and
// tell the caller that a part of the bid needs to be returned to the bidder.
_bid = _divD18(_mulD18(_bid, colBal), _size);
_size = colBal;
}
// Note that thanks to the collateral invariant, we know that
// colBal * price >= minted * ONE_DEC18
// and that therefore
// price >= minted / colbal * E18
// such that
// volumeZCHF = price * size / E18 >= minted * size / colbal
// So the owner cannot maliciously decrease the price to make volume fall below the proportionate repayment.
uint256 volumeZCHF = _mulD18(price, _size); // How much could have minted with the challenged amount of the collateral
// The owner does not have to repay (and burn) more than the owner actually minted.
uint256 repayment = minted < volumeZCHF ? minted : volumeZCHF; // how much must be burned to make things even
Proof of Concept
https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/MintingHub.sol#L217-L224 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Position.sol#L329-L350
Recommended Mitigation Steps
Consider implementing a challenge queue that allows the end function to be called on subsequent challenges only after previous challenges have ended.
luziusmeisser (Frankencoin) acknowledged and commented:
Bids must at least be 0.5% higher than the previous bid, so pro-longing the challenge four times already costs as much as the whole challenger reward of 2%, making this attack not very attractive under normal circumstances.
—> Not worth to add any complexity to change this.
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 challenge extension mechanism allows a later challenge to delay an earlier one, breaking the intended first-come-first-served order.
Impact
A later challenger can steal the reward from an earlier challenger, and the earlier challenger may get nothing because the collateral is already gone.
What the attacker needed
A position with collateral; enough funds to bid on challenges; ability to bid near the deadline
The fix
The project should implement a challenge queue so that later challenges can only be ended after earlier ones have ended.
How it was found
- Alice challenges a position with 2 WETH, expiring at block 7201.
- Bob challenges the same position with 2 WETH, expiring at block 7202.
- Bidders bid 4000 ZCHF on both challenges.
- At block 7200, Bob bids 4200 ZCHF on Alice's challenge, extending its expiration to block 7351.
- At block 7201, Alice cannot end her challenge because it is extended.
- At block 7202, Bob ends his challenge successfully and gets the reward.
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 this system, people compete to win a reward by challenging a position. Each challenge has a deadline. If someone bids near the deadline, the deadline is pushed back. This report shows that a later challenger can push back an earlier challenge's deadline, so the later challenge finishes first and takes the reward, leaving the earlier challenger with nothing.
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.