Skip to content
Smart contracts Audit finding Intermediate

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:

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

Internal pre-conditions

  1. Loan must not be already extended (extended == false)
  2. Borrower must have waited minimum duration (10% of initial duration)
  3. Loan must not be expired (nextDeadline() > block.timestamp)
  4. Must have at least one unpaid offer

External pre-conditions

  1. Current time must be close to offer's maxDeadline
  2. maxDeadline - (block.timestamp - startedAt) - block.timestamp < 0

Attack Path

  1. Loan starts at timestamp 1704067200 (January 1, 2024)
  2. Time advances to 1705190400 (January 14, 2024)
  3. Borrower attempts to extend loan
  4. For an offer with maxDeadline 1705276800 (January 15, 2024)
  5. Transaction reverts due to arithmetic underflow

Impact

Borrowers cannot extend loans near their deadlines even when they satisfy all other requirements:

  1. Forces unnecessary defaults near deadline
  2. Wastes gas on failed extension attempts
  3. Disrupts normal loan management operationsthe

PoC

This PoC demonstrates the reversion caused by unused time calculations in extendLoan function.

Solidity
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:

  1. loanStartedAt: 1704067200 (Jan 1, 2024 00:00)
  2. currentTime: 1705190400 (Jan 14, 2024 00:00)
  3. maxDeadline: 1705276800 (Jan 15, 2024 00:00)

The calculation flow:

  1. alreadyUsedTime = 1705190400 - 1704067200 = 1,123,200 (≈13 days)
  2. 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

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

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

  1. Loan starts at a given timestamp.
  2. Time advances to near the offer's maxDeadline.
  3. Borrower attempts to extend the loan.
  4. 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.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.