Loan Extension Fails Due to Unused Time Calculation
The extendLoan function in DebitaV3Loan contains an unused variable extendedTime that can cause an arithmetic underflow when a borrower tries to extend a loan near its deadline. This reverts the transaction, preventing borrowers from extending their loans even when they meet all other requirements.
0x37 Follow with 0xPhantom2, 0xmujahid002 and 14 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/766
Found by
0x37, 0xPhantom2, 0xmujahid002, Audinarey, BengalCatBalu, Falendar, Honour, dany.armstrong90, dimulski, jsmi, mladenov, moray5554, newspacexyz, nikhil840096, nikhilx0111, yovchev_yoan, zkillua
Summary
The extendLoan function in DebitaV3Loan::extendLoan has redundant time calculation logic that causes transaction reversions when borrowers attempt to extend loans near their deadline.
Root Cause
In the DebitaV3Loan contract the function extendLoan function has a varaible extendedTime that is not used and can cause reverts in some cases which cause some borrowers to not be able to extend their loan.
The exact line of code:
Internal pre-conditions
- Loan must not be already extended
(extended == false) - Borrower must have waited minimum duration
(10% of initial duration) - Loan must not be expired
(nextDeadline() > block.timestamp) - Must have at least one unpaid offer
External pre-conditions
- Current time must be close to offer's
maxDeadline maxDeadline - (block.timestamp - startedAt)-block.timestamp< 0
Attack Path
- Loan starts at timestamp
1704067200(January 1, 2024) - Time advances to
1705190400(January 14, 2024) - Borrower attempts to extend loan
- For an offer with maxDeadline
1705276800(January 15, 2024) - Transaction reverts due to arithmetic underflow
Impact
Borrowers cannot extend loans near their deadlines even when they satisfy all other requirements:
- Forces unnecessary defaults near deadline
- Wastes gas on failed extension attempts
- Disrupts normal loan management operationsthe
PoC
This PoC demonstrates the reversion caused by unused time calculations in extendLoan function.
contract BugPocTime {
uint256 loanStartedAt = 1704067200; // 1 January 00:00 time
uint256 currentTime = 1705190400; // 14 January 00:00 time
uint256 maxDeadline = 1705276800; // 15 January 00:00 time
function extendLoan() public view returns(uint256){
uint256 alreadyUsedTime = currentTime - loanStartedAt;
uint256 extendedTime = maxDeadline - alreadyUsedTime - currentTime;
return 10;
}
}
The example uses the following timestamps:
- loanStartedAt: 1704067200 (Jan 1, 2024 00:00)
- currentTime: 1705190400 (Jan 14, 2024 00:00)
- maxDeadline: 1705276800 (Jan 15, 2024 00:00)
The calculation flow:
- alreadyUsedTime = 1705190400 - 1704067200 = 1,123,200 (≈13 days)
- extendedTime = 1705276800 - 1,123,200 - 1705190400 = 1705276800 - 1706313600 = -1,036,800 (reverts due to underflow)
Mitigation
Remove the unused extendedTime calculation as it serves no purpose and can cause legitimate loan extensions to fail.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/dd1ad26725ba4835bc6406acf1289c1fbd33f8f2
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
Likely, the unused variable extendedTime is calculated with a subtraction that can underflow when the current time is close to the offer's maxDeadline.
Impact
Borrowers cannot extend loans near their deadlines, which could force unnecessary defaults and wastes gas on failed attempts.
What the attacker needed
Loan not already extended; Borrower waited minimum duration; Loan not expired; At least one unpaid offer
The fix
The unused extendedTime calculation should be removed to prevent the underflow.
How it was found
- Loan starts at a given timestamp.
- Time advances to near the offer's maxDeadline.
- Borrower attempts to extend the loan.
- The transaction reverts due to arithmetic underflow in the extendedTime 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.
A smart contract function for extending loans has a calculation that is not used but can still cause the transaction to fail if the numbers go negative. This means borrowers cannot extend their loans close to the deadline, which could lead to unnecessary defaults.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.