# Depositor can cease all alchemist operations under certain conditions

Repaying debt without reducing cumulativeEarmarked lets totalDebt fall below it, underflowing _earmark and freezing all Alchemist operations.

- Payout: Contest reward
- Severity: high
- Program: Alchemix
- Credited: rokinot
- Disclosed: 2025-07-15
- Write-up quality: 7/10
- Original: https://cdn.cantina.xyz/reports/cantina_competition_alchemix_may2025.pdf#3.1.9
- Library page: https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.9
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:cantina sev:high tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** AlchemistV3.sol _earmark/_subDebt accounting
**Root cause:** _earmark assumes totalDebt >= cumulativeEarmarked, but repay() reduces totalDebt via _subDebt without capping cumulativeEarmarked, so a large repay makes totalDebt < cumulativeEarmarked and the subtraction underflows.
**Steps:**
1. Deposit yield and mint debt via `alchemist.mint(tokenId, 50e18, ...)`
2. Have another user create a Transmuter redemption (`createRedemption(30e18)`) so earmarking accrues
3. Advance blocks so cumulativeEarmarked grows toward totalDebt
4. Repay nearly full debt: `alchemist.repay(yieldToRepayFullDebt - 1, tokenId)`
5. Advance one block and call `alchemist.poke(tokenId)`; `_earmark` underflows (Panic 0x11)
**How found:** Code-reading of _earmark revealed an implicit invariant totalDebt >= cumulativeEarmarked; compared burn (which caps amount by debt-earmark difference) against repay (which never decreases cumulativeEarmarked), spotting the asymmetry.
**Exploitation:** Attacker with sufficiently large debt repays in a way that drops totalDebt below cumulativeEarmarked; subsequent _earmark calls revert, bricking mint, burn, deposit, withdraw, repay, liquidate and poke, trapping other users' funds.
**Insight:** When a function guards an implicit invariant via subtraction, audit every state-mutating path that lowers the minuend (here _subDebt) for one that fails to also lower the subtrahend; compare sibling functions like burn vs repay for asymmetric caps.
