# Interest paid for non perpetual loan during loan extension is lost when the borrower repays debt

DebitaV3Loan.payDebt overwrites accrued interestToClaim instead of adding, so lenders lose interest accrued during loan extension when borrower repays.

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

**Target:** DebitaV3Loan.payDebt / extendLoan interest accounting
**Root cause:** extendLoan accrues interestToClaim and interestPaid for elapsed time, but payDebt assigns (=) the new interest minus fee to interestToClaim instead of accumulating (+=), discarding previously accrued interest.
**Steps:**
1. Borrower takes non-perpetual loan and calls `extendLoan()` to max deadline; interestToClaim and interestPaid accrue for used time (L656-660).
2. Borrower repays at extended maxDeadline via `payDebt(indexes)`.
3. At L238 `interestToClaim = interest - feeOnInterest` overwrites prior accrued value instead of `+=`.
4. Lender receives less interest than accrued; compare interestToClaim before/after repayment.
**How found:** Code review of interest accounting across extendLoan and payDebt; noticed assignment vs accumulation mismatch on interestToClaim.
**Insight:** When a state variable is accrued in one function (extendLoan) and settled in another (payDebt), check whether settlement uses assignment or accumulation; extension flows that pre-credit interest are prime spots for overwrite bugs.

