# User can get their Kerosene stuck because of an invalid check on withdraw

VaultManagerV2::withdraw compares non-Kerosene collateral value against minted Dyad even when withdrawing Kerosene, permanently locking users' Kerosene collateral.

- Payout: Audit contest
- Severity: high
- Program: DYAD
- Found by: 0xAlix2
- Disclosed: 2024-06-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-dyad-findings/issues/397
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-06
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity vuln:accounting-error vuln:business-logic

**Target:** VaultManagerV2::withdraw in DYAD lending protocol
**Root cause:** The withdraw function applies the exogenous-collateral check (getNonKeroseneValue - value < minted Dyad) regardless of whether the withdrawn vault is a Kerosene or non-Kerosene vault, so Kerosene value is subtracted from non-Kerosene value.
**Steps:**
1. Fork mainnet at block 19703450 and deploy V2 contracts.
2. Bob deposits 1 WETH into ethVault and 25,000 Kerosene into unboundedKerosineVault.
3. Bob mints Dyad equal to getNonKeroseneValue (1 WETH), giving >300% collateral ratio.
4. Bob calls `vaultManagerV2.withdraw(bobNFT, address(unboundedKerosineVaultV2), 1e18, bob)`.
5. Transaction reverts with `NotEnoughExoCollat` because getNonKeroseneValue(100) - 1 < minted Dyad(100).
**How found:** Code review of withdraw's collateral check: noticed the same exogenous-collateral comparison is applied to Kerosene vault withdrawals, where comparing non-Kerosene value against Kerosene withdrawal amount is logically wrong.
**Exploitation:** No direct theft; the flaw blocks legitimate Kerosene withdrawals, trapping user funds in the protocol. A user with sufficient exogenous collateral and minted Dyad cannot withdraw any Kerosene because the check subtracts Kerosene value from the non-Kerosene balance.
**Insight:** When a protocol has two collateral classes with different rules, check that each withdrawal path branches on vault type before applying class-specific invariants; a single shared check will misapply one class's constraint to the other.

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

**Foundry test proving Kerosene withdrawal reverts**

```
function test_CannotWithdrawKerosene() public {
        setUpV2();

        vm.prank(MAINNET_OWNER);
        keroseneV2.transfer(bob, 100_000e18);

        deal(MAINNET_WETH, bob, 1_000e18);
        deal(MAINNET_WETH, address(ethVaultV2), 5_000e18);

        uint256 bobNFT = dNFT.mintNft{value: 1 ether}(bob);

        // Bob adds Weth and Unbounded Kerosene vaults to his NFT
        // Bob deposits 1 Weth and 25,000 Kerosene
        // Bob mints Dyad exactly equal to the non-Kerosene value (1 Weth)
        vm.startPrank(bob);
        wrappedETH.approve(address(vaultManagerV2), type(uint256).max);
        keroseneV2.approve(address(vaultManagerV2), type(uint256).max);

        vaultManagerV2.add(bobNFT, address(ethVaultV2));
        vaultManagerV2.addKerosene(bobNFT, address(unboundedKerosineVaultV2));

        vaultManagerV2.deposit(bobNFT, address(ethVaultV2), 1e18);
        vaultManagerV2.deposit(bobNFT, address(unboundedKerosineVaultV2), 25_000e18);

        vaultManagerV2.mintDyad(bobNFT, vaultManagerV2.getNonKeroseneValue(bobNFT), bob);
        vm.stopPrank();

        // Verify that Bob's collateral ratio is greater than 300%
        assertGt(vaultManagerV2.collatRatio(bobNFT), 2 * vaultManagerV2.MIN_COLLATERIZATION_RATIO());

        vm.roll(1);

        // Bob tries to withdraw 1 Kerosene, reverts
        vm.prank(bob);
        vm.expectRevert(abi.encodeWithSelector(IVaultManager.NotEnoughExoCollat.selector));
        vaultManagerV2.withdraw(bobNFT, address(unboundedKerosineVaultV2), 1e18, bob);
    }
```

