Premature Liquidation When a Borrower Pays early
The liquidation check in TellerV2 uses the time since the last repayment rather than the payment due date, so a borrower who pays early can be liquidated before their next payment is due. An attacker could exploit this to liquidate loans prematurely and profit from the collateral.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-03-teller-judging/issues/494
Found by
branch_indigo
Summary
On TellerV2 markets, whenever a borrower pays early in one payment cycle, they could be at risk to be liquidated in the next payment cycle. And this is due to a vulnerability in the liquidation logic implemented in _canLiquidateLoan. Note: This issue is submitted separately from issue #2 because the exploit is based on user behaviors regardless of a specific market setting. And the vulnerability might warrant a change in the liquidation logic.
Vulnerability Detail
In TellerV2.sol, the sole liquidation logic is dependent on the time gap between now and the previous payment timestamp. But a user might decide to pay at any time within a given payment cycle, which makes the time gap unreliable and effectively renders this logic vulnerable to exploitation.
return (uint32(block.timestamp) -
_liquidationDelay -
lastRepaidTimestamp(_bidId) >
bidDefaultDuration[_bidId]);
Suppose a scenario where a user takes on a loan on a market with 3 days payment cycle and 3 days paymentDefaultDuration. And the loan is 14 days in duration. The user decided to make the first minimal payment an hour after receiving the loan, and the next payment due date is after the sixth day. Now 5 days passed since the user made the first payment, and a liquidator comes in and liquidates the loan and claims the collateral before the second payment is due.
Here is a test to show proof of concept for this scenario.
Impact
Given the fact that this vulnerability is not market specific and that users can pay freely during a payment cycle, it's quite easy for a liquidator to liquidate loans prematurely. And the effect might be across multiple markets.
When there are proportional collaterals, the exploit can be low cost. An attacker could take on flash loans to pay off the principal and interest, and the interest could be low when early in the loan duration. The attacker would then sell the collateral received in the same transaction to pay off flash loans and walk away with profits.
Code Snippet
Tool used
Manual Review
Recommendation
Consider using the current timestamp - previous payment due date instead of just lastRepaidTimestamp in the liquidation check logic. Also, add the check to see whether a user is late on a payment in _canLiquidateLoan.
Discussion
ethereumdegen
In this logic, we should be calculating the default date(s) based relative to a 'due date' and not a 'repaid date' . We will look into this more closely.
ethereumdegen
Github PR: Issue 494 - improving logic for is loan liquidateable
IAm0x52
Fix looks good. Default date is now calculated from due date rather than repaid date
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 liquidation logic calculates default based on the time since the last repayment instead of the payment due date.
Impact
A liquidator could liquidate loans prematurely and claim collateral, potentially profiting by using flash loans to pay off the loan and selling the collateral.
What the attacker needed
Borrower makes an early payment; loan has proportional collateral; attacker has capital or flash loan
The fix
The liquidation check should use the payment due date instead of the last repayment timestamp and should verify that the borrower is actually late.
How it was found
- A borrower takes a loan with a 3-day payment cycle and 3-day default duration.
- The borrower makes the first minimal payment one hour after receiving the loan.
- Five days after that payment, a liquidator calls the liquidation function.
- The loan is liquidated and the collateral is claimed, even though the next payment is not yet due.
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.
In a loan, you have to make payments on time. The system decides if you are late by looking at when you last paid, not when your next payment is due. So if you pay early, the system might think you are late sooner than you should be, and someone can take your collateral.
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.