TrueFiStrategy: Too little withdrawn when used with AlphaBetaSplitter
AlphaBetaSplitter assumes withdrawAll returns the full balance, but TrueFiStrategy only returns USDC held in the contract, not the amount locked in TrueFi. An attacker could cause significantly less tokens to be returned than requested when TrueFi is used within AlphaBetaSplitter.
Source: https://github.com/sherlock-audit/2022-09-sherlock-judging/tree/main/003-M
Found by
Lambda
Summary
AlphaBetaSplitter implicitly assumes that withdrawAll returns the whole balance, which is not true for TrueFiStrategy.
Vulnerability Detail
When _amount is withdrawn from AlphaBetaSplitter and this value is larger than the balance of the first child (which was retrieved earlier with a _balanceOf call on the child), withdrawAll is called. Then, _amount - childOneBalance is withdrawn on the second child. This assumes that the withdrawAll() call on the first child in fact returned childOneBalance, i.e. the whole balance. However, this is not necessarily true for TrueFiStrategy. This strategy only returns the USDC that are currently held in the contract, whereas _balanceOf() returns the amount that is locked in TrueFi (but where a call to liquidExit is necessary to get the USDC into the strategy).
Impact
Because of this issue, it can happen that significantly less tokens are returned than requested when TrueFi is used within an AlphaBetaSplitter. Let's say that 950,000 USDC are locked in TrueFi and 50,000 USDC are currently in the TrueFiStrategy contract. We assume that the TrueFiStrategy is the first child of an AlphaBetaSplitter and _withdraw is called with 1,000,050 USDC. Then, only 50,000 USDC (from TrueFi) + 50,000 USDC (from the second child) will be transferred to core, i.e. 100,000 USDC instead of 1,000,050 USDC.
Code Snippet
https://github.com/sherlock-audit/2022-09-sherlock/blob/main/sherlock-v2-core/contracts/strategy/splitters/AlphaBetaSplitter.sol#L38 https://github.com/sherlock-audit/2022-09-sherlock/blob/main/sherlock-v2-core/contracts/strategy/TrueFiStrategy.sol#L111 https://github.com/sherlock-audit/2022-09-sherlock/blob/main/sherlock-v2-core/contracts/strategy/TrueFiStrategy.sol#L134
Tool used
Manual Review
Recommendation
Check the actual amount that was returned by _withdrawAll in AlphaBetaSplitter. This value is already returned by all strategies, so refactoring the Splitter to incorporate it should be easy.
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 splitter does not check the actual amount returned by withdrawAll, assuming it equals the previously read balance.
Impact
Significantly less tokens could be returned than requested when TrueFi is used within an AlphaBetaSplitter.
What the attacker needed
TrueFiStrategy used as first child; withdrawal amount exceeds first child balance
The fix
The splitter should check the actual amount returned by withdrawAll and use that value.
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 splitter contract divides withdrawal requests between two child strategies. It assumes that asking the first child to withdraw everything gives back the full balance it reported. But one strategy (TrueFi) only gives back cash it already holds, not funds locked elsewhere, so the splitter under-withdraws and returns too little.
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.