Possible to create vault positions ineligible for liquidation
A vault account can be set up so that its secondary debt is below the minimum borrow size, making it impossible to liquidate because the minimum borrow check fails when trying to reduce one currency's debt. An attacker could create many such accounts, preventing liquidation and causing bad debt for the protocol.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-03-notional-judging/issues/202
Found by
xiaoming90 + 0xleastwood
Summary
Users can self-liquidate their secondary debt holdings in such a way that it is no longer possible to deleverage their vault account as checkMinBorrow will fail post-maturity.
Vulnerability Detail
When deleveraging a vault account, the liquidator will pay down account debt directly and the account will not accrue any cash. Under most circumstances, it is not possible to put an account's debt below its minimum borrow size.
However, there are two exceptions to this:
- Liquidators purchasing cash from a vault account. This only applies to non-prime vault accounts.
- A vault account is being settled and
checkMinBorrowis skipped to ensure an account can always be settled.
File: VaultLiquidationAction.sol
057: function deleverageAccount(
058: address account,
059: address vault,
060: address liquidator,
061: uint16 currencyIndex,
062: int256 depositUnderlyingInternal
063: ) external payable nonReentrant override returns (
064: uint256 vaultSharesToLiquidator,
065: int256 depositAmountPrimeCash
066: ) {
067: require(currencyIndex < 3);
068: (
069: VaultConfig memory vaultConfig,
070: VaultAccount memory vaultAccount,
071: VaultState memory vaultState
072: ) = _authenticateDeleverage(account, vault, liquidator);
073:
074: PrimeRate memory pr;
075: // Currency Index is validated in this method
076: (
077: depositUnderlyingInternal,
078: vaultSharesToLiquidator,
079: pr
080: ) = IVaultAccountHealth(address(this)).calculateDepositAmountInDeleverage(
081: currencyIndex, vaultAccount, vaultConfig, vaultState, depositUnderlyingInternal
082: );
083:
084: uint16 currencyId = vaultConfig.borrowCurrencyId;
085: if (currencyIndex == 1) currencyId = vaultConfig.secondaryBorrowCurrencies[0];
086: else if (currencyIndex == 2) currencyId = vaultConfig.secondaryBorrowCurrencies[1];
087:
088: Token memory token = TokenHandler.getUnderlyingToken(currencyId);
089: // Excess ETH is returned to the liquidator natively
090: (/* */, depositAmountPrimeCash) = TokenHandler.depositUnderlyingExternal(
091: liquidator, currencyId, token.convertToExternal(depositUnderlyingInternal), pr, false
092: );
093:
094: // Do not skip the min borrow check here
095: vaultAccount.vaultShares = vaultAccount.vaultShares.sub(vaultSharesToLiquidator);
096: if (vaultAccount.maturity == Constants.PRIME_CASH_VAULT_MATURITY) {
097: // Vault account will not incur a cash balance if they are in the prime cash maturity, their debts
098: // will be paid down directly.
099: _reduceAccountDebt(
100: vaultConfig, vaultState, vaultAccount, pr, currencyIndex, depositUnderlyingInternal, true
101: );
102: depositAmountPrimeCash = 0;
103: }
104:
105: // Check min borrow in this liquidation method, the deleverage calculation should adhere to the min borrow
106: vaultAccount.setVaultAccountForLiquidation(vaultConfig, currencyIndex, depositAmountPrimeCash, true);
107:
108: emit VaultDeleverageAccount(vault, account, currencyId, vaultSharesToLiquidator, depositAmountPrimeCash);
109: emit VaultLiquidatorProfit(vault, account, liquidator, vaultSharesToLiquidator, true);
110:
111: _transferVaultSharesToLiquidator(
112: liquidator, vaultConfig, vaultSharesToLiquidator, vaultAccount.maturity
113: );
114:
115: Emitter.emitVaultDeleverage(
116: liquidator, account, vault, currencyId, vaultState.maturity,
117: depositAmountPrimeCash, vaultSharesToLiquidator
118: );
119: }
currencyIndex represents which currency is being liquidated and depositUnderlyingInternal the amount of debt being reduced. Only one currency's debt can be updated here.
File: VaultLiquidationAction.sol
239: function _reduceAccountDebt(
240: VaultConfig memory vaultConfig,
241: VaultState memory vaultState,
242: VaultAccount memory vaultAccount,
243: PrimeRate memory primeRate,
244: uint256 currencyIndex,
245: int256 depositUnderlyingInternal,
246: bool checkMinBorrow
247: ) private {
248: if (currencyIndex == 0) {
249: vaultAccount.updateAccountDebt(vaultState, depositUnderlyingInternal, 0);
250: vaultState.setVaultState(vaultConfig);
251: } else {
252: // Only set one of the prime rates, the other prime rate is not used since
253: // the net debt amount is set to zero
254: PrimeRate[2] memory pr;
255: pr[currencyIndex - 1] = primeRate;
256:
257: VaultSecondaryBorrow.updateAccountSecondaryDebt(
258: vaultConfig,
259: vaultAccount.account,
260: vaultAccount.maturity,
261: currencyIndex == 1 ? depositUnderlyingInternal : 0,
262: currencyIndex == 2 ? depositUnderlyingInternal : 0,
263: pr,
264: checkMinBorrow
265: );
266: }
267: }
In the case of vault settlement, through self-liquidation, users can setup their debt and cash holdings post-settlement, such that both accountDebtOne and accountDebtTwo are non-zero and less than vaultConfig.minAccountSecondaryBorrow. The objective would be to have zero primary debt and Y secondary debt and X secondary cash. Post-settlement, cash is used to offset debt (Y - X < minAccountSecondaryBorrow) and due to the lack of checkMinBorrow in VaultAccountAction.settleVaultAccount(), both secondary currencies can have debt holdings below the minimum amount.
Now when deleverageAccount() is called on a prime vault account, debts are paid down directly. However, if we are only able to pay down one secondary currency at a time, checkMinBorrow will fail in VaultSecondaryBorrow.updateAccountSecondaryDebt() because both debts are checked.
File: VaultSecondaryBorrow.sol
295: if (checkMinBorrow) {
296: // No overflow on negation due to overflow checks above
297: require(accountDebtOne == 0 || vaultConfig.minAccountSecondaryBorrow[0] <= -accountDebtOne, "min borrow");
298: require(accountDebtTwo == 0 || vaultConfig.minAccountSecondaryBorrow[1] <= -accountDebtTwo, "min borrow");
299: }
No prime fees accrue on secondary debt, hence, this debt will never reach a point where it is above the minimum borrow amount.
Impact
Malicious actors can generate vault accounts which cannot be liquidated. Through opening numerous vault positions, Notional can rack up significant exposure and accrue bad debt as a result.
Code Snippet
Tool used
Manual Review
Recommendation
Either allow for multiple currencies to be liquidated or ensure that checkMinBorrow is performed only on the currency which is being liquidated.
Discussion
T-Woodward
True. Also I don't think you need to settle the accounts. If you call liquidateVaultCashBalance I believe min borrow checks will be skipped on all currencies, so you could just deleverage twice to get positive cash balances on each secondary currency and then liquidateVaultCashBalance on each to get both secondary currency debts below min.
0xleastwood
Escalate for 10 USDC
I think this was wrongly classified as medium severity during the judging contest phase. I had confirmed this as a high severity finding with the Notional team prior to submission.
Ultimately, the finding states that users can create any number of vault positions where they only have debt in each secondary currency and no primary currency. They are then able to liquidate their debt below minAccountSecondaryBorrow and therefore prevent any future liquidation. Repeated abuse of this could lead to protocol insolvency.
sherlock-admin
Escalate for 10 USDC
I think this was wrongly classified as
mediumseverity during the judging contest phase. I had confirmed this as ahighseverity finding with the Notional team prior to submission.Ultimately, the finding states that users can create any number of vault positions where they only have debt in each secondary currency and no primary currency. They are then able to liquidate their debt below
minAccountSecondaryBorrowand therefore prevent any future liquidation. Repeated abuse of this could lead to protocol insolvency.
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 issue should be a high
hrishibhat
Result: High Unique Considering this issue as a valid high
sherlock-admin
Escalations have been resolved successfully!
Escalation status:
- 0xleastwood: accepted
jeffywu
Fixed: https://github.com/notional-finance/contracts-v2/pull/138
xiaoming9090
@0xleastwood + @xiaoming9090: Verified. Fixed in PR https://github.com/notional-finance/contracts-v2/pull/138
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 minimum borrow check is skipped during vault settlement and only one currency's debt can be reduced at a time during liquidation, so accounts with multiple secondary debts below the minimum cannot be liquidated.
Impact
Malicious actors could create vault accounts that cannot be liquidated, potentially leading to significant exposure and bad debt for the protocol.
What the attacker needed
A vault account with secondary debt; ability to self-liquidate; vault account reaches maturity
The fix
The issue was fixed by allowing multiple currencies to be liquidated or by checking the minimum borrow only on the currency being liquidated.
How it was found
- Create a vault account with secondary debt in two currencies and no primary debt.
- Self-liquidate to set up debt and cash holdings such that after settlement both secondary debts are below the minimum.
- Settle the vault account, skipping the minimum borrow check.
- Attempt to liquidate the account; the minimum borrow check fails because both debts are checked.
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 this lending protocol, vault accounts must keep a minimum amount of debt in each currency. If debt falls below that minimum, the account cannot be liquidated normally. The report shows a way to push debt below the minimum during settlement, so later liquidation attempts fail, leaving bad debt.
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.