# Attacker can profit from discount fees

Discount penalty fee minted to yDUSD vault scales with total debt, not discounted volume, letting a vault-shareholder attacker profit from self-triggered discounts.

- Payout: Audit contest
- Severity: high
- Program: DittoETH
- Found by: d3e4
- Disclosed: 2024-07-29
- Write-up quality: 8/10
- Original: https://github.com/code-423n4/2024-07-dittoeth-findings/issues/18
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-dittoeth%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** DittoETH _matchIsDiscounted discount penalty fee / yDUSD vault
**Root cause:** The discountPenaltyFee is applied to (almost) the entire ercDebt rather than to the amount actually traded at a discount, so minted dUSD fees can exceed the attacker's implied trade loss.
**Steps:**
1. Deposit dUSD into yDUSD vault to hold shares (e.g. 1,000,000 of 2,000,000 total, after 1,000,000 already deposited by users).
2. Ensure enough days elapsed so discountMultiplier makes discountPct large (k>0.5 after ~2 days).
3. Place a limit ask at 99% of savedPrice for ercAmount ≈ 0.01*ercDebt/k (e.g. 454,546 ether) to trigger discount.
4. Discount penalty fee 0.1% of ercDebt mints newDebt dUSD to the yDUSD vault (e.g. 50,000 ether).
5. Trade back at savedPrice, withdraw escrow, then proposeWithdraw and withdraw vault shares after 7 days to realize profit.
**How found:** Code reading of _matchIsDiscounted: noticed discountPenaltyFee applied to ercDebtMinusTapp (total debt) rather than discountedErcMatched, hypothesizing minted fees could exceed the discount loss; built a Foundry PoC to confirm.
**Exploitation:** Attacker holds yDUSD shares, deliberately trades at a >1% discount to trigger the discount penalty fee which mints dUSD proportional to total ercDebt into the vault; attacker's share of minted fees exceeds the trade loss, netting profit (~20,454 dUSD on a 4,545.46 dUSD loss in the PoC).
**Escalation:** Attacker owning all vault shares captures the entire fee; could self-trade to eliminate the trade loss entirely.
**Insight:** When a penalty/fee is minted to a vault the attacker can hold shares in, compare the fee base (total debt) against the triggering quantity (discounted volume) — if the fee base is much larger, the attacker can profit by self-triggering.

