Skip to content
Business logic Audit finding Intermediate

In CreditLine#_borrowTokensToLiquidate , oracle is used wrong way

In the liquidation path of the CreditLine contract, the price oracle was queried with the borrow asset and collateral asset in the wrong order, so the ratio returned was inverted relative to what the calculation expected. A liquidator or lender could therefore lose or gain funds during liquidation because of the miscalculated price.

0x0x0x Follow

Originally disclosed on Code4rena

Submitted by 0x0x0x

Current implementation to get the price is as follows:

(uint256 _ratioOfPrices, uint256 _decimals) = IPriceOracle(priceOracle).getLatestPrice(_borrowAsset, _collateralAsset);

https://github.com/code-423n4/2021-12-sublime/blob/9df1b7c4247f8631647c7627a8da9bdc16db8b11/contracts/CreditLine/CreditLine.sol#L1050

But it should not consult borrowToken / collateralToken, rather it should consult the inverse of this result. As a consequence, in liquidate the liquidator/lender can lose/gain funds as a result of this miscalculation.

Mitigation step

Replace it with

(uint256 _ratioOfPrices, uint256 _decimals) = IPriceOracle(priceOracle).getLatestPrice(_collateralAsset, _borrowAsset);

ritik99 (Sublime) confirmed

The original report as published on Code4rena, by 0x0x0x. 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 oracle call passed the borrow asset and collateral asset in the wrong order, returning an inverted price ratio that the liquidation maths did not account for.

Impact

During liquidation the inverted ratio could cause the liquidator or lender to lose or gain funds, as the text states.

What the attacker needed

A position eligible for liquidation

The fix

The oracle call should be made with the collateral asset first and the borrow asset second, which the project confirmed as the mitigation.

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 often asks a price service, called an oracle, how much one token is worth compared with another. Here the contract asked for the price in the wrong direction, like asking how many dollars one euro buys when you actually need how many euros one dollar buys. That flipped number was then used to work out how much a borrower owes during liquidation, so the amounts paid out could be wrong.

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 0x0x0x

View all

6 more disclosed reports, best first.

More from Sublime contest

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.