In case that unstakingDelay is decreased, users who have previously unstaked would have to wait more than unstakingDelay for new unstakes
When the unstaking delay is decreased, users with pending unstake drafts must wait for the old, longer delay to pass before they can withdraw, and any new unstake drafts they create are also blocked until that old delay expires. This means a user who unstaked a tiny amount before the change cannot access their remaining stake for the original delay period, even though the delay was shortened.
Submitted by 0xA5DF, also found by Soosh
Users who wish to unstake their RSR from StRSR have to first unstake and then wait unstakingDelay till they can actually withdraw their stake.
The unstakingDelay can change by the governance.
The issue is that when the unstakingDelay is decreased - users that have pending unstakes (aka drafts) would have to wait till the old delay has passed for the pending draft (not only for their pending drafts, but also for any new draft they wish to create. e.g. if the unstaking delay was 6 months and was changed to 2 weeks, if a user has a pending draft that was created a month before the change the user would have to wait at least 5 months since the change for every new draft).
Proof of Concept
The following PoC shows an example similar to above:
- Unstaking delay was 6 months
- Bob unstaked (create a draft) 1 wei of RSR
- Unstaking delay was changed to 2 weeks
- Both Bob and Alice unstake their remaining stake
- Alice can withdraw her stake after 2 weeks
- Bob has to wait 6 months in order to withdraw both that 1 wei and the remaining of the stake
diff --git a/test/ZZStRSR.test.ts b/test/ZZStRSR.test.ts
index f507cd50..3312686a 100644
--- a/test/ZZStRSR.test.ts
+++ b/test/ZZStRSR.test.ts
@@ -599,6 +599,8 @@ describe(`StRSRP${IMPLEMENTATION} contract`, () => {
let amount2: BigNumber
let amount3: BigNumber
+ let sixMonths = bn(60*60*24*30*6);
+
beforeEach(async () => {
stkWithdrawalDelay = bn(await stRSR.unstakingDelay()).toNumber()
@@ -608,18 +610,56 @@ describe(`StRSRP${IMPLEMENTATION} contract`, () => {
amount3 = bn('3e18')
// Approve transfers
- await rsr.connect(addr1).approve(stRSR.address, amount1)
+ await rsr.connect(addr1).approve(stRSR.address, amount1.add(1))
await rsr.connect(addr2).approve(stRSR.address, amount2.add(amount3))
+
// Stake
- await stRSR.connect(addr1).stake(amount1)
+ await stRSR.connect(addr1).stake(amount1.add(1))
await stRSR.connect(addr2).stake(amount2)
await stRSR.connect(addr2).stake(amount3)
- // Unstake - Create withdrawal
- await stRSR.connect(addr1).unstake(amount1)
+ // here
+ let sixMonths = bn(60*60*24*30*6);
+ // gov thinks it's a good idea to set delay to 6 months
+ await expect(stRSR.connect(owner).setUnstakingDelay(sixMonths))
+ .to.emit(stRSR, 'UnstakingDelaySet')
+ .withArgs(config.unstakingDelay, sixMonths);
+
+ // Poor Bob created a draft when unstaking delay was 6 months
+ await stRSR.connect(addr1).unstake(bn(1))
+
+ // gov revise their previous decision and set unstaking delay back to 2 weeks
+ await expect(stRSR.connect(owner).setUnstakingDelay(config.unstakingDelay))
+ .to.emit(stRSR, 'UnstakingDelaySet')
+ .withArgs(sixMonths, config.unstakingDelay);
+
+ // now both Bob and Alice decide to unstake
+ await stRSR.connect(addr1).unstake(amount1);
+ await stRSR.connect(addr2).unstake(amount2);
+
+ })
+
+ it('PoC user 1 can\'t withdraw', async () => {
+ // Get current balance for user
+ const prevAddr1Balance = await rsr.balanceOf(addr1.address)
+
+ // 6 weeks have passed, much more than current delay
+ await advanceTime(stkWithdrawalDelay * 3)
+
+
+ // Alice can happily withdraw her stake
+ await stRSR.connect(addr2).withdraw(addr2.address, 1)
+ // Bob can't withdraw his stake and has to wait 6 months
+ // Bob is now very angry and wants to talk to the manager
+ await expect(stRSR.connect(addr1).withdraw(addr1.address, 2)).to.be.revertedWith(
+ 'withdrawal unavailable'
+ )
+
+
})
+ return; // don't run further test
it('Should revert withdraw if Main is paused', async () => {
// Get current balance for user
const prevAddr1Balance = await rsr.balanceOf(addr1.address)
@@ -1027,6 +1067,7 @@ describe(`StRSRP${IMPLEMENTATION} contract`, () => {
})
})
})
+ return; // don't run further test
describe('Add RSR / Rewards', () => {
const initialRate = fp('1')
Recommended Mitigation Steps
Allow users to use current delay even if it was previously higher. I think this should apply not only to new drafts but also for drafts that were created before the change.
Alternatively, the protocol can set a rule that even if the staking delay was lowered stakers have to wait at least the old delay since the change till they can withdraw. But in this case the rule should apply to everybody regardless if they have pending drafts or not.
Ultimately this feels like a design tradeoff. I do agree that the UX would be better if the most recent value was used, but it can cut both ways if the delay is increased.
0xean (judge) decreased severity to Medium
pmckelvy1 (Reserve) acknowledged via duplicate issue #151
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 contract calculates the withdrawal time for each draft using the unstaking delay value at the time the draft is created, and it also prevents new drafts from being withdrawn until all existing drafts are past their delay, so a decrease in the delay does not affect already-created drafts.
Impact
Users who unstaked before a decrease in the unstaking delay could be locked out of withdrawing their stake for the old, longer delay period, causing frustration and potentially locking funds for months.
What the attacker needed
Governance changes unstaking delay; user has a pending unstake draft
The fix
The contract should allow users to use the current delay even if it was previously higher, applying this to both new and existing drafts.
How it was found
- Set the unstaking delay to 6 months.
- Bob unstakes 1 wei of RSR, creating a draft.
- Change the unstaking delay to 2 weeks.
- Both Bob and Alice unstake their remaining stake.
- After 2 weeks, Alice can withdraw her stake.
- Bob cannot withdraw his stake (including the 1 wei and the rest) until 6 months have passed.
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.
Staking means locking up tokens to earn rewards. When you unstake, you often have to wait a set period (the unstaking delay) before you can withdraw your tokens. This report shows that if the delay is shortened, anyone who already started unstaking still has to wait out the old, longer delay for all their unstakes, which is unfair and confusing.
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.