Skip to content
Business logic Audit finding Advanced

User's can create non-liquidateable positions by leveraging `rebalanceBadDebt` to decrease share price

The rebalanceBadDebt function reduces a pool's total deposit assets without reducing total deposit shares, deflating the share price. An attacker can repeatedly borrow and trigger bad debt to inflate total shares near the maximum uint256, causing overflow in functions like getBorrowsOf and isPositionHealthy, which prevents liquidation of their positions.

hash Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-sentiment-v2-judging/issues/585

Found by

hash

Summary

User's can create non-liquidateable positions by leveraging rebalanceBadDebt to decrease share price

Vulnerability Detail

The rebalanceBadDebt function decreases the deposit assets while the deposit shares are kept the same

Solidity
    function rebalanceBadDebt(uint256 poolId, address position) external {
        
        ....

        // rebalance bad debt across lenders
        pool.totalBorrowShares = totalBorrowShares - borrowShares;
        // handle borrowAssets being rounded up to be greater than totalBorrowAssets
        pool.totalBorrowAssets = (totalBorrowAssets > borrowAssets) ? totalBorrowAssets - borrowAssets : 0;
        uint256 totalDepositAssets = pool.totalDepositAssets;
        pool.totalDepositAssets = (totalDepositAssets > borrowAssets) ? totalDepositAssets - borrowAssets : 0;
        borrowSharesOf[poolId][position] = 0;

The deflates the value of a depositors share and hence a deposit afterwards will lead to a massive amount of shares being minted. An attacker can leverage this to create pools such that the total share amount will become ~type(uint.max). After this any query to many of the pool's functions including getBorrowsOf will revert due to the overflow. This can be used to create positions that borrow from other pools and cannot be liquidated

Eg: attacker creates a pool for with with 1e18 assets and 1e18 shares attacker borrows 1e18 - 1. the position goes into bad debt and rebalanceBadDebt is invoked now assets left = 1 and shares = 1e18 attacker deposits 1e18 tokens and gets 1e36 tokens in return attacker repeates the process by borrowing 1e18 tokens, being in bad debt, getting rebalanceBadDebt invoked and delfating the share value

since the attacker has full control over the increase by choosing the deposit amount, they can make it reach a value near type(uint).max followed by a borrow from this infected pool and from other pools from which they attacker really wanted to borrow after some time, the interest increase will make the corresponding fee share cause overflow for the pool shares and hence the getBorrowsOf and isPositionHealthy functions to revert preventing liquidations of the attackers position

Impact

User's can create unliquidateable positions and make protocol accrue bad debt/depositors from other pools loose assets

Code Snippet

https://github.com/sherlock-audit/2024-08-sentiment-v2/blob/0b472f4bffdb2c7432a5d21f1636139cc01561a5/protocol-v2/src/Pool.sol#L547

https://github.com/sherlock-audit/2024-08-sentiment-v2/blob/0b472f4bffdb2c7432a5d21f1636139cc01561a5/protocol-v2/src/RiskModule.sol#L212-L213

Tool used

Manual Review

Recommendation

Can't think of any good solution if a position has to have the ability to borrow from multiple pools using the same collateral backing

Discussion

S3v3ru5

I do not consider this issue to have medium severity.

First of, I agree it is possible for an attacker to make totalDepositShares to be near uint256.max. Very good exploit. I do not think the attack is viable though.

I agree with an attacker can make "totalDepositShares" to be near uint256.max. I do not agree with viability of the impact, hence the severity.

My main reason is the cost of the attack.

The exploit scenario says isPositionHealthy starts failing because of overflow after some time (because of fees). The attack has two main steps after making the totalDepositShares = ~uint256.max

  1. Attacker borrows before the isPositionHealthy starts failing
  2. After isPositionHealthy starts failing, the position becomes unliquidatable

As a result, the other pools which the attacker borrowed from will incur bad debt equal to bad debt.

In step 1, if the attacker was able to borrow borrowedAmount then that means attacker position has sufficient collateral greater than borrowedAmount.

The value of the collateral needs to be more than the value of the borrowed amount because of LTV < 100%.

Note, once isPositionHealthy starts failing, no operations can be performed. Because every operation includes isPositionHealthy check at the end. As a result,

The loss to protocol pools from attack (borrowed amount) is significantly less than loss to the attacker(collateral amount).

Hence, I consider this attack to be non-viable. Should this issue still be considered medium severity?

Also the difficulty to make "totalDepositShares" to be ~uint256.max is high.

Attacker can make "totalDepositSharesto be nearuint256.max`.

Difficult but is still possible. The difficulty to do this comes from

  1. Attacker deposits some tokens to over-collateralize the position in-order to borrow.
    • Small amounts, can be negligible.
  2. The collateral token has to lose its value relative to borrowed token, to make the value of collateral to be less than the borrowed tokens.
    • Possible for a few times.
  3. The position has to incur bad debt i.e The position is not liquidated for some reason.

The main difficulty in making the "totalDepsitShares" to near uint256.max comes from "position incuring bad debt". It is possible once or twice, the position is not liquidated before incuring bad debt but the attack requires multiple times (atleast 30 times without increasing the cost non-negligible).

I consider this to be very difficult to make it happen.

Liquidating the position before incuring bad debt is intended behavior, attacker cannot keep liquidators from liquidating their position.

The attack is based on position incuring bad debt i.e Liquidators not liquidating the position on time. The chances of this and the same pool incuring bad debt more than 30 times is very low.

I consider anyone of the following reasons is sufficient to not consider this issue as a medium:

  1. Attacker loses significantly more money than the protocol pools
  2. Difficulty to make "totalDepositShares" to be ~uint256.max is high. Attacker cannot control the chances as well. The chances of this happening is very very low.

NicolaMirchev

Escalate.

Why the severity should be downgraded to low based on the above comment. Additinally, max LTV regarding the README is set to 98%(We cannot have 100% LTV). That means liquidation bots will most probably try to liquidate the position, which means the probability drops even further.

sherlock-admin3

Escalate.

Why the severity should be downgraded to low based on the above comment. Additinally, max LTV regarding the README is set to 98%(We cannot have 100% LTV). That means liquidation bots will most probably try to liquidate the position, which means the probability drops even further.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

10xhash

The loss to protocol pools from attack (borrowed amount) is significantly less than loss to the attacker(collateral amount)

This is incorrect. The attacker only looses (collateral - borrowed amount) while the protocol looses borrowed amount which is significantly higher than (collateral - borrowed)

The attack is based on position incuring bad debt i.e Liquidators not liquidating the position on time. The chances of this and the same pool incuring bad debt more than 30 times is very low:

Attacker has control of the pool and hence has ability to configure the pool with the params that will make normal liquidator's not incentivized to liquidate (low debt, high ltv etc). And it is not required to be done 30 times(I am not sure what the entire assumptions are that were used to reach this number) to eventually reach such a state

S3v3ru5

This is incorrect. The attacker only looses (collateral - borrowed amount) while the protocol looses borrowed amount which is significantly higher than (collateral - borrowed)

I am not sure I understand. For the position to be healthy, doesn't it require to have assets > borrowed at all times? If collateral token cannot be a debt token then doesn't it mean collateral tokens to be worth of at-least borrowed amount?

Upd: So attacker transfers all borrowed assets to their account. The position is left with collateral assets. Attacker deposits collateral tokens and gets borrowed tokens. Attacker only lost (collateral - borrow) > protocol lost all borrowed amount. Agree with this point. Sorry for misunderstanding.

Attacker has control of the pool and hence has ability to configure the pool with the params that will make normal liquidator's not incentivized to liquidate (low debt, high ltv etc). And it is not required to be done 30 times(I am not sure what the entire assumptions are that were used to reach this number) to eventually reach such a state

I think I followed the sceanario mentioned and came up with 70 iterations to have the negligible costs. I chose (did some calc on my mind but nothing concrete) 30 (far less than 70) to present my point. May be it requires far less iterations. How many does it require?

I think the sentiment owner has the control over minBorrow and minDebt. LTV for a collateral can be set by a pool owner, however they are bounded by minLTV and maxLTV that are set by the sentiment owner.

If this scenario requires sentiment owner to set minDebt, minBorrow, maxLTV to values which would make the liquidations non-profitable multiple times, then wouldn't that a problem for the rest of the pools as well? Doesn't this count as Sentiment owner mistake? i.e admin mistake?

cvetanovv

I agree with @S3v3ru5 comments. While the exploit is technically possible, it's challenging to achieve.

Liquidation mechanisms, LTV settings, minDebt and minBorrow restrictions would prevent the scenario from easily occurring. Additionally, the potential loss for the attacker would far outweigh the gains, as they would lose more collateral than the protocol loses in borrowed amounts.

These are the main reasons why I think this issue is Low severity.

Planning to accept the escalation and invalidate the issue.

10xhash

I am using the risk parameters as mentioned in the readme and the high LTV for the attack is set by an attacker (instead of a honest pool owner) and is not an obstacle

The loss incured by the protocol far exceeds the loss that the attacker will incur. This is clarified in the earlier comment and accepted here

cvetanovv

@ruvaag can I have your opinion?

cvetanovv

After reviewing the issue again, I agree with @10xhash points.

While the exploit is complex and requires specific conditions, it is possible for an attacker to manipulate the pool and leverage the rebalanceBadDebt function to inflate shares, causing overflows and rendering positions unliquidatable.

I am planning to reject the escalation and leave the issue as is.

0xjuaan

@cvetanovv please consider this:

The protocol clearly states in the README that maxLTV will be set to 98%

Max LTV = 98% = 980000000000000000

When setting a pool's LTV, it MUST abide by this limit:

Solidity
// ensure new ltv is within global limits. also enforces that an existing ltv cannot be updated to zero
if (ltv < minLtv || ltv > maxLtv) revert RiskEngine\_LtvLimitBreached(ltv);

This means that the LTV cannot be set to 100% by the attacker, which is a requirement for the attack to work. Hence, the attack won't work.

In addition, it requires the same position to reach bad debt without liquidation several times consecutively, which has extremely low likelihood.

cvetanovv

@cvetanovv please consider this:

The protocol clearly states in the README that maxLTV will be set to 98%

Max LTV = 98% = 980000000000000000

When setting a pool's LTV, it MUST abide by this limit:

Solidity
// ensure new ltv is within global limits. also enforces that an existing ltv cannot be updated to zero
if (ltv < minLtv || ltv > maxLtv) revert RiskEngine\_LtvLimitBreached(ltv);

This means that the LTV cannot be set to 100% by the attacker, which is a requirement for the attack to work. Hence, the attack won't work.

In addition, it requires the same position to reach bad debt without liquidation several times consecutively, which has extremely low likelihood.

@0xjuaan I agree with this, but as far as I understood, the attack is also possible with LTV 98%. Or did I not understand correctly?

0xjuaan

You're right, it is technically possible if liquidators choose not to earn free profits, but isn't it too far fetched to assume that liquidators will not liquidate such a position on multiple consecutive instances when they can earn a 2% profit?

cvetanovv

@0xjuaan Yes, this issue is borderline Medium/Low, and it is hard to judge if it is valid or not(Low severity).

What I can point out as another augment that maybe the attack is very difficult to accomplish is that the Readme states that there will be Liquidator bots:

Are there any off-chain mechanisms or off-chain procedures for the protocol (keeper bots, arbitrage bots, etc.)?

  • Liquidator bots: maintain protocol solvency through timely liquidation of risky positions Reallocation bots: used to rebalance SuperPool deposits among respective base pools

However, there is still a situation in which this attack can be executed. The malicious user will have to wait for high volatility in the market and simultaneously preform the attack before the bots liquidate the position, which is very difficult.

Because of that, I think it is rather Low severity. @10xhash, if you want, you can provide new arguments in favor of it being Medium.

Planning to accept the escalation and invalidate the issue.

10xhash

LTV=98%, oracle possible deviation is >= 2% Min Debt = from 0 to 0.05 ETH Liquidation Fee = 0 (Might be increased to 20-30% in the future)

There are multiple scenarios where an attacker can create positions that will make liquidators have to suffer losses in order to liquidate:

  1. High LTV wait for oracle deviation of >= 2%
  2. High LTV, low min debt
  3. High LTV, higher liquidation fees

The protocol is not planned to stop an attacker from accruing bad debt to oneself

cvetanovv

On that issue, I changed my mind a few times because each comment changed my mind slightly one way or the other.

There is another issue in this contest related to High TVL and the risk of bad debt due to price volatility. There is a valid situation where the price can fall by more than 2%, I see no reason why it should not apply here.

Therefore, my last decision is to reject the escalation.

WangSecurity

Result: Medium Unique

sherlock-admin4

Escalations have been resolved successfully!

Escalation status:

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/sentimentxyz/protocol-v2/pull/336

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

Impact

Positions can become unliquidatable, causing the protocol to accrue bad debt and depositors from other pools to lose assets; however, the attack requires specific conditions and may be difficult to execute.

What the attacker needed

Attacker can create a pool; attacker can borrow and incur bad debt; liquidators do not liquidate in time

The fix

The protocol team fixed this issue in a pull request.

How it was found

  1. Attacker creates a pool with 1e18 assets and 1e18 shares.
  2. Attacker borrows 1e18 - 1, putting the position into bad debt and triggering rebalanceBadDebt.
  3. After rebalance, assets left = 1 and shares = 1e18.
  4. Attacker deposits 1e18 tokens and receives 1e36 shares.
  5. Attacker repeats the process to further deflate share value and increase total shares.
  6. Attacker borrows from the infected pool and other pools, then waits for interest to cause overflow in getBorrowsOf and isPositionHealthy, preventing liquidation.

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 pool, shares represent a depositor's portion of the pool. When bad debt is rebalanced, the pool's total assets are reduced but the number of shares stays the same, so each share becomes worth less. An attacker can exploit this by repeatedly causing bad debt, making shares worth almost nothing, then depositing a large amount to receive an enormous number of shares. This can push the total share count so high that it overflows, breaking the functions that check if a position is healthy and preventing liquidators from closing the attacker's position.

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 hash

View all

27 more disclosed reports, best first.

More from Sentiment V2

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.