Partial liquidations are not possible
The liquidation logic in Notional's vault contracts incorrectly requires that a liquidator either fully repay an account's debt or leave it above the minimum borrow size, preventing partial liquidations. This can create a deadlock where an account cannot be liquidated at all, potentially leading to bad debt for liquidity providers.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-03-notional-judging/issues/204
Found by
xiaoming90 + 0xleastwood
Summary
Due to an incorrect implementation of VaultValuation.getLiquidationFactors(), Notional requires that a liquidator reduces an account's debt below minBorrowSize. This does not allow liquidators to partially liquidate a vault account into a healthy position and opens up the protocol to an edge case where an account is always ineligible for liquidation.
Vulnerability Detail
While VaultValuation.getLiquidationFactors() might allow for the resultant outstanding debt to be below the minimum borrow amount and non-zero, deleverageAccount() will revert due to checkMinBorrow being set to true. Therefore, the only option is for liquidators to wipe the outstanding debt entirely but users can set up their vault accounts such that that maxLiquidatorDepositLocal is less than each of the vault currency's outstanding debt.
File: VaultValuation.sol
240: int256 maxLiquidatorDepositLocal = _calculateDeleverageAmount(
241: vaultConfig,
242: h.vaultShareValueUnderlying,
243: h.totalDebtOutstandingInPrimary.neg(),
244: h.debtOutstanding[currencyIndex].neg(),
245: minBorrowSize,
246: exchangeRate,
247: er.rateDecimals
248: );
249:
250: // NOTE: deposit amount is always positive in this method
251: if (depositUnderlyingInternal < maxLiquidatorDepositLocal) {
252: // If liquidating past the debt outstanding above the min borrow, then the entire
253: // debt outstanding must be liquidated.
254:
255: // (debtOutstanding - depositAmountUnderlying) is the post liquidation debt. As an
256: // edge condition, when debt outstanding is discounted to present value, the account
257: // may be liquidated to zero while their debt outstanding is still greater than the
258: // min borrow size (which is normally enforced in notional terms -- i.e. non present
259: // value). Resolving this would require additional complexity for not much gain. An
260: // account within 20% of the minBorrowSize in a vault that has fCash discounting enabled
261: // may experience a full liquidation as a result.
262: require(
263: h.debtOutstanding[currencyIndex].sub(depositUnderlyingInternal) < minBorrowSize,
264: "Must Liquidate All Debt"
265: );
266: } else {
267: // If the deposit amount is greater than maxLiquidatorDeposit then limit it to the max
268: // amount here.
269: depositUnderlyingInternal = maxLiquidatorDepositLocal;
270: }
If depositUnderlyingInternal >= maxLiquidatorDepositLocal, then the liquidator's deposit is capped to maxLiquidatorDepositLocal. However, maxLiquidatorDepositLocal may put the vault account's outstanding debt below the minimum borrow amount but not to zero.
However, because it is not possible to partially liquidate the account's debt, we reach a deadlock where it isn't possible to liquidate all outstanding debt and it also isn't possible to liquidate debt partially. So even though it may be possible to liquidate an account into a healthy position, the current implementation doesn't always allow for this to be true.
Impact
Certain vault positions will never be eligible for liquidation and hence Notional may be left with bad debt. Liquidity providers will lose funds as they must cover the shortfall for undercollateralised positions.
Code Snippet
Tool used
Manual Review
Recommendation
VaultValuation.getLiquidationFactors() must be updated to allow for partial liquidations.
File: VaultValuation.sol
251: if (depositUnderlyingInternal < maxLiquidatorDepositLocal) {
252: // If liquidating past the debt outstanding above the min borrow, then the entire
253: // debt outstanding must be liquidated.
254:
255: // (debtOutstanding - depositAmountUnderlying) is the post liquidation debt. As an
256: // edge condition, when debt outstanding is discounted to present value, the account
257: // may be liquidated to zero while their debt outstanding is still greater than the
258: // min borrow size (which is normally enforced in notional terms -- i.e. non present
259: // value). Resolving this would require additional complexity for not much gain. An
260: // account within 20% of the minBorrowSize in a vault that has fCash discounting enabled
261: // may experience a full liquidation as a result.
262: require(
263: h.debtOutstanding[currencyIndex].neg().sub(depositUnderlyingInternal) >= minBorrowSize,
|| h.debtOutstanding[currencyIndex].neg().sub(depositUnderlyingInternal) == 0
264: "Must Liquidate All Debt"
265: );
266: } else {
267: // If the deposit amount is greater than maxLiquidatorDeposit then limit it to the max
268: // amount here.
269: depositUnderlyingInternal = maxLiquidatorDepositLocal;
270: }
Discussion
T-Woodward
This is true. This is an issue when a vaultAccount is borrowing from the prime maturity, but not an issue when an account is borrowing from an fCash maturity.
0xleastwood
Escalate for 10 USDC
We are able to set up a vault account in a way such that liquidating an amount equal or up to maxLiquidatorDepositLocal will leave the resultant currency debt above minBorrowSize and hence the liquidation will fail. Therefore, we would be in a deadlock position where a user is unable to sufficiently liquidate a vault of considerable size and hence the vault could accrue bad debt. While this only applies to prime vaults, high severity is still justified here because it is not possible to liquidate a vault if these conditions are held.
sherlock-admin
Escalate for 10 USDC
We are able to set up a vault account in a way such that liquidating an amount equal or up to
maxLiquidatorDepositLocalwill leave the resultant currency debt aboveminBorrowSizeand hence the liquidation will fail. Therefore, we would be in a deadlock position where a user is unable to sufficiently liquidate a vault of considerable size and hence the vault could accrue bad debt. While this only applies to prime vaults,highseverity is still justified here because it is not possible to liquidate a vault if these conditions are held.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Trumpero
Agree with the escalation that this should be a high issue.
hrishibhat
Result: High Unique Considering this a high issue based points raised in the issue and the escalation
sherlock-admin
Escalations have been resolved successfully!
Escalation status:
- 0xleastwood: accepted
jeffywu
Fixed: https://github.com/notional-finance/contracts-v2/pull/132
xiaoming9090
@0xleastwood + @xiaoming9090 : Verified. Fixed in PR https://github.com/notional-finance/contracts-v2/pull/132
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 liquidation function enforces that any partial repayment must reduce the debt below the minimum borrow size, but if the maximum allowed repayment still leaves debt above that minimum, no valid partial liquidation is possible.
Impact
Certain vault positions may never be liquidated, potentially causing bad debt that liquidity providers must cover.
What the attacker needed
A vault account borrowing from prime maturity; debt exceeds maxLiquidatorDepositLocal; maxLiquidatorDepositLocal leaves debt above minBorrowSize
The fix
The liquidation logic was updated to allow partial liquidations as long as the remaining debt is either zero or at least the minimum borrow size.
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.
In lending protocols, if a borrower's collateral value falls too low, others can repay part of the debt in exchange for a discount, which is called liquidation. This report found that the code only allowed liquidators to repay the entire debt at once, not just part of it, so some risky loans could never be fixed and the protocol could lose money.
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.