# NFTPositionManager's `repay()` and `repayETH()` are unavailable unless preceded atomically by an accounting updating operation

NFTPositionManager.repay()/repayETH() revert standalone because previousDebtBalance is read before pool.repay() accrues interest, so the debt-delta check mismatches.

- Payout: Audit contest
- Severity: medium
- Program: New Scope
- Found by: 000000
- Disclosed: 2024-06-27
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-06-new-scope-judging/issues/467
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-14
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:incomplete-fix technique:source-review vuln:accounting-error vuln:business-logic

**Target:** NFTPositionManager repay/repayETH in a lending pool (Solidity/EVM)
**Root cause:** _repay() reads pool.getDebt() before pool.repay() calls reserve.updateState(), which bumps borrowIndex for elapsed interest; the stale previousDebtBalance makes previousDebtBalance-currentDebtBalance < repaid.assets, tripping BalanceMisMatch.
**Steps:**
1. Deploy pool with positive borrow rate and outstanding debt; let time pass since lastUpdateTimestamp.
2. Call NFTPositionManager.repay(params) standalone (no other pool op in same tx).
3. _repay reads previousDebtBalance via getDebt() using stale borrowIndex.
4. pool.repay() -> executeRepay -> reserve.updateState() -> _updateIndexes bumps borrowIndex, then repays.
5. currentDebtBalance reflects both interest accrual and repayment; check `previousDebtBalance - currentDebtBalance != repaid.assets` reverts with BalanceMisMatch.
6. Workaround: atomically call pool.forceUpdateReserve(asset) before repay, or bundle with another state-updating op.
**How found:** Code reading of _repay() ordering: noticed getDebt() called before pool.repay(), then traced into BorrowLogic.executeRepay -> ReserveLogic.updateState/_updateIndexes to see borrowIndex mutated mid-call, making the pre-read stale.
**Exploitation:** Not an attack; protocol malfunction. A user attempting to repay before liquidation has all standalone repay txs revert, position gets liquidated, incurring liquidation penalty.
**Insight:** When a wrapper reads pool state before and after an external call to compute a delta, check whether the callee lazily accrues interest (borrowIndex/supplyIndex) inside that call; any pre-read of index-derived values will be stale and break equality checks.

