The time available for a canceled withdrawal should not impact future unstaking processes
A cancelled withdrawal request remains in the queue and its old availability time is used as a floor for later withdrawal requests, so after the owner reduces the unstaking delay, a user who cancels and unstakes again still has to wait the old, longer delay. This can lock a user's funds for the original delay period even though the delay was shortened.
When stakers want to unstake their StRSR, they cannot withdrawRSR immediately.
Instead, each withdrawal enters a queue and will become available after the unstaking delay period.
This queue operates on a FIFO basis, meaning earlier withdrawals are processed before later ones.
Stakers can also cancel their withdrawals, and the RSR will be restaked immediately.
However, even canceled withdrawals can still impact future withdrawal requests.
Proof of Concept
Suppose the current unstakingDelay is set to 1 day, and a user decides to unstake some amount of StRSR at time T (line 279).
This request enters a queue, which we assume is empty at this point, making the withdrawal available at T + 1 day (line 658).
function pushDraft(address account, uint256 rsrAmount)
internal
returns (uint256 index, uint64 availableAt)
{
CumulativeDraft[] storage queue = draftQueues[draftEra][account];
index = queue.length; // index = 0
uint192 oldDrafts = index != 0 ? queue[index - 1].drafts : 0; // 0
uint64 lastAvailableAt = index != 0 ? queue[index - 1].availableAt : 0; // 0
658: availableAt = uint64(block.timestamp) + unstakingDelay; // T + 1 day
if (lastAvailableAt > availableAt) {
availableAt = lastAvailableAt;
}
queue.push(CumulativeDraft(uint176(oldDrafts + draftAmount), availableAt));
}
Now, let’s assume the user cancels this withdrawal at time T for testing purposes. Instead of removing the withdrawal from the queue, we simply increase the first available ID, which is a good approach and is easy to implement (line 368).
Even though the queue technically still contains one item (the canceledwithdrawal request), we can consider the queue empty in terms of available withdrawals.
Later, the owner updates the unstakingDelay to 1 hour.
The user attempts to unstake again, expecting to withdraw just 1 hour later, which should be possible.
However, the canceled withdrawal still impacts this new request.
In line 654, the index is 1 , and in line 657, lastAvailableAt is set to T + 1 day due to the canceled withdrawal.
As a result, in line 658, the availableAt for the new withdrawal is calculated as T + 1 hour, but since this is less than T + 1 day, the new withdrawal is also pushed to be available 1 day later.
function pushDraft(address account, uint256 rsrAmount)
internal
returns (uint256 index, uint64 availableAt)
{
CumulativeDraft[] storage queue = draftQueues[draftEra][account];
654: index = queue.length; // index = 1
uint192 oldDrafts = index != 0 ? queue[index - 1].drafts : 0; // 0
657: uint64 lastAvailableAt = index != 0 ? queue[index - 1].availableAt : 0; // T + 1 day
658: availableAt = uint64(block.timestamp) + unstakingDelay; // T + 1 hour
if (lastAvailableAt > availableAt) {
availableAt = lastAvailableAt;
}
queue.push(CumulativeDraft(uint176(oldDrafts + draftAmount), availableAt));
}
This situation is clearly unfair to the user.
The availableAt of canceled withdrawals should not be considered when determining the availability of new withdrawals.
Please add below test to the test/ZZStRSR.test.ts
describe('PushDraft Test', () => {
it('Should use current unstakingDelay', async () => {
// old unstakingDelay is 1 day
const oldUnstakingDelay = 3600 * 24
await stRSR.connect(owner).setUnstakingDelay(oldUnstakingDelay)
const amount: BigNumber = bn('100e18')
await rsr.connect(addr1).approve(stRSR.address, amount)
await stRSR.connect(addr1).stake(amount)
const draftEra = 1
const availableAtOfFirst = await getLatestBlockTimestamp() + oldUnstakingDelay + 1
/**
* Unstaking request enter a queue, and withdrawal become available 1 day later
*/
await expect(stRSR.connect(addr1).unstake(amount))
.emit(stRSR, 'UnstakingStarted')
.withArgs(0, draftEra, addr1.address, amount, amount, availableAtOfFirst)
/**
* Cancel the unstaking to eliminate any pending withdrawals
*/
await stRSR.connect(addr1).cancelUnstake(1)
// new unstakingDelay is 1 hour
const newUnstakingDelay = 3600
await stRSR.connect(owner).setUnstakingDelay(newUnstakingDelay)
await rsr.connect(addr2).approve(stRSR.address, amount)
await stRSR.connect(addr2).stake(amount)
const availableAtOfFirstOfUser2 = await getLatestBlockTimestamp() + newUnstakingDelay + 1
/**
* Unstaking request enter a queue, and withdrawal become available 1 hour later for a second user
*/
await expect(stRSR.connect(addr2).unstake(amount))
.emit(stRSR, 'UnstakingStarted')
.withArgs(0, draftEra, addr2.address, amount, amount, availableAtOfFirstOfUser2)
/**
* Although the first unstaking was canceled, its available time still impacts subsequent unstaking requests
*/
await expect(stRSR.connect(addr1).unstake(amount))
.emit(stRSR, 'UnstakingStarted')
.withArgs(1, draftEra, addr1.address, amount, amount, availableAtOfFirst)
})
})
Considering the low likelihood (owner reduces unstakingDelay, user cancels withdrawals before that) and the earlier the cancellation, the lower the impact, it will be downgraded to Low.
Let me clarify the impact and likelihood again.
As seen in the code below, the minimum unstaking delay is 2 minutes, and the maximum is 1 year. There’s a significant difference between these two values.
Suppose the current unstaking delay is set to the 1 year.
All stakers are operating under this delay now.
For various reasons, the admin decides to reduce the unstaking delay to a shorter period, say 1 month.
Stakers will realize they can withdraw their funds after 1 month instead of 1 year.
They can cancel their existing withdrawal requests and attempt to unstake again.
However, the original 1-yeardelay still applies to all stakers, meaning they cannot withdraw their funds after just 1 month—even if they cancel their old withdrawals.
Their funds remain locked for 1 year.
Considering the low likelihood (owner reduces unstakingDelay, user cancels withdrawals before that) and the earlier the cancellation, the lower the impact, it will be downgraded to Low
Regarding the likelihood, users do not need to cancel their withdrawals before the owner changes the unstaking delay. Even if they cancel their withdrawals anytime after the delay is changed, the old delay still impacts all stakers.
As for the impact, this situation results in users’ funds being locked and creates a DoS issue.
Given these points, I believe the impact and likelihood are at least medium. I would appreciate it if you could reconsider this issue.
When the owner reduces unstakingDelay, the user will not be able to apply the latest unstakingDelay even if they cancel the previous withdrawal.
If this is correct, I tend to raise it to Medium.
The original report as published on Code4rena, by ether_sky. 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
Likely the pushDraft function uses the last queue entry's availableAt as a floor even when that entry has been cancelled and is before firstRemainingDraft.
Impact
A user's funds could remain locked for the original, longer unstaking delay even after the owner shortens it, creating a denial-of-service for that user.
What the attacker needed
Owner reduces unstaking delay; user cancels a prior withdrawal; user unstakes again
The fix
The pushDraft function should ignore the last queue entry's availableAt when that entry has been cancelled, so the current unstaking delay applies.
How it was found
Set the unstaking delay to one day and stake an amount.
Unstake, which queues a withdrawal available one day later.
Cancel the unstake, which advances the first remaining draft index.
Change the unstaking delay to one hour.
Unstake again and observe the new withdrawal is still available one day later, not one hour later.
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
When you unstake, your request joins a queue and becomes available after a waiting period. If you cancel, the request is skipped but not removed, and its old availability time is still used as a minimum for your next request. So if the waiting period is later shortened, your new request can still be stuck with the old, longer wait.
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.