# A borrower may pay more interest that he has specified, if orders are matched by a malicious actor

DebitaV3Aggregator.matchOffersV3 lets a matcher split lend amounts into tiny chunks so integer rounding zeroes out high-APR contributions, forcing borrowers to pay above their specified max APR.

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

**Target:** DebitaV3Aggregator.matchOffersV3 order-matching function
**Root cause:** Weighted-average APR update computes (lendInfo.apr * lendAmountPerOrder[i]) / amountPerPrinciple, which rounds to 0 when the chunk is small relative to principal, so high-APR lend orders contribute no APR weight while still lending principal. No minimum on lendAmountPerOrder and no cap on resulting APR vs borrower's max.
**Steps:**
1. Borrower creates borrow order for 500_000e6 USDC at max 5% APR, 150 days, WETH collateral.
2. Attacker creates a lend order at 10% APR with 15_000e6 USDC.
3. Call `matchOffersV3` with 29 lendOrders: index 0 = victim lender (495_000e6, 5% APR), indices 1-28 = attacker lend order; lendAmountPerOrder[0]=200_000e6+1, rest 200e6 each.
4. Repeat `matchOffersV3` with lendAmountPerOrder[0]=286_391e6+1 and rest 286e6.
5. Borrower repays; interest computed at 10% APR on ~13_608e6 USDC instead of 5%, overpaying ~279e6 USDC (~2.72%).
**How found:** Code reading of the weighted-average APR math in matchOffersV3, noticing Solidity integer division truncation combined with no minimum on lendAmountPerOrder and permissionless matching.
**Exploitation:** Attacker (any caller of matchOffersV3) supplies their own higher-APR lend order and splits it into 28 tiny chunks below the rounding threshold, so the weighted APR for those chunks rounds to zero and the borrower's effective rate on that principal jumps to the attacker's APR. Attacker collects the inflated interest on repayment; repeatable across many borrowers.
**Escalation:** Repeated matchOffersV3 calls (29-order cap per call) to cover larger principals; scaling to multiple large borrow orders.
**Insight:** In weighted-average accounting loops, check whether per-iteration division can truncate to zero for small inputs; if the caller controls chunk sizes and there's no minimum, an attacker can dilute the weight of honest high-value entries and skew the average toward their own terms.

