# DebitaIncentives::updateFunds will exit prematurely and not update whitelisted pairs causing loss of funds to lenders and borrowers

DebitaIncentives.updateFunds uses return instead of continue on a non-whitelisted pair, skipping later valid pairs and blocking incentive claims.

- 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/870
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-21
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** DebitaIncentives.updateFunds incentive accounting
**Root cause:** The loop uses `return` instead of `continue` when a principle/collateral pair is not whitelisted, halting the entire function and skipping all subsequent valid pairs.
**Steps:**
1. Whitelist pair (AERO, USDC) via `whitelListCollateral`.
2. Incentivize AERO via `incentivizePair` for epoch 2.
3. Create lend offer with non-whitelisted pair (wETH, USDC) and another with whitelisted pair (AERO, USDC).
4. Create borrow order accepting both wETH and AERO with USDC collateral.
5. Call `matchOffersV3` with both lend orders; non-whitelisted offer at index 0 triggers early `return`.
6. Observe `lentAmountPerUserPerEpoch`, `totalUsedTokenPerEpoch`, `borrowAmountPerEpoch` remain 0; `claimIncentives` reverts with 'No borrowed or lent amount'.
**How found:** Code review of the updateFunds loop: noticed `return` inside the for-loop on the `!validPair` branch, which exits the whole function rather than skipping the iteration, then built a PoC with mixed whitelisted/non-whitelisted offers.
**Exploitation:** Not an attacker-driven exploit; a borrower/lender matching a non-whitelisted lend offer alongside a whitelisted one causes the whitelisted lender's incentive accounting to be skipped, permanently losing their claimable incentives for that epoch.
**Insight:** In multi-offer matching loops, audit every early-exit branch: a `return` inside a per-element validation loop silently drops all later elements, so check whether `continue` was intended and whether accounting mappings for later valid entries are left stale.

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

**Vulnerable updateFunds loop with return**

```
for (uint i = 0; i < lenders.length; i++) {
            bool validPair = isPairWhitelisted[informationOffers[i].principle][
                collateral
            ];
            if (!validPair) {
@>                return;
            }
            address principle = informationOffers[i].principle;

            uint _currentEpoch = currentEpoch();

            lentAmountPerUserPerEpoch[lenders[i]][
                hashVariables(principle, _currentEpoch)
            ] += informationOffers[i].principleAmount;
            totalUsedTokenPerEpoch[principle][
                _currentEpoch
            ] += informationOffers[i].principleAmount;
            borrowAmountPerEpoch[borrower][
                hashVariables(principle, _currentEpoch)
            ] += informationOffers[i].principleAmount;

            emit UpdatedFunds(
                lenders[i],
                principle,
                collateral,
                borrower,
                _currentEpoch
            );
        }
    }
```

