# Attacker will prevent lenders from canceling lend orders and block non-perpetual lend orders matching.

Missing isActive check in addFunds lets attacker re-add funds to a canceled lend order, repeatedly decrementing activeOrdersCount to 0 and bricking cancelOffer and matchOffersV3.

- Payout: Audit contest
- Severity: medium
- Program: Debita
- Found by: 0x37
- Disclosed: 2024-10-31
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-10-debita-judging/issues/246
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-6
- 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 vuln:dos

**Target:** DebitaLendOffer-Implementation / DebitaLendOfferFactory (Solidity lending protocol)
**Root cause:** addFunds lacks an isActive check, so funds can be added to an already-canceled lend order, letting cancelOffer be re-invoked and deleteOrder decrement activeOrdersCount repeatedly. Once activeOrdersCount hits 0, deleteOrder underflows and reverts.
**Steps:**
1. Create a lend order via `DLOFactory::createLendOrder` (increments activeOrdersCount).
2. Call `DLOImplementation::cancelOffer` -> `deleteOrder` decrements activeOrdersCount.
3. Call `DLOImplementation::addFunds(1)` to re-fund the now-inactive order, satisfying `require(availableAmount > 0)` in cancelOffer.
4. Repeat cancelOffer/addFunds until `activeOrdersCount == 0`.
5. Any subsequent `cancelOffer` or `matchOffersV3` that reaches `deleteOrder` reverts with arithmetic underflow.
**How found:** Researcher noticed addFunds has no isActive guard, allowing re-funding a canceled order, and traced that cancelOffer's require(availableAmount>0) can be re-satisfied to repeatedly call deleteOrder, driving the shared counter to underflow.
**Exploitation:** Attacker repeatedly cycles cancelOffer and addFunds(1 wei) on their own lend order to drive the factory's activeOrdersCount to zero. This bricks deleteOrder for all users, blocking every lender's cancelOffer and preventing non-perpetual lend orders from being fully matched via matchOffersV3.
**Insight:** When a shared counter is decremented in a delete path, check whether the delete can be re-triggered on the same entity (e.g. re-funding a canceled order) to drive the counter to zero and cause underflow DoS across all users.

## Proof of concept (copied exactly from the original report)

**Attack sequence cancelOffer/addFunds loop**

```
vm.startPrank(lender1);
        DLOImplementation(lendOffer1).cancelOffer();

        // addFunds (1 wei)
        wETHContract.approve(lendOffer1, 3);
        DLOImplementation(lendOffer1).addFunds(1);

        // cancelOffer again -> DLOFactory::activeOrdersCount == 1
        DLOImplementation(lendOffer1).cancelOffer();

        // addFunds (1 wei)
        DLOImplementation(lendOffer1).addFunds(1);

        // lender1 cancels the offer -> DLOFactory::activeOrdersCount == 0
        DLOImplementation(lendOffer1).cancelOffer();

        vm.stopPrank();

        // check DLOFactory::activeOrdersCount == 0
        assertEq(DLOFactoryContract.activeOrdersCount(), 0);
```

