Skip to content
Access control Audit finding Advanced

`deleverageAccount` can be used by an address to enter a vault that would otherwise be restricted by the `requireValidAccount` check in `enterVault`

The `deleverageAccount` function allows a liquidator to receive vault shares and implicitly enter a vault without passing the `requireValidAccount` check that `enterVault` enforces. This lets system-level accounts, which are normally restricted from entering vaults, obtain a vault position.

Arbitrary-Execution Follow

Originally disclosed on Sherlock

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

Found by

Arbitrary-Execution

Summary

deleverageAccount can be used by an address to enter a vault that would otherwise be restricted by the requireValidAccount check in enterVault

Vulnerability Detail

When enterVault in VaultAccountAction.sol is called, the first function that is called is requireValidAccount. This function checks to ensure that the passed-in account parameter is not a system-level account address:

Solidity
require(account != Constants.RESERVE); // Reserve address is address(0)
require(account != address(this));
(
    uint256 isNToken,
    /* incentiveAnnualEmissionRate */,
    /* lastInitializedTime */,
    /* assetArrayLength */,
    /* parameters */
) = nTokenHandler.getNTokenContext(account);
require(isNToken == 0);

With the above checks, requireValidAccount ensures that any Notional system-level account cannot enter a vault. However, deleverageAccount in VaultAccountAction.sol allows liquidators to transfer vault shares from a liquidated account into their own account. In the case that a liquidator is not already entered into a vault, then deleverageAccount will instantiate a vault account for them (using _transferLiquidatorProfits) before depositing the liquidated account's vault shares into the newly-instantiated account. This effectively circumvents the requireValidAccount check in enterVault.

Impact

Any address that would otherwise be restricted from entering vaults via the requireValidAccount check would be able to circumvent that function using deleverageAccount. I assume these system-level accounts are restricted from entering vaults as they have access to internal Notional state and are used across the protocol, so having them be able to enter vaults could negatively impact Notional.

Assuming that all the relevant Notional system accounts are smart contracts that do not allow arbitrary calls, then having any of the system accounts themselves trigger this issue is infeasible. However, as a result of another issue it is possible for a vault to force an arbitrary address to deleverage accounts, which could be used to force a Notional system account to enter into a vault.

Code Snippet

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

PoC (add to tests/stateful/vaults/test_vault_deleverage.py);

PYTHON3
def test_deleverage_account_instantiate_liquidator_maturity(environment, accounts, vault):
    environment.notional.updateVault(
        vault.address,
        get_vault_config(currencyId=2, flags=set_flags(0, ENABLED=True)),
        100_000_000e8,
    )
    maturity = environment.notional.getActiveMarkets(1)[0][1]
    systemAccount = accounts.at(environment.nToken[1], force=True)
    environment.token["DAI"].transfer(systemAccount, 10_000_000e18, {"from": accounts[0]})
    environment.cToken["DAI"].transfer(systemAccount, 10_000_000e8, {"from": accounts[0]})
    environment.token["DAI"].approve(environment.notional.address, 2 ** 256 - 1, {"from": systemAccount})
    environment.cToken["DAI"].approve(environment.notional.address, 2 ** 256 - 1, {"from": systemAccount})

    with brownie.reverts():
        # nToken address is not allowed to enter a vault
        environment.notional.enterVault(
            systemAccount,
            vault.address,
            100_000e18,
            maturity,
            100_000e8,
            0,
            "",
            {"from": systemAccount},
        )

    environment.notional.enterVault(
        accounts[1], vault.address, 50_000e18, maturity, 200_000e8, 0, "", {"from": accounts[1]}
    )

    vault.setExchangeRate(0.95e18)

    environment.notional.deleverageAccount(
        accounts[1], vault.address, systemAccount, 1_000e8, True, "", {"from": systemAccount}
    )

    # System account now has a position in the vault
    systemAccountInfo = environment.notional.getVaultAccount(systemAccount, vault)
    assert systemAccountInfo["maturity"] != 0

Tool used

Manual Review

Recommendation

Consider updating the require statement in _transferLiquidatorProfits to the following:

Solidity
require(liquidator.maturity == maturity, "Vault Shares Mismatch"); // dev: has vault shares

Removing the option of allowing addresses that do not have a maturity in the respective vault to receive shares and therefore implicitly enter a vault prevents Notional system accounts from being able to enter into vaults.

Discussion

jeffywu

Not sure why this issue was closed, but I think it is a valid suggestion. We can also simply add requireValidAccount(liquidator) to deleverage vault.

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` path creates a vault account for the liquidator via `_transferLiquidatorProfits` without applying the `requireValidAccount` restriction used by `enterVault`.

Impact

Any address restricted by `requireValidAccount` could enter a vault through liquidation, though forcing a system account to do so depends on another issue that lets a vault force an arbitrary address to deleverage.

What the attacker needed

A liquidatable vault position exists; attacker can call deleverageAccount

The fix

The `require` in `_transferLiquidatorProfits` should be changed to require that the liquidator already has a maturity in the vault, or `requireValidAccount(liquidator)` should be added to the deleverage path.

How it was found

  1. Confirm that a system-level account is rejected by `enterVault` due to `requireValidAccount`.
  2. Have another account enter the vault normally.
  3. Change the vault exchange rate so the position can be liquidated.
  4. Call `deleverageAccount` from the system-level account as liquidator.
  5. Observe that the system-level account now has a vault position.

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 restricted area in a smart contract. The normal way in checks who you are and blocks some special system accounts. A separate liquidation function lets someone take over another person's vault position, and it does not run that same check, so a blocked account can get in through the side door.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

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.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.