# Attacker/partial liquidator can extend Liquidation action by resetting $.liquidationStart[_agent] to 0.

Partial liquidation repays debt and closes liquidation before slashing delegation, so health appears healthy and resets liquidationStart, blocking other liquidators.

- Payout: Audit contest
- Severity: medium
- Program: Cap
- Found by: Bigsam
- Disclosed: 2025-07-07
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-07-cap-judging/issues/145
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-07-cap%3AM-1
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:business-logic vuln:liquidation

**Target:** LiquidationLogic.liquidate / _closeLiquidation in lending pool
**Root cause:** liquidate() recomputes health after BorrowLogic.repay but before IDelegation.slash, so the health check uses reduced debt with unslashed delegation and can pass >=1e27, prematurely calling _closeLiquidation which zeroes $.liquidationStart[_agent].
**Steps:**
1. Agent health drops below 1e27 and liquidation is opened, starting grace period.
2. After grace passes, attacker calls `liquidate` with a small `params.amount` (few wei) to partially repay.
3. BorrowLogic.repay burns debt, reducing totalDebt.
4. ViewLogic.agent recomputes health with reduced debt but delegation not yet slashed; health >= 1e27.
5. `_closeLiquidation` sets `$.liquidationStart[_agent] = 0`.
6. Next liquidator's `validateLiquidation` sees start=0 and reverts `GracePeriodNotOver` (block.timestamp <= start+grace), forcing a new liquidation and grace period.
**How found:** Code review of liquidate() ordering: health recomputed after repay but before slash; noticed _closeLiquidation zeroes liquidationStart, and validateLiquidation uses start+grace, so resetting start blocks others.
**Exploitation:** Attacker (or partial liquidator) waits for grace period, submits a minimal partial liquidation. The premature close resets liquidationStart to 0, so subsequent liquidators must reopen liquidation and wait a new grace period. Attacker profits from the partial liquidation bonus/fee and can repeat to extend the window.
**Insight:** In liquidation flows, always verify state-mutating health checks occur after all balance-changing operations (repay AND slash/seize). A health check between repay and collateral slash can falsely report health and trigger premature state resets like liquidationStart=0.

