# LMPVault.updateDebtReporting could underflow because of subtraction before addition

LMPVault.updateDebtReporting subtracts a rounded-up debt burn before adding, letting repeated 1-share redeems make totalDebt < prevNTotalDebt and revert with underflow.

- Payout: Contest reward
- Severity: medium
- Program: Tokemak
- Credited: 0x007
- Disclosed: 2023-06-30
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/675
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-06-tokemak%3AM-14
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos vuln:precision-loss

**Target:** LMPVault.updateDebtReporting / LMPDebt debt accounting
**Root cause:** totalDebtBurn is computed with Math.Rounding.Up while prevNTotalDebt (currentDebt) is scaled with rounding down, so accumulated rounded-up burns can push totalDebt below prevNTotalDebt; the expression subtracts before adding, causing underflow.
**Steps:**
1. Set up vault with totalDebt=1,000,002 and totalSupply=1,000,000 (ratio ~1.000002).
2. Call `_lmpVault.redeem(1, address(this), address(this))` — burns 2 debt due to Rounding.Up, totalDebt becomes 1,000,000.
3. Call `redeem(1, ...)` again — totalDebt becomes 999,998.
4. Call `_lmpVault.updateDebtReporting(_destinations)` — prevNTotalDebt = currentDebt*originalShares/ownedShares rounds down to 1,000,000 > totalDebt, so `totalDebt - prevNTotalDebt` underflows and reverts.
**How found:** Noticed the asymmetric rounding: totalDebtBurn uses Math.Rounding.Up while currentDebt uses integer division (round down), then reasoned that repeated small redeems could make totalDebt < prevNTotalDebt and that the subtraction-before-addition ordering would underflow.
**Exploitation:** Attacker repeatedly redeems 1 share (each burning 2 debt units due to Rounding.Up) until totalDebt falls below the rounded-down prevNTotalDebt, then triggers updateDebtReporting which reverts on underflow, bricking debt reporting and locking withdrawals (noNavDecrease).
**Insight:** When auditing debt/share accounting, compare rounding directions of every paired mulDiv: a Rounding.Up subtraction paired with a Rounding.Down recomputation lets tiny repeated operations drift the stored total below the recomputed baseline, and subtraction-before-addition turns that drift into a hard revert.
