L-1: Redundant return value check in `LiquidityInjector.injectLiquidity`
Description:
In LiquidityInjector.injectLiquidity, the return value of lendingMarket.supply is checked to ensure assetsSupplied == amountToMintAndInject:
(uint256 assetsSupplied,) = lendingMarket.supply(params, amountToMintAndInject, 0, address(this), "");
require(assetsSupplied == amountToMintAndInject, "LI: partial inject");
This check is unnecessary. When LendingMarket.supply is called with a non-zero assets argument and shares == 0, the function computes shares from the given assets but never modifies the assets value itself. The returned assets is always equal to the input assets parameter:
if (assets > 0) {
shares = assets.toSharesDown(market[id].totalSupplyAssets, market[id].totalSupplyShares);
} else {
assets = shares.toAssetsUp(market[id].totalSupplyAssets, market[id].totalSupplyShares);
}
// ...
return (assets, shares);
Since injectLiquidity always passes amountToMintAndInject as the assets argument and 0 as shares, the assets > 0 branch is taken and assets is returned unchanged. The require statement can therefore never fail.
A similar pattern exists in LiquidityInjector.withdrawLiquidity, where the return value of lendingMarket.withdraw is checked in the same manner. The same reasoning applies: when LendingMarket.withdraw is called with a non-zero assets argument, the returned value is identical to the input.
Impact:
Low. The check wastes gas but has no functional consequence.
Recommendation:
Remove the redundant checks in both injectLiquidity and withdrawLiquidity:
- (uint256 assetsSupplied,) = lendingMarket.supply(params, amountToMintAndInject, 0, address(this), "");
- require(assetsSupplied == amountToMintAndInject, "LI: partial inject");
+ lendingMarket.supply(params, amountToMintAndInject, 0, address(this), "");
- (uint256 assetsWithdrawn,) =
- lendingMarket.withdraw(params, amountToWithdrawAndBurn, 0, address(this), address(this));
- require(assetsWithdrawn == amountToWithdrawAndBurn, "LI: partial withdraw");
+ (uint256 assetsWithdrawn,) =
+ lendingMarket.withdraw(params, amountToWithdrawAndBurn, 0, address(this), address(this));
Note that in withdrawLiquidity, the assetsWithdrawn variable is still needed for the subsequent burnByLI call, so it should be retained but the require can be removed.
Developer Response:
Acknowledged.