Closed c4-bot-8 closed 5 months ago
https://github.com/code-423n4/2024-05-bakerfi/blob/59b1f70cbf170871f9604e73e7fe70b70981ab43/contracts/core/strategies/StrategyLeverage.sol#L565
WETH cannot be used, resulting in a loss of funds
The _payDebt function may produce extra weth, these weth are provided to AAVE through _supply for use as collateral.
_payDebt
_supply
function _payDebt(uint256 debtAmount, uint256 fee) internal { ..... uint256 wethLefts = output > (debtAmount + fee) ? output - (debtAmount + fee) : 0; if (wethLefts > 0) { _supply(wETHA(), wethLefts); } emit StrategyUndeploy(msg.sender, debtAmount); }
The problem is StrategyAAVEv3 doesn't use WETH as collateral.
StrategyAAVEv3
//_supplyAndBorrow(ierc20A(), collateralIn, wETHA(), loanAmount + fee); function _supplyAndBorrow(address assetIn,uint256 amountIn,address assetOut,uint256 borrowOut ) internal override virtual{ _supply(assetIn, amountIn); //@audit assetIn is always ierc20A aaveV3().setUserUseReserveAsCollateral(assetIn, true); aaveV3().borrow(assetOut, borrowOut, 2, 0, address(this)); }
So wethLefts cannot be used.
_getMMPosition Obtaining collateralBalance also does not contain wETH
_getMMPosition
collateralBalance
function _getMMPosition() internal virtual override view returns ( uint256 collateralBalance, uint256 debtBalance ) { DataTypes.ReserveData memory wethReserve = (aaveV3().getReserveData(wETHA())); DataTypes.ReserveData memory colleteralReserve = (aaveV3().getReserveData(ierc20A())); debtBalance = IERC20(wethReserve.variableDebtTokenAddress).balanceOf(address(this)); @> collateralBalance = IERC20(colleteralReserve.aTokenAddress).balanceOf(address(this)); }
vscode, manual
Convert WETH to ierc20A and then call _supply
WETH
ierc20A
Other
0xleastwood marked the issue as duplicate of #41
0xleastwood marked the issue as satisfactory
Lines of code
https://github.com/code-423n4/2024-05-bakerfi/blob/59b1f70cbf170871f9604e73e7fe70b70981ab43/contracts/core/strategies/StrategyLeverage.sol#L565
Vulnerability details
Impact
WETH cannot be used, resulting in a loss of funds
Proof of Concept
The
_payDebt
function may produce extra weth, these weth are provided to AAVE through_supply
for use as collateral.The problem is
StrategyAAVEv3
doesn't use WETH as collateral.So wethLefts cannot be used.
_getMMPosition
ObtainingcollateralBalance
also does not contain wETHTools Used
vscode, manual
Recommended Mitigation Steps
Convert
WETH
toierc20A
and then call_supply
Assessed type
Other