_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:
-
Alice calls
liquidateLoan(loandId= 1) -> success.LoanLiquidatorgenerates an auction._loans\[loandId = 1]is still valid , and will only be cleared when the auction is over.
-
Alice call
addNewTranche(loandId= 1) -> success._baseLoanChecks(loandId= 1) will pass.- delete
_loans\[1]; _loans\[2] = newLoan.hash().
-
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
Strict
-><=.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
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
- At the exact timestamp when the loan duration ends, call liquidateLoan for the loan ID.
- Immediately call addNewTranche for the same loan ID, which passes the expiration check and deletes the original loan record.
- 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.