Skip to content
Business logic Audit finding Intermediate

`deleverageAccount` can still be called when a vault is paused

The deleverageAccount function in VaultAccountAction.sol does not check the vault's ENABLED flag, so it can still be called while a vault is paused. A liquidator could therefore liquidate vault account positions even when the vault is meant to be paused.

Arbitrary-Execution Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-09-notional-judging/issues/17

Found by

Arbitrary-Execution

Summary

deleverageAccount can still be called when a vault is paused

Vulnerability Detail

Every vault has an ENABLED flag that can be toggled on an off, and is used to prevent certain vault account functions from being called in VaultAccountAction.sol when a vault is 'Paused'; these functions include: enterVault and rollVaultPosition. However, deleverageAccount is still able to be called even when a vault is paused.

Impact

When the ENABLED flag is not set, meaning a vault is paused, liquidators will still be able to liquidate vault account positions. However, users are still able to call exitVault to either fully exit their position or lower their collateral ratio if necessary to avoid liquidation.

Code Snippet

https://github.com/notional-finance/contracts-v2/blob/cf05d8e3e4e4feb0b0cef2c3f188c91cdaac38e0/contracts/external/actions/VaultAccountAction.sol#L261

Failing test (add to tests/stateful/vaults/test_vault_deleverage.py):

PYTHON3
def test_deleverage_paused(environment, accounts, vault):
    environment.notional.updateVault(
        vault.address,
        get_vault_config(currencyId=2, flags=set_flags(0, ENABLED=False)),
        100_000_000e8,
    )
    maturity = environment.notional.getActiveMarkets(1)[0][1]

    environment.notional.enterVault(
        accounts[1], vault.address, 25_000e18, maturity, 100_000e8, 0, "", {"from": accounts[1]}
    )
    vault.setExchangeRate(0.85e18)
    (cr, _, _) = environment.notional.getVaultAccountCollateralRatio(accounts[1], vault)
    assert cr < 0.2e9

    # would expect this call to revert when a vault is paused
    with brownie.reverts("Cannot Enter"):
        environment.notional.deleverageAccount(
            accounts[1], vault.address, accounts[2], 25_000e18, False, "", {"from": accounts[2]}
        )

Tool used

Manual Review

Recommendation

Consider adding the following require statement to deleverageAccount:

Solidity
require(vaultConfig.getFlag(VaultConfiguration.ENABLED), "Cannot Enter");

Discussion

jeffywu

@T-Woodward we can consider adding this, in general we like to allow liquidations to occur regardless but it's possible that we may need to disable deleverage due to some potential vulnerability.

T-Woodward

Yes I still think it's riskier to disable deleveraging in a pause scenario. I suppose we could add a third state "pause with no liquidations" or something if you want to @jeffywu .

jeffywu

Yes, I think adding a separate pause state will be worthwhile.

The original report as published on Sherlock, by Arbitrary-Execution. 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

Likely the deleverageAccount function lacks the same ENABLED flag check that other vault account functions such as enterVault and rollVaultPosition have.

Impact

While a vault is paused, liquidators could still liquidate vault account positions, although users can still call exitVault to reduce their collateral ratio and avoid liquidation.

What the attacker needed

A vault that has been paused; a vault account position below the collateral threshold; a liquidator to call deleverageAccount

The fix

The recommendation is to add a require statement to deleverageAccount that checks the vault's ENABLED flag; the discussion suggests a separate pause state that also disables liquidations may be worthwhile, but the text does not say it was fixed.

How it was found

  1. Pause the vault by updating its configuration with the ENABLED flag unset.
  2. Enter a vault position for an account.
  3. Lower the vault exchange rate so the account's collateral ratio falls below the threshold.
  4. Call deleverageAccount on the paused vault and observe that it does not revert.

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 that holds users' funds and positions. The team added a pause switch to stop certain actions in an emergency, but one action, liquidating a user's position, was not wired to that switch. So even with the vault paused, someone could still trigger a 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.

More by Arbitrary-Execution

View all

1 more disclosed report, 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.