Repository navigation
Description
Lines of code
Vulnerability details
Impact
WETH supplied to Aave will be lost.
Proof of Concept
When a strategy pays debt on Aave it does a swap of the withdrawn collateral from Aave in exchange for WETH. After the swap is completed, it checks if there are any weth leftovers after the swap, if so, it deposits them back. The problem with this approach is that the strategy doesn't have any means to pull WETH out of Aave, the strategy is only capable of withdrawing the collateral from Aave, but not WETH.
function _payDebt(uint256 debtAmount, uint256 fee) internal {
...
//@audit-info => output represents the received amount of WETH for the swap
uint256 output = _swap(
ISwapHandler.SwapParams(
ierc20A(),
wETHA(),
ISwapHandler.SwapType.EXACT_OUTPUT,
amountIn,
debtAmount + fee,
_swapFeeTier,
bytes("")
)
);
//@audit-info => Checks if there are any WETH leftovers
// When there are leftovers from the swap, deposit then back
uint256 wethLefts = output > (debtAmount + fee) ? output - (debtAmount + fee) : 0;
//@audit-issue => If any leftover WETH, it deposits them onto Aave!
//@audit-issue => Once the WETH is deposited in Aave, the Strategy won't be able to pull it out.
if (wethLefts > 0) {
_supply(wETHA(), wethLefts);
}
emit StrategyUndeploy(msg.sender, debtAmount);
}
The strategy uses the StrategyAAVEv3._withdraw() function to withdraw an asset from Aave, but, in the places where this function is called, the only assets requested to be withdrawn is the Collateral.
Tools Used
Manual Audit
Recommended Mitigation Steps
Instead of supplying the wethLefts, use the excess WETH to repay more WETH debt on Aave, in this way, those extra WETHs won't be lost on Aave because the strategy doesn't have any means to withdraw them.
- By using the extra WETH to repay more debt, the loan to value is brought down even to a healtier level.
function _payDebt(uint256 debtAmount, uint256 fee) internal {
...
...
...
//@audit => Instead of supplying WETH to Aave, use it to repay more debt
if (wethLefts > 0) {
- _supply(wETHA(), wethLefts);
+ _repay(wETHA(), wethLefts);
}
emit StrategyUndeploy(msg.sender, debtAmount);
}
Assessed type
Context
Activity
0xStalin issue #41
c4-judge commentedon Jun 5, 2024
0xleastwood marked the issue as primary issue
c4-judge commentedon Jun 12, 2024
0xleastwood marked the issue as selected for report
ickas commentedon Jun 18, 2024
Fixed → https://github.com/baker-fi/bakerfi-contracts/pull/42