Skip to content
Business logic Audit finding Intermediate

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.

branch_indigo Follow

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.

Solidity
        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

https://github.com/teller-protocol/teller-protocol-v2/blob/cb66c9e348cdf1fd6d9b0416a49d663f5b6a693c/packages/contracts/contracts/TellerV2.sol#L965-L969

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

The original report as published on Sherlock, by branch_indigo. 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

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

  1. A borrower takes a loan with a 3-day payment cycle and 3-day default duration.
  2. The borrower makes the first minimal payment one hour after receiving the loan.
  3. Five days after that payment, a liquidator calls the liquidation function.
  4. 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.

More by branch_indigo

View all

2 more disclosed reports, best first.

More from Teller

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.