Skip to content
Business logic Audit finding Intermediate

Users can be liquidated prematurely because calculation understates value of underlying position

The position risk calculation uses the initially deposited token amount without accounting for accrued interest, undervaluing the user's collateral. This can cause users to be liquidated prematurely because their collateral value is understated.

obront Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/126

Found by

obront

Summary

When the value of the underlying asset is calculated in getPositionRisk(), it uses the underlyingAmount, which is the amount of tokens initially deposited, without any adjustment for the interest earned. This can result in users being liquidated early, because the system undervalues their assets.

Vulnerability Detail

A position is considered liquidatable if it meets the following criteria:

Solidity
((borrowsValue - collateralValue) / underlyingValue) >= underlyingLiqThreshold

The value of the underlying tokens is a major factor in this calculation. However, the calculation of the underlying value is performed with the following function call:

Solidity
uint256 cv = oracle.getUnderlyingValue(
    pos.underlyingToken,
    pos.underlyingAmount
);

If we trace it back, we can see that pos.underlyingAmount is set when lend() is called (ie when underlying assets are deposited). This is the only place in the code where this value is moved upward, and it is only increased by the amount deposited. It is never moved up to account for the interest payments made on the deposit, which can materially change the value.

Impact

Users can be liquidated prematurely because the value of their underlying assets are calculated incorrectly.

Code Snippet

https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L485-L488

https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/oracle/CoreOracle.sol#L182-L189

https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L644

Tool used

Manual Review

Recommendation

Value of the underlying assets should be derived from the vault shares and value, rather than being stored directly.

The original report as published on Sherlock, by obront. 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 stored underlying amount is not updated to reflect interest earned, so the risk calculation undervalues the collateral.

Impact

Users could be liquidated prematurely because their collateral value is understated.

What the attacker needed

A lending position with interest-bearing collateral

The fix

The value of the underlying assets should be derived from the vault shares and their current value, rather than being stored directly.

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 lending system, your collateral can earn interest over time. The bug is that the system checks if you can be liquidated using only the original amount you deposited, ignoring the extra interest you earned. So it thinks your collateral is worth less than it really is, and may liquidate you too early.

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 obront

View all

46 more disclosed reports, best first.

More from Blueberry Update #3

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.