Skip to content
Business logic Audit finding Intermediate

Liquidation transactions can potentially fail for all markets

Liquidation transactions in all markets can revert because the liquidation flow calls an exchange-rate update that reverts when the fetched rate is not positive. This can leave under-collateralised positions unliquidatable, potentially pushing the protocol into insolvency.

zzzitron Follow with GalloDaSballo

Originally disclosed on Code4rena

Submitted by zzzitron, also found by GalloDaSballo

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/bigBang/BigBang.sol#L315-L316

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/Market.sol#L340-L344

As an example, when calling BigBang.liquidate() the tx potentially fails, because the subsequent call to Market.updateExchangeRate (BigBang.sol line 316) can face a revert condition on line 344 in Market.sol.

In Market.updateExchangeRate() a revert is triggered if rate is not bigger than 0 - see line 344 in Market.sol.

Liquidations should never fail and instead use the old exchange rate - see BigBang.sol line 315 comment:

// Oracle can fail but we still need to allow liquidations

But the liquidation transaction can potentially fail when trying to fetch the new exchange rate via Market.updateExchangeRate() as shown above.

This issue applies for all markets (Singularity, BigBang) since the revert during the liquidation happens in the Market.sol contract from which all markets inherit.

Because of this issue user’s collateral values may fall below their debt values, without being able to liquidate them, pushing the protocol into insolvency.

This is classified as high risk because liquidation is an essential functionality of the protocol.

Proof of Concept

Here is a POC that shows that a liquidation tx reverts according to the issue described above:

https://gist.github.com/zzzitron/90206267434a90990ff2ee12e7deebb0

Recommended Mitigation Steps

Instead of reverting on line 344 in Market.sol when fetching the exchange rate, consider to return the old rate instead, so that the liquidation can be executed successfully.

0xRektora (Tapioca) confirmed


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

Likely the shared exchange-rate update reverts on a non-positive rate instead of falling back to the previous rate, and the liquidation path calls it without handling that revert.

Impact

Liquidations may fail across all markets, so under-collateralised positions could not be closed and the protocol could become insolvent.

What the attacker needed

A market with a failing or non-positive rate fetch

The fix

The exchange-rate update should return the old rate instead of reverting so that liquidation can complete.

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 liquidation is when someone repays another person's bad debt to keep a lending system healthy. Here, the code that performs a liquidation also tries to refresh a price-like value, and that refresh can fail and cancel the whole liquidation. If liquidations keep failing, bad debt can pile up and the system may run out of money.

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 zzzitron

View all

21 more disclosed reports, best first.

More from Tapioca 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.