# `Market::liquidate()` will not work when most of the liquidity is borrowed due to wrong liquidator `transferFrom()` order

Market.liquidate pulls liquidator funds via transferFrom only after seizing collateral, so self-market liquidations revert when most liquidity is borrowed.

- Payout: Contest reward
- Severity: medium
- Program: Interest Rate Model
- Credited: 0x73696d616f
- Disclosed: 2024-04-06
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-04-interest-rate-model-judging/issues/118
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-04-interest-rate-model%3AM-11
- Tags: domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:liquidation

**Target:** Market.liquidate() in Solidity lending protocol
**Root cause:** transferFrom of the liquidator's repayment assets happens at the end of liquidate(), after collateral is seized and transferred out; when seizeMarket == repayMarket and most liquidity is borrowed, the contract lacks assets to send the liquidator.
**Steps:**
1. Deploy Market with adjustFactor 0.9e18.
2. ALICE deposits 10_000 ether DAI and borrows 8100 ether (90% of 90% LTV).
3. skip(10 days) so interest accrues and ALICE becomes liquidatable.
4. Liquidator approves market for max and calls `market.liquidate(ALICE, type(uint256).max, market)`.
5. Call reverts because collateral transfer to liquidator occurs before liquidator's transferFrom repays the debt.
**How found:** Code reading of liquidate() ordering: noticed transferFrom at line 613 occurs after seize/withdraw logic at line 693, hypothesized self-market liquidation fails under high utilization, confirmed with Foundry PoC.
**Exploitation:** Not an attack; a liquidator cannot execute liquidation in the self-market high-utilization case, so bad debt accumulates. Workaround requires depositing nearly double the funds first.
**Insight:** In liquidation flows, check the ordering of pulling repayment funds versus releasing seized collateral; when repay and seize markets coincide, the contract can be momentarily insolvent and revert, blocking all liquidations under high utilization.
