# Flash loan protection mechanism can be bypassed via self-liquidations

DYAD's same-block deposit/withdraw flash-loan guard is bypassed via self-liquidation, letting attackers mint DYAD at ~100% CR and leave bad debt.

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

**Target:** VaultManagerV2 / Vault.kerosine.sol (CDP protocol)
**Root cause:** The idToBlockOfLastDeposit check only guards deposit/withdraw, but liquidate() calls vault.move() to shift collateral to another NFT without updating that NFT's last-deposit block, so the receiving vault can withdraw in the same block.
**Steps:**
1. Flash-loan USDC, deposit into vault A, mint DYAD against inflated kerosene price.
2. Use account C to remove collateral and deflate kerosene price, making A liquidatable.
3. Call `liquidate(idA, idB)` so collateral moves to account B via `vault.move`.
4. Withdraw from vault B in the same block (no DepositedInSameBlock revert).
5. Repay flash loan; account D retains position at ~1.0 CR, protocol accrues bad debt.
**How found:** Code reading: noticed liquidate() uses vault.move() which transfers balances without setting idToBlockOfLastDeposit, unlike deposit(), so the same-block guard is not applied to the receiving account.
**Exploitation:** Attacker flash-loans large USDC, deposits to inflate kerosene price, mints DYAD at inflated valuation, then deflates price via withdrawal, self-liquidates to move collateral to a second NFT, and withdraws same-block to recover funds, leaving an undercollateralized position.
**Escalation:** Repeat steps 5-6 to mint more DYAD each cycle and shift more flashed funds into vault B, amplifying bad debt.
**Insight:** When a protocol guards one fund-movement path (deposit/withdraw) against same-block manipulation, enumerate every other path that moves the same balances (liquidations, transfers, migrations) and check whether the guard state is updated there too.

