Skip to content
Business logic Audit finding Intermediate

Vault account might not be able to exit after liquidation

After a liquidation leaves a vault account with a positive cash balance, the exit function reverts because it requires the temporary cash balance to be zero. The vault owner cannot exit and their assets remain stuck in the protocol.

xiaoming90 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-03-notional-judging/issues/192

Found by

xiaoming90 + 0xleastwood

Summary

The vault exit might fail after a liquidation event, leading to users being unable to main their positions.

Vulnerability Detail

Assume that a large portion of the vault account gets liquidated which results in a large amount of cash deposited into the vault account's cash balance. In addition, interest will also start accruing within the vault account's cash balance.

Let $x$ be the primaryCash of a vault account after a liquidation event and interest accrual.

The owner of the vault account decided to exit the vault by calling exitVault. Within the exitVault function, the vaultAccount.tempCashBalance will be set to $x$.

Next, the lendToExitVault function is called. Assume that the cost in prime cash terms to lend an offsetting fCash position is $-y$ (primeCashCostToLend). The updateAccountDebt function will be called, and the vaultAccount.tempCashBalance will be updated to $x + (-y) \Rightarrow x - y$. If $x > y$, then the new vaultAccount.tempCashBalance will be more than zero.

Subsequently, the redeemWithDebtRepayment function will be called. However, since vaultAccount.tempCashBalance is larger than zero, the transaction will revert, and the owner cannot exit the vault.

https://github.com/sherlock-audit/2023-03-notional/blob/main/contracts-v2/contracts/internal/vaults/VaultConfiguration.sol#L429

Solidity
File: VaultConfiguration.sol
424:             if (vaultAccount.tempCashBalance < 0) {
425:                 int256 x = vaultConfig.primeRate.convertToUnderlying(vaultAccount.tempCashBalance).neg();
426:                 underlyingExternalToRepay = underlyingToken.convertToUnderlyingExternalWithAdjustment(x).toUint();
427:             } else {
428:                 // Otherwise require that cash balance is zero. Cannot have a positive cash balance in this method
429:                 require(vaultAccount.tempCashBalance == 0);
430:             }

Impact

The owner of the vault account would not be able to exit the vault to main their position. As such, their assets are stuck within the protocol.

Code Snippet

https://github.com/sherlock-audit/2023-03-notional/blob/main/contracts-v2/contracts/internal/vaults/VaultConfiguration.sol#L429

Tool used

Manual Review

Recommendation

Consider refunding the excess positive vaultAccount.tempCashBalance to the users so that vaultAccount.tempCashBalance will be cleared (set to zero) before calling the redeemWithDebtRepayment function.

Discussion

jeffywu

Fixed in: https://github.com/notional-finance/contracts-v2/pull/133

xiaoming9090

@0xleastwood + @xiaoming9090: Verified. Fixed in PR https://github.com/notional-finance/contracts-v2/pull/133

The original report as published on Sherlock, by xiaoming90 + 0xleastwood. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

The exit logic requires the temporary cash balance to be exactly zero after repaying debt, but a positive balance from liquidation or interest is not refunded, causing a revert.

Impact

The vault owner cannot exit the vault, so their assets are stuck within the protocol.

What the attacker needed

Vault account is liquidated; positive cash balance remains; owner attempts to exit

The fix

The excess positive temporary cash balance should be refunded to the user so it becomes zero before redeemWithDebtRepayment is called; the report states this was fixed in a pull request.

How it was found

  1. A large portion of the vault account is liquidated, leaving a positive cash balance.
  2. Interest accrues, increasing the cash balance further.
  3. The owner calls exitVault, which sets tempCashBalance to the positive amount.
  4. lendToExitVault is called; if the cost to lend is less than the cash balance, tempCashBalance remains positive.
  5. redeemWithDebtRepayment is called, but it reverts because tempCashBalance is not zero.

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 vault is a smart contract where users deposit funds. After a liquidation, the vault may hold extra cash. When the owner tries to withdraw, the code checks that a temporary balance is exactly zero; because it is positive, the withdrawal fails and the funds are locked.

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.

More by xiaoming90

View all

17 more disclosed reports, best first.

More from Notional Update #4

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.