# An attacker can steal the entire borrow and lending incentive of an epoch with FLASHLOAN in a single transaction

Self-matched lend/borrow offers with huge ratio and 1 wei collateral, repaid same block via flash loan, let attacker claim nearly all epoch incentives.

- Payout: Audit contest
- Severity: medium
- Program: Debita
- Found by: BengalCatBalu
- Disclosed: 2024-10-31
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-10-debita-judging/issues/708
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-19
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained vuln:business-logic vuln:flash-loan vuln:reward-distribution

**Target:** DebitaV3Loan / DebitaV3Aggregator offer matching and incentive distribution
**Root cause:** No check prevents the same address being lender, borrower and connector, and payDebt() permits same-block repayment with zero APR, so a self-matched loan with an arbitrarily high maxRatio and 1 wei collateral can be opened and closed instantly.
**Steps:**
1. Take a flash loan (e.g. Aave V3, 0.05% fee) in the callback.
2. Create a lend offer with maxRatio ~100e24 so collateral per principal is dust.
3. Create a borrow offer with 1 wei collateral and maxApr = 0.
4. Call `matchOfferV3()` to self-match; only ~0.17% net fee after 15% rebate.
5. Call `payDebt()` in the same block (only deadline check) to repay with zero interest.
6. Repay flash loan plus fee.
7. After epoch ends, claim nearly all borrow+lend incentives in the next block.
**How found:** Code review of ratio and APR validation in matchOfferV3 and the absence of a same-block repayment check in payDebt, plus noticing no restriction on lender==borrower==connector.
**Exploitation:** Attacker flash-loans capital, self-matches a lend/borrow pair with extreme ratio and 1 wei collateral, repays same block at 0 APR, returns flash loan, then claims the epoch's incentive pool since their volume dominates total borrow/lend.
**Escalation:** Using 1 wei collateral with huge maxRatio minimizes capital needed, lowering flash-loan fees and making the attack profitable even for smaller incentive pools.
**Insight:** Incentive/reward accounting that keys off volume is gameable when the same actor can be both sides of a trade and close it in the same block; check for self-matching restrictions and same-block open/close in any reward-per-epoch design.

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

**Same-block repayment check in payDebt**

```
// check next deadline
        require(
            nextDeadline() >= block.timestamp,
            "Deadline passed to pay Debt"
        );
```

**Dust collateral via huge maxRatio**

```
maxRatio = lendInfo.maxRatio[collateralIndex]; //@audit attacker set this to be large to allow the use of dust collateral
            }
            // calculate ratio based on porcentage of the lend order
            uint ratio = (maxRatio * porcentageOfRatioPerLendOrder[i]) / 10000;
            uint m_amountCollateralPerPrinciple = amountCollateralPerPrinciple[
                principleIndex
            ];
            // calculate the amount of collateral used by the lender
            uint userUsedCollateral = (lendAmountPerOrder[i] *
                (10 ** decimalsCollateral)) / ratio; //@audit collateral required for large loan becomes dust!
```

**Zero APR bypasses interest fee**

```
// check if the apr is within the limits of the borrower
            require(weightedAverageAPR[i] <= borrowInfo.maxApr, "Invalid APR"); //@audit Apr is set to zero, so no fee on interest!
```

