Open c4-bot-4 opened 5 months ago
0xleastwood marked the issue as duplicate of #34
0xleastwood marked the issue as selected for report
0xleastwood marked the issue as not a duplicate
0xleastwood changed the severity to 2 (Med Risk)
This seems to predominantly impact yield in two ways:
Neither of these impact user's funds directly so medium
severity seems right.
Hello Judge @0xleastwood
I'd like to clarify the second point raised in your comment to downgrade the severity of this report to medium
Harvest does not fail but there is some value leakage that happens over time. Neither of these impact user's funds directly so medium severity seems right.
Actually, when harvest does not fail, and, causes the leftover collateral to be left sitting on the protocol, those funds are actually the funds deposited by the users. While it is true that the leakage happens over time, those funds are user funds, not only yield.
I'd like to ask if you could take a second look at your verdict for the severity of this report and if you would consider re-assigning the original severity based on this clarification
Hello Judge @0xleastwood
I'd like to clarify the second point raised in your comment to downgrade the severity of this report to medium
Harvest does not fail but there is some value leakage that happens over time. Neither of these impact user's funds directly so medium severity seems right.
Actually, when harvest does not fail, and, causes the leftover collateral to be left sitting on the protocol, those funds are actually the funds deposited by the users. While it is true that the leakage happens over time, those funds are user funds, not only yield.
I'd like to ask if you could take a second look at your verdict for the severity of this report and if you would consider re-assigning the original severity based on this clarification
I see what you mean, even though the amount is somewhat on the smaller side, a debt adjustment will leave some excess collateral stuck as it rebalances to maintain a target LTV.
0xleastwood changed the severity to 3 (High Risk)
Lines of code
https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/strategies/StrategyLeverage.sol#L545-L547 https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/hooks/UseSwapper.sol#L95-L97
Vulnerability details
Impact
Collateral can be locked and lost in the Strategy contract.
Proof of Concept
When harvesting a strategy and adjusting the debt to maintain the loan to value of the strategy, the strategy does the following steps:
EXACT_OUTPUT
swap on Uniswap. It requests to receive the exactdebtAmount + fees
(to repay the flashloan) in exchange for at most the withdrawn amount of collateral from AaveThe problem identified on this report is caused due to some issues in the steps 4 & 6. Let's dive into it.
The first part of the problem is caused due to the way how the UniQuoter is invoked. The
fee
of the pool that is sent to the UniQuoter is hardcoded to be500
, which represents a pool of (0.05% fee). This can cause two problems:The execution can be reverted if there is not an existing pool for the COLLATERAL/WETH at a 0.05% fee. The UniQuoter will receive the call and will derive the address of the pool based on the tokenIn, tokenOut and fee. If there is not a pool for the 0.05% fee (500), the call will be reverted and the whole harvesting execution will blown up.
The second problem is when the
swapFeeTier
is different than 500, or in other words, that the fee of the UniPool that is configured for the strategy is different than 500 (0.05%), for example, if the strategy is configured to work with a pool with a fee of 0.01% (100).debtAmount + fee
to repay the flashloan is 100WETH.swapFeeTier
. Assume the Strategy is configured to work with the UniPool with the lowest fee available (0.01%).EXACT_OUTPUT
swap on a pool with 0.01% fee for 100 WETH, the required amount of tokenIn (collateral) will be:StrategyLeverage._payDebt() function
Now it comes the second part of the problem, the Strategy checks if there is any leftover collateral after the swap, and if there is any, it does a self transfer for the leftover amount. This can cause one of these two problems:
The most problematic is that the leftover collateral will simply be left in the Strategy, it won't be re-supplied to Aave, neither pull out of the Strategy, it will be simply left in the Strategy's balance, from where it will be irrecoverable, meaning, the leftover collateral will be locked in the Strategy contract.
Depending on the Collateral's contract, there are some ERC20s that reverts the execution if they receive a self-transfer of tokens.
UseSwapper._swap() function
To recapitulate the most important points, the biggest impact because of the two problems on steps 4 & 6 is when the UniPool configured for the strategy uses a lower fee than 0.05% (500). In this case, the leftover collateral after doing the EXACT_OUTPUT swap for the required amount of WETH to repay the flashloan will be left and locked in the Strategy.
Tools Used
Manual Audit, Uniswap Pool's Explorer & UniV2Quoter contract
Recommended Mitigation Steps
To address this problem, I'd recommend to apply the two below suggestions.
swapFeeTier
)Assessed type
Context