Withdrawals initiated after cycle withdrawal request won’t be withdrawn in the correct cycle
A smart contract allows only one withdrawal request per cycle, so withdrawals initiated after the request but before the cycle ends are recorded but not actually processed. This causes a mismatch between tokens withdrawn and tokens users are allowed to withdraw, meaning some eligible users cannot withdraw due to insufficient tokens.
Submitted by 0x52, also found by IllIllI
Some user withdrawals won’t be available for withdrawal even though it should be.
Proof of Concept
sendWithdrawalRequest can only happen once per cycle. canBatchTransactions (L386) must return true for the actual withdrawal request to happen. It checks in L362 that currentCycleIndex > lastTokeCycleIndex and in L397 of sendWithdrawlRequest, lastTokeCycleIndex = currentCycleIndex. This means that for the rest of the cycle, canBatchTransactions will return false. This means that if a user requests a withdrawal towards the end of epoch after the withdrawal has been submitted but before the end of the epoch, their withdrawal will be set to the current epoch but the actual token amount of their withdrawal won’t be processed. This will lead to a discrepancy between the number of tokens withdrawn and the number of tokens allowed to be withdrawn by users, which means that not all users who are “eligible” for withdrawal will actually be able to withdraw because there won’t be enough tokens for everyone.
Recommended Mitigation Steps
The requirement in L362 should be removed. As noted in the contract, “TOKE’s requestWithdrawal overwriting the amount if you call it more than once per cycle”. Overwriting the withdrawal is perfectly okay though because it already uses requestWithdrawalAmount which is a cumulative measure of the tokens that need to be withdrawn because it is only decreased when the asset it actually received from a withdrawal.
toshiSat (Yieldy) acknowledged and commented:
We get around this by having a coolDownPeriod of 2. It saves on gas and we only have to call
sendWithdrawalRequestonce per cycle.
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 enforces a single withdrawal request per cycle by checking that the current cycle index is greater than the last cycle index, which prevents additional requests from being processed within the same cycle.
Impact
Some users who are eligible for withdrawal may not be able to withdraw because there won't be enough tokens for everyone.
What the attacker needed
User requests withdrawal near end of epoch; after withdrawal request submitted; before epoch ends
The fix
The requirement in L362 should be removed, as overwriting the withdrawal amount is acceptable because it uses a cumulative measure.
How it was found
- A user initiates a withdrawal request towards the end of an epoch, after the withdrawal has been submitted but before the end of the epoch.
- The withdrawal is recorded for the current epoch, but the actual token amount is not processed because the batch transaction check fails.
- This creates a discrepancy between tokens withdrawn and tokens allowed to be withdrawn, leading to insufficient tokens for some eligible users.
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 a bug in a smart contract that handles withdrawals. The contract only allows one withdrawal request per cycle, so if you request a withdrawal after that one request has been made but before the cycle ends, your request is recorded but the actual tokens are not set aside. Later, when you try to withdraw, there may not be enough tokens because the contract's accounting is off.
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.