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.
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
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
-
The borrower calls the
extendLoan()function to extend their loan duration. -
The function validates initial conditions:
loanData.extendedisfalse.nextDeadline()returns a timestamp greater thanblock.timestamp.offer.maxDeadlineis a valid future timestamp.
-
The function calculates
feeOfMaxDeadlineas:Solidity uint feeOfMaxDeadline = ((offer.maxDeadline * feePerDay) / 86400);This incorrectly uses
offer.maxDeadlineinstead of the actual extended period derived fromnextDeadline()andm_loan.startedAt. -
The miscalculation leads to an inflated
feeOfMaxDeadlineandmisingBorrowFee. -
The inflated fees are deducted from the borrower's principal during the loan extension.
-
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
uint extendedDays = nextDeadline() - m_loan.startedAt;
require(extendedDays > 0, "Invalid extended days");
uint feeOfMaxDeadline = ((extendedDays * feePerDay) / 86400);
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
- The borrower calls the extendLoan() function to extend their loan duration.
- 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.
- The function calculates feeOfMaxDeadline using offer.maxDeadline instead of the actual extended period.
- The miscalculation leads to an inflated feeOfMaxDeadline and misingBorrowFee.
- The inflated fees are deducted from the borrower's principal during the loan extension.
- 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.