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.
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.
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
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
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
- A large portion of the vault account is liquidated, leaving a positive cash balance.
- Interest accrues, increasing the cash balance further.
- The owner calls exitVault, which sets tempCashBalance to the positive amount.
- lendToExitVault is called; if the cost to lend is less than the cash balance, tempCashBalance remains positive.
- 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.