Withdrawals will stuck
The report claims that if a new staking era begins while the draft era remains old, then later unstaking drafts are recorded under the old draft era and can be lost when the draft era finally updates. An attacker could cause users to lose their future withdrawals.
Originally disclosed on Code4rena
Submitted by csanuragjain
If a new era gets started for stakeRSR and draftRSR still point to old era then user will be at risk of losing their future holdings.
Proof of Concept
- seizeRSR is called with amount 150 where stakeRSR was 50 and draftRSR was 80. The era was 1 currently for both stake and draft
function seizeRSR(uint256 rsrAmount) external notPausedOrFrozen {
...
stakeRSR -= stakeRSRToTake;
..
if (stakeRSR == 0 || stakeRate > MAX_STAKE_RATE) {
seizedRSR += stakeRSR;
beginEra();
}
...
draftRSR -= draftRSRToTake;
if (draftRSR > 0) {
// Downcast is safe: totalDrafts is 1e38 at most so expression maximum value is 1e56
draftRate = uint192((FIX_ONE_256 * totalDrafts + (draftRSR - 1)) / draftRSR);
}
...
- stakeRSR portion comes to be 50 which means remaining stakeRSR will be 0 (50-50). This means a new staking era will get started
if (stakeRSR == 0 || stakeRate > MAX_STAKE_RATE) {
seizedRSR += stakeRSR;
beginEra();
}
- This causes staking era to become 2
function beginEra() internal virtual {
stakeRSR = 0;
totalStakes = 0;
stakeRate = FIX_ONE;
era++;
emit AllBalancesReset(era);
}
- Now draftRSR is still > 0 so only draftRate gets updated. The draft Era still remains 1
- User stakes and unstakes in this new era. Staking is done in era 2
- Unstaking calls the pushDraft which creates User draft on draftEra which is still 1
function pushDraft(address account, uint256 rsrAmount)
internal
returns (uint256 index, uint64 availableAt)
{
...
CumulativeDraft[] storage queue = draftQueues[draftEra][account];
...
queue.push(CumulativeDraft(uint176(oldDrafts + draftAmount), availableAt));
...
}
- Lets say due to unfortunate condition again seizeRSR need to be called. This time
draftRate > MAX_DRAFT_RATEwhich means draft era increases and becomes 2
if (draftRSR == 0 || draftRate > MAX_DRAFT_RATE) {
seizedRSR += draftRSR;
beginDraftEra();
}
- This becomes a problem since all unstaking done till now in era 2 were pointing in draft era 1. Once draft era gets updated to 2, all those unstaking are lost.
Recommended Mitigation Steps
Era should be same for staking and draft. So if User is unstaking at era 1 then withdrawal draft should always be era 1 and not some previous era.
I believe the sequence of events here to be off with when beginDraftEra would be called.
Will leave open for sponsor confirmation on the beginDraftEra call being triggered earlier in the process due to the value of
draftRSR == 0.
tbrent (Reserve) disputed and commented:
In the example described, I’m pretty sure point 4 is wrong: draftRSR would be 0 and both the eras would be changed at the same time.
That said, I don’t think it’s a problem to have different eras for stakeRSR and draftRSR. It’s subtle, but it could be that due to rounding one of these overflows
MAX_STAKE_RATE/MAX_DRAFT_RATE, but not the other. This is fine. This means enough devaluation has happened to one of the polities (current stakers; current withdrawers) that they have been wiped out. It’s not a contradiction for the other polity to still be entitled to a small amount of RSR.It also might be the warden is misunderstanding the intended design here: if you initiate StRSR unstaking, then a sufficient RSR seizure event should result in the inability to withdraw anything after.
Please note: the following comment and re-assessment took place after judging and awarding were finalized. As such, this report will leave this finding in its originally assessed risk category as it simply reflects a snapshot in time.
I wanted to comment and apologize that this issue slipped through the QA process and I didn’t give it a second pass to close it out as invalid. While C4 will not change grades or awards retroactively, it is worth noting for the final report that I do not believe this issue to be valid.
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 design allows the staking era and draft era to advance independently, so unstaking drafts created under an old draft era are not carried over when the draft era changes.
Impact
Users could lose their pending withdrawals if the staking and draft eras diverge, but the project team disputed the scenario and stated that such loss is intended after a sufficient seizure event.
What the attacker needed
SeizeRSR called with specific amounts; stakeRSR becomes zero while draftRSR remains positive; user stakes and unstakes in new era; second seizeRSR triggers draft era change
How it was found
- Call seizeRSR with an amount that reduces stakeRSR to zero, starting a new staking era.
- Observe that draftRSR is still positive, so the draft era remains unchanged.
- A user stakes and unstakes in the new staking era; the unstaking draft is recorded under the old draft era.
- Call seizeRSR again so that draftRate exceeds MAX_DRAFT_RATE, starting a new draft era.
- The previously recorded unstaking drafts from the old draft era are lost.
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.
This is about a staking system where users can lock tokens and later withdraw them. The system uses 'eras' to track balances. The report says that if the staking era and the withdrawal era get out of sync, some withdrawal records might be lost. However, the project team disputed this, saying the scenario is wrong and the behaviour is intended.
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.