Skip to content
Business logic Audit finding Intermediate

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.

0x52 Follow

Originally disclosed on Code4rena

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 sendWithdrawalRequest once per cycle.


The original report as published on Code4rena, by 0x52. 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.

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

  1. 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.
  2. The withdrawal is recorded for the current epoch, but the actual token amount is not processed because the batch transaction check fails.
  3. 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.

More by 0x52

View all

211 more disclosed reports, best first.

More from Yieldy contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.