# User is unable to partially payback loan if they aren't able to post enough isoUSD to bring them back to minOpeningMargin

closeLoan reverts unless remaining debt meets minOpeningMargin, blocking partial repayments and forcing users near liquidation to default.

- Payout: Contest reward
- Severity: high
- Program: Isomorph
- Credited: 0x52
- Disclosed: 2022-11-05
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2022-11-isomorph-judging/issues/161
- Library page: https://bugbountylibrary.com/r/sherlock%3A2022-11-isomorph%3AH-1
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:business-logic vuln:liquidation

**Target:** Vault_Synths.sol closeLoan lending contract
**Root cause:** closeLoan enforces the minOpeningMargin check on any remaining debt even when the user removes zero collateral, so partial repayments that don't restore the opening margin revert.
**Steps:**
1. User has an open loan near liquidation margin.
2. Call `closeLoan(_collateralAddress, 0, _USDToVault)` with a partial repayment.
3. Contract computes `outstandingisoUSD` and `borrowMargin = outstandingisoUSD * minOpeningMargin / LOAN_SCALE`.
4. `require(colInUSD > borrowMargin)` fails because remaining collateral still sits below minOpeningMargin.
5. Transaction reverts; user cannot reduce debt without also posting enough isoUSD to reach minOpeningMargin.
**How found:** Code review of closeLoan's margin check: noticed the minOpeningMargin requirement applies even when no collateral is withdrawn, conflating opening-margin with repayment.
**Escalation:** Users unable to deleverage get liquidated when a small repayment would otherwise have saved the position.
**Insight:** When auditing lending/perp contracts, check whether opening-margin constraints are also applied to pure-repayment paths; a margin check that ignores whether collateral is being removed can lock users out of deleveraging.
