Withdraw delay can be bypassed
The staking contract allowed a user to request a withdrawal before staking any tokens, so the withdrawal delay could be bypassed. An attacker could stake and immediately unstake without waiting for the delay.
Banditx0x Follow with spyrosonic10
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-telcoin-judging/issues/23
Found by
banditx0x, spyrosonic10
Summary
StakingModule has core feature around staking, claim and withdraw. All these features has core and essential mechanism which is delayed withdrawal. In ideal scenario, user will stake X amount of token and will call requestWithdrawal when user want to withdraw his/her stake. requestWithdrawal will record user's request to withdraw and allow this user to withdraw only after withdrawalDelay is passed and during withdrawalWindow only. User can call requestWithdrawal in well advance before staking and this will allow user to bypass withdrawalDelay.
Vulnerability Detail
Withdraw locking/delaying is core feature of this contract and it can be exploited very easily.
User can call requestWithdrawal before staking tokens and this will set user's withdrawalRequestTimestamps. Once withdrawalDelay is passed user can easily stake and unstake without locking time.
One would suggest that easy fix is to check staked > 0 during call to requestWithdrawal and that should solve this issue. No, it will not.
Assume staked>0 check is added in requestWithdrawal then user will stake 1 wei and call requestWithdrawal and this will result in almost same scenario.
Why would this happen?
Because there is no relationship between stake and withdrawalRequestTimestamps.
Impact
withdrawalDelay can be bypassed
Code Snippet
POC
it.only("should bypass withdrawal delay", async () => {
const delay = 60
const window = 30
// Set time delay
await stakingContract.connect(deployer).grantRole(SLASHER_ROLE, slasher.address)
await stakingContract.connect(slasher).setWithdrawDelayAndWindow(delay, window)
await helpers.mine(1)
// Request withdrawal
await stakingContract.requestWithdrawal()
// Increase time to pass timed delay
await helpers.time.increase(delay)
// Stake some tokens
bobStakeTx3 = await stakingContract.connect(bob).stake(bobAmtStake)
// Check there is non-zero staked balance
expect(await stakingContract.balanceOf(bob.address, emptyBytes)).gt(0)
// Claim and exit without wait.
await stakingContract.fullClaimAndExit(emptyBytes)
})
Tool used
Manual Review
Recommendation
Consider resetting withdrawalRequestTimestamps when user stake any amount of token.
function stake(uint256 amount) external nonReentrant {
_stake({
account: msg.sender,
from: msg.sender,
amount: amount
});
withdrawalRequestTimestamps = 0;
}
Discussion
dmitriia
Looks ok
hrishibhat
Considering this issue as a valid medium. As it just bypasses the delay mechanism. No direct funds are lost or any other significant impact for the issue to classify as high.
spyrosonic10
Escalate for 10 USDC.
While I agree that no direct funds are lost but delayed withdrawal is essential mechanism of StakingModule. So in my opinion bypassing an essential mechanism by user should be considered as High issue.
sherlock-admin
Escalate for 10 USDC.
While I agree that no direct funds are lost but
delayed withdrawalis essential mechanism ofStakingModule. So in my opinion bypassing an essential mechanism by user should be considered asHighissue.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
hrishibhat
Escalation rejected
Not a valid high Bypassing delay mechanism in this case is not a valid high issue
sherlock-admin
Escalation rejected
Not a valid high Bypassing delay mechanism in this case is not a valid high issue
This issue's escalations have been rejected!
Watsons who escalated this issue will have their escalation amount deducted from their next payout.
jacksanford1
Admin note: This is the PR that was created and signed off on: https://github.com/telcoin/telcoin-audit/pull/7
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 does not reset the withdrawal request timestamp when a user stakes, so a pre-existing request remains valid.
Impact
The withdrawal delay mechanism can be bypassed, but no direct funds are lost.
What the attacker needed
A user account with staking ability; no special privileges needed
The fix
The withdrawal request timestamp should be reset whenever a user stakes tokens.
How it was found
- Call requestWithdrawal before staking any tokens.
- Wait for the withdrawal delay to pass.
- Stake tokens.
- Call fullClaimAndExit to withdraw immediately without waiting.
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 withdrawal delay is a waiting period before you can take your staked tokens back. The contract let someone ask to withdraw before they had even staked anything, so the waiting period started early. Then they could stake and immediately unstake, skipping the 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.