Skip to content
Business logic Audit finding Intermediate

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

When a borrower extends a non-perpetual loan, interest is accrued and the lender's interestPaid is updated. Later, when the borrower repays the debt, the unpaid interest overwrites the previously accrued interestToClaim, causing the lender to lose the interest earned during the extension period.

0x37 Follow with Audinarey, ExtraCaterpillar and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/483

Found by

0x37, Audinarey, ExtraCaterpillar, KaplanLabs, dimulski, newspacexyz, robertodf, t.aksoy

Summary

When a borrower call extendLoan()to extend a loan to the max deadline, interest is accrued to the lender up until the time the loan is extended and the lender's interestPaid is updated as well for accounting purpose when calculating the interest with calculateInterestToPay()

Root Cause

https://github.com/sherlock-audit/2024-11-debita-finance-v3/blob/main/Debita-V3-Contracts/contracts/DebitaV3Loan.sol#L655-L65

https://github.com/sherlock-audit/2024-11-debita-finance-v3/blob/main/Debita-V3-Contracts/contracts/DebitaV3Loan.sol#L237C1-L241C14

As shown below interest is accrued and interestPaid is also accrued correctly

Solidity

File: DebitaV3Loan.sol
655:                 } else {
656:      @>             loanData._acceptedOffers[i].interestToClaim +=
657:                         interestOfUsedTime - 
658:                         interestToPayToDebita;
659:                 }
660:                 loanData._acceptedOffers[i].interestPaid += interestOfUsedTime;

The problem is that when a borrower extends a loan and later repays the loan a the end of the maxDeadline that the loan was extended to, the unpaid interest is used to overwrite the previously accrued interest (as shown on L238 below) thus leading to a loss of interest to the borrower

Solidity
File: DebitaV3Loan.sol
186:     function payDebt(uint[] memory indexes) public nonReentrant {
187:         IOwnerships ownershipContract = IOwnerships(s_OwnershipContract);
////SNIP   .......
237:             } else {
238:     @>            loanData._acceptedOffers[index].interestToClaim =
239:                     interest -
240:                     feeOnInterest;
241:             }

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

This leads to a loss of interest for the lender

PoC

No response

Mitigation

Modify the payDebt() function as shown below

Diff
File: DebitaV3Loan.sol
186:     function payDebt(uint[] memory indexes) public nonReentrant {
187:         IOwnerships ownershipContract = IOwnerships(s_OwnershipContract);
////SNIP   .......
237:             } else {
-238:                   loanData._acceptedOffers[index].interestToClaim =
+238:                   loanData._acceptedOffers[index].interestToClaim +=
239:                     interest -
240:                     feeOnInterest;
241:             }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/c6047ca43070746cbf8adcab12784e583d1de5d5

The original report as published on Sherlock, by 0x37. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

The lender loses the interest that was accrued during the loan extension period.

What the attacker needed

Borrower extends a non-perpetual loan; borrower repays debt after extension

The fix

The payDebt function should add the new interest to interestToClaim rather than overwrite it; the protocol team fixed this issue.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In a loan, interest builds up over time. This report says that if a borrower extends the loan and later repays, the system accidentally replaces the interest the lender already earned with a smaller amount, so the lender gets less money than they should.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0x37

View all

79 more disclosed reports, best first.

More from Debita Finance V3

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.