When the challenge is successful, the user can send tokens to the position to avoid the position’s cooldown period being extended
The position's cooldown period is only extended when its collateral balance falls below the minimum after a successful challenge. An attacker can send collateral just before the challenge ends, keeping the balance above the minimum, so the cooldown is not extended and they can immediately mint a large amount of ZCHF at the manipulated price.
cccz Follow with mahdikarimi
Originally disclosed on Code4rena
Submitted by cccz, also found by mahdikarimi
When the challenge is successful, internalWithdrawCollateral will be called to transfer the collateral in the position. Note that the cooldown period of the position will be extended until the position expires only if the collateral in the position is less than minimumCollateral, if the user sends collateral to the position in advance, then the cool down period of the position will not be extended.
function internalWithdrawCollateral(address target, uint256 amount) internal returns (uint256) {
IERC20(collateral).transfer(target, amount);
uint256 balance = collateralBalance();
if (balance < minimumCollateral){
cooldown = expiration;
}
emitUpdate();
return balance;
}
I will use the following example to illustrate the severity of the issue.
Consider WETH:ZCHF=2000:1, the position has a challenge period of 3 days and the minimum amount of collateral is 1 WETH.
- alice clones the position, offering 1 WETH to mint 0 zchf.
- alice adjusts the price to 10e8, the cooldown period is extended to 3 days later.
- bob offers 1 WETH to launch the challenge and charlie bids 1800 zchf.
- Since bob has already covered all collateral, other challengers are unprofitable and will not launch new challenges
- After 3 days, the cooldown period ends and the challenge expires.
- bob calls end() to end the challenge.
- alice observes bob’s transaction and uses MEV to send 1 WETH to the position in advance.
- bob’s transaction is executed, charlie gets the 1 WETH collateral in the position, and alice gets most of the bid.
- Since the position balance is still 1 WETH, the position cooldown period does not extend to the position expiration.
10.Since the position is not cooldown and there is no challenge at this point, alice uses that price to mint 10e8 zchf.
Proof of Concept
https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Position.sol#L268-L276 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Position.sol#L329-L354 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/MintingHub.sol#L252-L276
Recommended Mitigation Steps
Consider extending the cooldown period of the position even if the challenge is successful
luziusmeisser (Frankencoin) commented:
Excellent finding! Will implement 1 day cooldown on successful challenges.
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 cooldown is set only when the post-withdrawal collateral balance is below minimumCollateral, so an attacker can keep the balance above that threshold by sending collateral just before the challenge ends.
Impact
The position owner can avoid the cooldown after a successful challenge and mint a large amount of ZCHF at the manipulated price, while also receiving most of the challenger's bid.
What the attacker needed
Attacker owns a position; attacker can send collateral via MEV; challenge is about to expire
The fix
The cooldown period should be extended even when a challenge is successful, regardless of the remaining collateral balance.
How it was found
- Alice clones a position with 1 WETH collateral and mints 0 ZCHF.
- Alice adjusts the price to 10e8, which extends the cooldown to 3 days later.
- Bob starts a challenge with 1 WETH and Charlie bids 1800 ZCHF.
- After 3 days the challenge expires and Bob calls end().
- Alice observes Bob's transaction and uses MEV to send 1 WETH to the position in advance.
- Bob's transaction executes, Charlie gets the 1 WETH, and Alice gets most of the bid; the balance stays at 1 WETH so the cooldown is not extended, and Alice mints 10e8 ZCHF at that 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 position lets someone lock collateral to mint a stablecoin. If the position is challenged, a cooldown is supposed to stop the owner from minting more for a while. The code only starts the cooldown if the collateral left after the challenge is below a minimum. By topping up the collateral just before the challenge ends, the owner avoids the cooldown and can mint again straight away.
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.