The precision loss in the fee percentage for connecting offers results in the borrower paying less than the expected fee
The fee percentage for connecting offers is calculated with integer division that rounds down, causing a precision loss. A borrower can set the loan duration to just below a day boundary to pay less than the intended fee, with the loss reaching up to a quarter of the daily fee.
nikhil840096 Follow with ydlee
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/208
Found by
nikhil840096, ydlee
Summary
Some of the borrowed principal tokens is charged as a fee for connecting transactions. The percentage of the fee is calculated according to DebitaV3Aggregator.sol:391. There is a non-negligible precision loss in the calculation process. Since the default feePerDay is 4, the maximum loss could reach up to 1/4 of the daily fee, which is significant, especially when the amount borrowed is substantial.
391: uint percentage = ((borrowInfo.duration * feePerDay) / 86400); // @audit-issue 最多损失1/4天的费用
There are another 2 instances of the issue in DebitaV3Load.sol:extendLoan.
571: uint PorcentageOfFeePaid = ((m_loan.initialDuration * feePerDay) /
572: 86400);
602: uint feeOfMaxDeadline = ((offer.maxDeadline * feePerDay) /
603: 86400);
Root Cause
In DebitaV3Aggregator.sol:391, rounding down the fee percentage can lead to a non-trivial precision loss.
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
By setting the borrowing duration to N days + 86400/4 - 1, users can save the maximum fee.
Impact
The precision loss in the fee percentage results in the borrower paying less than the expected fee, with the maximum loss potentially reaching up to 1/4 of the daily fee.
PoC
No response
Mitigation
When calculating the fee percentage, rounding up; or multiplying by a multiple to increase precision.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/c946cdd90c8d4841fa254359a863d3b574e34566
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 borrower pays less than the expected fee, with the maximum loss potentially reaching up to 1/4 of the daily fee.
What the attacker needed
A loan offer with a fee; borrower controls loan duration
The fix
The protocol team fixed this issue in the referenced PRs/commits.
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 smart contract calculates a fee using whole-number division, any remainder is thrown away. This means the fee can be slightly lower than intended. By choosing a loan duration that leaves a large remainder, a borrower can reduce the fee they pay.