# Lend offer can be deleted multiple times

Debita lend offer in perpetual mode with zero availableAmount can be deleted repeatedly via changePerpetual, corrupting activeOrdersCount and blocking deletion of other orders.

- Payout: Audit contest
- Severity: medium
- Program: Debita
- Found by: 0x37
- Disclosed: 2024-10-31
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-10-debita-judging/issues/119
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-1
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** DebitaLendOffer-Implementation / DLOFactory lend order registry
**Root cause:** changePerpetual() calls deleteOrder() when perpetual is set false and availableAmount is 0 but never sets isActive=false, so the same order can be deleted repeatedly. Each deleteOrder decrements activeOrdersCount and rewrites the index mapping, corrupting the active orders array.
**Steps:**
1. Create a lend offer with perpetual=true.
2. Match the offer so availableAmount becomes 0.
3. Call `changePerpetual(false)` repeatedly; each call passes `require(isActive)` and re-invokes `IDLOFactory.deleteOrder(address(this))`.
4. activeOrdersCount decrements each time, overwriting allActiveLendOrders entries and zeroing indices of other orders.
5. Other lend orders can no longer be deleted/cancelled correctly.
**How found:** Code review of changePerpetual() noting the missing isActive=false assignment before deleteOrder, combined with the perpetual-mode + zero availableAmount precondition.
**Exploitation:** Owner of a lend offer repeatedly calls changePerpetual(false) to drive activeOrdersCount down and corrupt the factory's allActiveLendOrders array, breaking deletion for all other lend orders.
**Insight:** When a state-changing function both mutates config and triggers a registry removal, check whether the guard flag (isActive) is cleared; repeated calls to a delete path that decrements a shared counter corrupt index arrays for unrelated entries.

