_calculateMaxBorrowCollateral calculates repay incorrectly and can lead to set token liquidation
The function _calculateMaxBorrowCollateral incorrectly applies unutilizedLeveragePercentage when calculating netRepayLimit, causing repayments to revert if borrowValue exceeds liquidationThreshold * (1 - unutilizedLeveragePercentage). This prevents the set token from rebalancing and can lead to liquidation.
Source: https://github.com/sherlock-audit/2023-05-Index-judging/issues/254
Found by
0x52
Summary
When calculating the amount to repay, _calculateMaxBorrowCollateral incorrectly applies unutilizedLeveragePercentage when calculating netRepayLimit. The result is that if the borrowValue ever exceeds liquidationThreshold * (1 - unutilizedLeveragPercentage) then all attempts to repay will revert.
Vulnerability Detail
AaveLeverageStrategyExtension.sol#L1110-L1118
} else {
uint256 netRepayLimit = _actionInfo.collateralValue
.preciseMul(liquidationThresholdRaw.mul(10 ** 14))
.preciseMul(PreciseUnitMath.preciseUnit().sub(execution.unutilizedLeveragePercentage));
return _actionInfo.collateralBalance
.preciseMul(netRepayLimit.sub(_actionInfo.borrowValue))
.preciseDiv(netRepayLimit);
}
When calculating netRepayLimit, _calculateMaxBorrowCollateral uses the liquidationThreshold adjusted by unutilizedLeveragePercentage. It then subtracts the borrow value from this limit. This is problematic because if the current borrowValue of the set token exceeds liquidationThreshold * (1 - unutilizedLeveragPercentage) then this line will revert making it impossible to make any kind of repayment. Once no repayment is possible the set token can't rebalance and will be liquidated.
Impact
Once the leverage exceeds a certain point the set token can no longer rebalance
Code Snippet
AaveLeverageStrategyExtension.sol#L1110-L1118
Tool used
Manual Review
Recommendation
Don't adjust the max value by unutilizedLeveragPercentage
Discussion
pblivin0x
The outlined issue and fix LGTM. We need to loosen the performed netRepayLimit check to avoid the case where we have high leverage and can't submit repayment (borrowValue > liquidationThreshold * (1 - unutilizedLeveragPercentage))
ckoopmann
Fixed in the below PR by removing the unutilizedLeveragPercentage adjustment as suggested:
https://github.com/IndexCoop/index-coop-smart-contracts/pull/142
IAm0x52
Fix looks good. unutilizedLeveragePercentage is no longer used when calculating net repay
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 code incorrectly subtracts unutilizedLeveragePercentage from the liquidation threshold when computing the net repay limit, causing an underflow when borrowValue exceeds that limit.
Impact
Once the leverage exceeds a certain point the set token can no longer rebalance and may be liquidated.
What the attacker needed
BorrowValue exceeds liquidationThreshold * (1 -…
The fix
The fix was to remove the unutilizedLeveragePercentage adjustment when calculating netRepayLimit.
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 smart contract that manages borrowed funds has a function to calculate how much can be repaid. It mistakenly reduces the maximum allowed debt by a safety margin, so if the debt gets too high, the calculation fails and no repayment can be made. This leaves the contract unable to fix its position and at risk of liquidation.
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.