Skip to content
Business logic Audit finding Intermediate

_baseLoanChecks() check errors for expire

The loan expiration check in _baseLoanChecks uses a strict less-than, so at the exact timestamp when the loan duration ends, the loan is still considered valid. An attacker can liquidate the loan and then immediately add a new tranche, which clears the original loan record, causing the later liquidation callback to fail and locking the NFT or funds.

bin2chen Follow with zhaojie and minhquanym

Originally disclosed on Code4rena

Submitted by bin2chen, also found by zhaojie and minhquanym

_baseLoanChecks() is used to check whether Loan has expired:

    function _baseLoanChecks(uint256 _loanId, Loan memory _loan) private view {
        if (_loan.hash() != _loans[_loanId]) {
            revert InvalidLoanError(_loanId);
        }
@>      if (_loan.startTime + _loan.duration < block.timestamp) {
            revert LoanExpiredError();
        }
    }

The expiration checks in liquidation are as follows:

    function _liquidateLoan(uint256 _loanId, IMultiSourceLoan.Loan calldata _loan, bool _canClaim)
        internal
        returns (bool liquidated, bytes memory liquidation)
    {
...

        uint256 expirationTime = _loan.startTime + _loan.duration;
@>      if (expirationTime > block.timestamp) {
            revert LoanNotDueError(expirationTime);
        }

This way, both checks pass when block.timestamp == _loan.startTime + _loan.duration.

This leads to the problem that a malicious attacker can perform the following steps when block.timestamp == _loan.startTime + _loan.duration:

  1. Alice calls liquidateLoan (loandId = 1) -> success.

    • LoanLiquidator generates an auction.
    • _loans\[loandId = 1] is still valid , and will only be cleared when the auction is over.
  2. Alice call addNewTranche (loandId = 1) -> success.

    • _baseLoanChecks (loandId = 1) will pass.
    • delete _loans\[1];
    • _loans\[2] = newLoan.hash().
  3. Bidding ends, call loanLiquidated(loandId = 1) will fail , because _loans[1] has been cleared.

Impact

Maliciously disrupting the end of the bidding, causing the NFT/funds to be locked.

Recommended Mitigation

    function _baseLoanChecks(uint256 _loanId, Loan memory _loan) private view {
        if (_loan.hash() != _loans[_loanId]) {
            revert InvalidLoanError(_loanId);
        }
-       if (_loan.startTime + _loan.duration < block.timestamp) {
+      if (_loan.startTime + _loan.duration <= block.timestamp) {
            revert LoanExpiredError();
        }
    }

Assessed type

Context

0xend (Gondi) confirmed

Gondi mitigated:

Strict -> <=.

Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.


The original report as published on Code4rena, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 expiration check uses a strict less-than instead of less-than-or-equal, creating a one-second window where the loan is both expired for liquidation and not expired for other operations.

Impact

The attacker can disrupt the end of the bidding, causing the NFT or funds to be locked.

What the attacker needed

A loan that has reached its expiration timestamp; ability to call liquidateLoan and addNewTranche

How it was found

  1. At the exact timestamp when the loan duration ends, call liquidateLoan for the loan ID.
  2. Immediately call addNewTranche for the same loan ID, which passes the expiration check and deletes the original loan record.
  3. When the auction ends, call loanLiquidated for the original loan ID, which fails because the loan record has been cleared.

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 checks if a loan has expired using a less-than comparison, so at the exact moment the loan duration ends, the loan is still treated as active. This allows someone to liquidate the loan and then start a new loan from it, which deletes the old loan record. Later, when the auction ends, the system cannot find the old loan, so the NFT or funds get stuck.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Gondi Invitational

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.