Skip to content
Business logic Audit finding Intermediate

Incorrect calculation of extended loan days leads to unfair borrower fees

The extendLoan function calculates the fee for extending a loan using the offer's maximum deadline instead of the actual extended period, leading to inflated fees. Borrowers are charged more than they should be when extending their loans.

newspacexyz Follow with prosper

Originally disclosed on Sherlock

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

The protocol has acknowledged this issue.

Found by

newspacexyz, prosper

Summary

The miscalculation of extended loan days in the extendLoan function will cause borrowers to face unfair fees as the function incorrectly calculates the fee based on offer.maxDeadline instead of using the actual extended days derived from nextDeadline() and m_loan.startedAt. This leads to inflated fee deductions during loan extensions.

Root Cause

In DebitaV3Loan.sol:602, the calculation of the extended days incorrectly uses offer.maxDeadline as the basis for the fee calculation instead of the actual extended period derived from nextDeadline() and m_loan.startedAt. This results in an inflated feeOfMaxDeadline, leading to excessive fees for borrowers.

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

Real extended maxDeadline is nextDeadline(), not offer.maxDeadline.

// calculate difference from fee paid for the initialDuration vs the extra fee they should pay because of the extras days of extending the loan. MAXFEE shouldnt be higher than extra fee + PorcentageOfFeePaid

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

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. The borrower calls the extendLoan() function to extend their loan duration.

  2. The function validates initial conditions:

    • loanData.extended is false.
    • nextDeadline() returns a timestamp greater than block.timestamp.
    • offer.maxDeadline is a valid future timestamp.
  3. The function calculates feeOfMaxDeadline as:

    Solidity
    uint feeOfMaxDeadline = ((offer.maxDeadline * feePerDay) / 86400);
    

    This incorrectly uses offer.maxDeadline instead of the actual extended period derived from nextDeadline() and m_loan.startedAt.

  4. The miscalculation leads to an inflated feeOfMaxDeadline and misingBorrowFee.

  5. The inflated fees are deducted from the borrower's principal during the loan extension.

  6. The borrower loses more principal than necessary due to the incorrect fee calculation.

Impact

Borrowers will be charged inflated fees due to the incorrect calculation of the extended loan days. This results in unnecessary principal loss, making loan extensions disproportionately costly. Over time, this could discourage borrowers from using the loan extension feature, cause financial hardship, and lead to reputational damage for the platform as users perceive the fee structure as unfair or exploitative.

PoC

No response

Mitigation

Solidity
uint extendedDays = nextDeadline() - m_loan.startedAt;
require(extendedDays > 0, "Invalid extended days");

uint feeOfMaxDeadline = ((extendedDays * feePerDay) / 86400);

The original report as published on Sherlock, by newspacexyz. 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

Root cause

The fee calculation uses offer.maxDeadline instead of the actual extended period (nextDeadline() - m_loan.startedAt).

Impact

Borrowers will be charged inflated fees due to the incorrect calculation of the extended loan days, resulting in unnecessary principal loss.

What the attacker needed

Borrower has an active loan; borrower calls extendLoan()

The fix

The fee should be calculated using the actual extended days (nextDeadline() - m_loan.startedAt) instead of offer.maxDeadline.

How it was found

  1. The borrower calls the extendLoan() function to extend their loan duration.
  2. The function validates initial conditions: loanData.extended is false, nextDeadline() returns a timestamp greater than block.timestamp, and offer.maxDeadline is a valid future timestamp.
  3. The function calculates feeOfMaxDeadline using offer.maxDeadline instead of the actual extended period.
  4. The miscalculation leads to an inflated feeOfMaxDeadline and misingBorrowFee.
  5. The inflated fees are deducted from the borrower's principal during the loan extension.
  6. The borrower loses more principal than necessary due to the incorrect fee calculation.

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.

When a borrower wants to extend their loan, the smart contract charges a fee based on how many extra days they are borrowing. The code mistakenly uses the loan offer's maximum possible deadline instead of the actual new deadline, so the fee is calculated as if the loan were extended for much longer than it really is. This means borrowers pay more fees 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 newspacexyz

View all

4 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.