# Missing enough exogenous collateral check in VaultManagerV2::liquidate makes the liquidation revert even if (DYAD Minted > Non Kerosene Value)

DYAD VaultManagerV2.liquidate only checks total CR >= 150%, so positions with non-kerosene value below DYAD minted cannot be liquidated, breaking the 1:1 backing invariant.

- Payout: Audit contest
- Severity: high
- Program: DYAD
- Found by: shikhar229169
- Disclosed: 2024-06-17
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-04-dyad-findings/issues/338
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-07
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:liquidation vuln:oracle-manipulation

**Target:** VaultManagerV2.liquidate on-chain vault liquidation
**Root cause:** liquidate() reverts with CrTooHigh whenever total CR (including kerosene) >= MIN_COLLATERIZATION_RATIO, without checking that non-kerosene value still covers minted DYAD, so under-collateralized-in-exogenous positions are unliquidatable.
**Steps:**
1. Mint DNFT, add ethVault and addKerosene wstEth vault.
2. Deposit 10 WETH and 10 wstETH; mint DYAD equal to getNonKeroseneValue(id).
3. Manipulate WETH oracle price down to 90% via OracleMock etch.
4. Confirm getNonKeroseneValue(id) < dyadToMint.
5. Call `vaultManager.liquidate(id, liquidatorId)` from a liquidator with a DNFT; observe revert `CrTooHigh`.
6. Run: `forge test --mt test_LiquidationReverts_EvenIfVaultHasNotEnoughExoCollateral --fork-url $ETH_MAINNET_RPC_URL`
**How found:** Code review of liquidate() comparing its CR-only guard against the exogenous-collateral checks present in mintDyad()/withdraw(); built a Foundry fork PoC manipulating the WETH oracle to demonstrate the revert.
**Exploitation:** No direct theft; the flaw is that a position whose exogenous collateral falls below minted DYAD (while kerosene props total CR >= 150%) cannot be liquidated, letting bad debt persist and threatening DYAD's 1:1 backing/depeg.
**Escalation:** Correlated ETH price drop can push many positions below 1:1 exogenous backing simultaneously, breaking protocol-wide TVL > DYAD supply invariant.
**Insight:** When a protocol enforces a stricter collateral invariant on mint/withdraw than on liquidate, positions can drift into a state the stricter invariant forbids but liquidation cannot correct — diff the guards across mint, withdraw, and liquidate paths.

## Proof of concept (copied exactly from the original report)

**Foundry test proving liquidation reverts despite insufficient exogenous collater**

```
function test_LiquidationReverts_EvenIfVaultHasNotEnoughExoCollateral() public {
  address user = makeAddr("user");
  vm.deal(user, 100 ether);

  Licenser licenser = Licenser(MAINNET_VAULT_MANAGER_LICENSER);
  vm.prank(MAINNET_OWNER);
  licenser.add(address(contracts.vaultManager));

  DNft dnft = DNft(MAINNET_DNFT);

  vm.startPrank(user);

  uint256 id = dnft.mintNft{value: 10 ether}(user);

  // user adds vault
  contracts.vaultManager.add(id, address(contracts.ethVault));
  contracts.vaultManager.addKerosene(id, address(contracts.wstEth));

  // user adds weth to the vault
  deal(MAINNET_WETH, user, 10 ether);       // get 10 weth to the user
  ERC20(MAINNET_WETH).approve(address(contracts.vaultManager), 10 ether);
  contracts.vaultManager.deposit(id, address(contracts.ethVault), 10 ether);

  // user adds wsteth to the vault
  deal(MAINNET_WSTETH, user, 10 ether);       // get 10 wsteth to the user
  ERC20(MAINNET_WSTETH).approve(address(contracts.vaultManager), 10 ether);
  contracts.vaultManager.deposit(id, address(contracts.wstEth), 10 ether);

  // user mints DYAD token
  uint256 nonKeroseneValue = contracts.vaultManager.getNonKeroseneValue(id);

  // user mints DYAD equal to the usd value of their non-kerosene collateral
  uint256 dyadToMint = nonKeroseneValue;
  contracts.vaultManager.mintDyad(id, dyadToMint, user);

  // now the value of weth falls to 90%
  _manipulateWethPrice();

  // now get the nonKeroseneValue
  uint256 newNonKeroseneValue = contracts.vaultManager.getNonKeroseneValue(id);

  // non kerosene usd value reduced, as weth price reduced
  assert(newNonKeroseneValue < dyadToMint);

  // now it is intended that the user should be liquidated by a liquidator
  // but due to missing exogenous collateral check, the liquidation will not happen

  vm.stopPrank();


  address liquidator = makeAddr("liquidator");
  vm.deal(liquidator, 100 ether);

  vm.startPrank(liquidator);

  uint256 liquidatorId = dnft.mintNft{value: 10 ether}(liquidator);

  // the liquidation reverts as mentioned, even if (dyadMinted > nonKeroseneValue) 
  // thus shows unintended behaviour
  vm.expectRevert(IVaultManager.CrTooHigh.selector);
  contracts.vaultManager.liquidate(id, liquidatorId);

  vm.stopPrank();
}
```

**WETH price manipulation helper for the PoC**

```
function _manipulateWethPrice() internal {
  (, int256 ans, , , ) = contracts.ethVault.oracle().latestRoundData();
  OracleMock oracleMock = new OracleMock(uint256(ans));
  vm.etch(address(contracts.ethVault.oracle()), address(oracleMock).code);
  vm.warp(1);
  OracleMock(address(contracts.ethVault.oracle())).setPrice(uint256(ans) * 90e18 / 100e18);
}
```

