notifyLoss can be frontrun by redeem
The notifyLoss function transfers reserve funds out, reducing the value per share. A depositor who has passed the cooldown can frontrun the loss by redeeming before notifyLoss is called, then re-depositing at the lower share price to profit.
Originally disclosed on Code4rena
Submitted by 0xWaitress
notifyLoss immediately transfer zchf from reserve to the minter, reducing the amount of reserve and hence the equity and zchf to claim pershare.
While the deposit has 90 days cooldown before depositor can withdraw, current depositor that passed this cooldown can take advantage of a notifyLoss event by first frontrunning the notifyLoss by redeeming, then re-depositing into the protocol to take advantage of the reducedvalue per share.
notifyLoss can only be called by MintingHub::end, current depositor can bundle redeem + end + deposit, when they see a challenge that is ending in loss for the reserve.
Recommended Mitigation Steps
This is a re-current issue for most defi strategy to account loss in a mev-resistent way, a few possible solutions:
- create an additional window for MintingHub::end to be called by a whitelist, before it opens up to the public. The whitelist is trusted bot that will call
endthrough private mempool. - amortised the loss in the next coming period of time instead in 1 go with a
MAX_SPEED. - create an withdrawal queue such that the final withdrawal price is dependent on the upcoming equity change(s)
luziusmeisser (Frankencoin) acknowledged
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 loss is applied in a single step without any delay or queue, so a depositor can exit and re-enter around the loss event.
Impact
A depositor could shift part of the loss onto other depositors and profit from the reduced share value.
What the attacker needed
Depositor has passed the 90-day cooldown; ability to frontrun the loss event
The fix
The report suggests a whitelisted private-mempool caller for end, amortising the loss over time, or a withdrawal queue that uses the upcoming equity change; the text does not say it was fixed.
How it was found
- Wait until a challenge is about to end in a loss for the reserve.
- Redeem shares before notifyLoss is called.
- Let notifyLoss reduce the reserve and share value.
- Re-deposit at the reduced value per share.
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 deposit money and get shares representing their portion of a shared reserve. When a loss occurs, the total reserve shrinks, so each share is worth less. The report says a depositor can withdraw their shares just before the loss is recorded, then buy back in at the new lower price, leaving other depositors to absorb more of the loss.
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.