Incorrect withdrawal requested
The withdrawal function calculated a capped amount but then requested the uncapped amount from the Tokemak pool, so when the balance was lower than the requested amount, the contract asked to withdraw more than it held. An attacker could trigger this to request an excessive withdrawal, potentially causing a failure or draining more than intended.
Originally disclosed on Code4rena
Submitted by csanuragjain, also found by MiloTruck
\_requestWithdrawalFromTokemak function :: Instead of sending amountToRequest for requestWithdrawal, contract is asking _amount for requestWithdrawal. This becomes a problem when balance < _amount and only balance could be withdrawn
Proof of Concept
- In _requestWithdrawalFromTokemak function, amountToRequest is calculated as
// the only way balance < _amount is when using unstakeAllFromTokemak
uint256 amountToRequest = balance < _amount ? balance : _amount;
- Now assuming balance < _amount then amountToRequest becomes balance
- But tokePoolContract.requestWithdrawal is called over _amount instead of amountToRequest which means withdrawal is requested over an extra amount
Recommended Mitigation Steps
Modify Staking.sol#L326 to
if (amountToRequest > 0) tokePoolContract.requestWithdrawal(amountToRequest);
toshiSat (Yieldy) confirmed and resolved
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
The code computed a safe amount (amountToRequest) but then passed the original _amount to the external call instead of the computed value.
Impact
The contract could request a withdrawal larger than its balance, potentially causing the transaction to fail or withdrawing more than intended.
What the attacker needed
Balance < _amount
The fix
The code was fixed by changing the call to use amountToRequest instead of _amount.
How it was found
- Call the _requestWithdrawalFromTokemak function with an amount greater than the contract's balance.
- The function calculates amountToRequest as the balance because balance < _amount.
- The function then calls tokePoolContract.requestWithdrawal with _amount instead of amountToRequest, requesting an excessive withdrawal.
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 smart contract function is supposed to withdraw only what is available when the requested amount is too high. Instead, it tells the external pool to withdraw the full requested amount, which can be more than the contract actually has. This mistake could cause the withdrawal to fail or take too much.
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.