`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.
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
Failing test (add to tests/stateful/vaults/test_vault_deleverage.py):
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:
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.
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
- Pause the vault by updating its configuration with the ENABLED flag unset.
- Enter a vault position for an account.
- Lower the vault exchange rate so the account's collateral ratio falls below the threshold.
- 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.