Wrong calculation of excess depositToken allows stream creator to retrieve depositTokenFlashloanFeeAmount , which may cause fund loss to users
The excess deposit token calculation did not exclude the flashloan fee amount, allowing the stream creator to withdraw that fee. This could cause the protocol governance's claimFees to fail or force other users to lose part of their deposits.
Submitted by WatchPug, also found by 0x0x0x, ScopeLift, gpersoon, harleythedog, hyh, gzeon, jonah1005, and kenzo
uint256 excess = ERC20(token).balanceOf(address(this)) - (depositTokenAmount - redeemedDepositTokens);
In the current implementation, depositTokenFlashloanFeeAmount is not excluded when calculating excess depositToken. Therefore, the stream creator can call recoverTokens(depositToken, recipient) and retrieve depositTokenFlashloanFeeAmount if there are any.
As a result:
- When the protocol
governancecallsclaimFees()and claim accumulateddepositTokenFlashloanFeeAmount, it may fail due to insufficient balance of depositToken. - Or, part of users’ funds (depositToken) will be transferred to the protocol
governanceas fees, causing some users unable to withdraw or can only withdraw part of their deposits.
Proof of Concept
Given:
feeEnabled: truefeePercent: 10 (0.1%)- Alice deposited
1,000,000depositToken; - Bob called
flashloan()and borrowed1,000,000depositToken, then repaid1,001,000; - Charlie deposited
1,000depositToken; - After
endDepositLock, Alice calledclaimDepositTokens()and withdrawn1,000,000depositToken; streamCreatorcalledrecoverTokens(depositToken, recipient)and retrieved1,000depositToken(2,000 - (1,001,000 - 1,000,000));governancecalledclaimFees()and retrieved another1,000depositToken;- Charlie tries to
claimDepositTokens()but since the current balanceOf depositToken is0, the transcation always fails, and Charlie loses all the depositToken.
Recommendation
Change to:
uint256 excess = ERC20(token).balanceOf(address(this)) - (depositTokenAmount - redeemedDepositTokens) - depositTokenFlashloanFeeAmount;
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 excess calculation subtracted only the net deposit token amount, not the accumulated flashloan fee, so the fee was treated as excess and recoverable by the stream creator.
Impact
The protocol governance's claimFees may fail due to insufficient balance, or part of users' depositToken may be transferred to governance as fees, causing some users to be unable to withdraw or only withdraw part of their deposits.
What the attacker needed
FeeEnabled is true; stream creator can call recoverTokens; flashloan fee has accumulated
The fix
The excess calculation should also subtract depositTokenFlashloanFeeAmount.
How it was found
- Alice deposits 1,000,000 depositToken.
- Bob takes a flashloan of 1,000,000 depositToken and repays 1,001,000, generating a 1,000 fee.
- Charlie deposits 1,000 depositToken.
- After the deposit lock ends, Alice claims her 1,000,000 depositToken.
- The stream creator calls recoverTokens and retrieves 1,000 depositToken (the excess).
- Governance calls claimFees and retrieves another 1,000 depositToken, leaving zero balance.
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 held users' deposit tokens and also collected a small fee from flash loans. The code that let the stream creator recover extra tokens mistakenly included the fee as extra, so the creator could take it. This meant the protocol might not have enough tokens to pay its fees or return deposits to users.
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.