Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsidian - Liquidation fee is incorrectly calculated, leading to unprofitable liquidations #91

Open
sherlock-admin4 opened this issue Aug 24, 2024 · 2 comments
Labels
Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A Medium severity issue. Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Aug 24, 2024

Obsidian

High

Liquidation fee is incorrectly calculated, leading to unprofitable liquidations

Summary

Incorrect liquidation fee calculation makes liquidations unprofitable, leading to insolvency.

Root Cause

During PositionManager.liquidate() , two things happen:

  1. An amount x of the position’s collateral is paid to the liquidator (link)
  2. The liquidator pays off the debt of the position (link)

During step 1, the liquidation fee is effectively calculated as liquidationFee.mulDiv(x, 1e18)

This is incorrect- the correct way would be to take the liquidation fee from the profit of the liquidator, rather than from the entire amount x

Due to this inaccuracy, a large majority of liquidations will be unprofitable:

Example scenario

Consider a situation where liquidation fee is 30% (as stated in the contest README)

Say LTV = 90%, Debt value = $90, Collateral value drops from $100 to $98

Now, since the position LTV (90/98) is greater than the set LTV (90/100), the position is liquidatable

A liquidator aims to pay off the debt and receive the $98 worth of collateral, effectively buying the collateral at a discount of ~8%

However, They will only receive 70% of the $98 (due to the 30% liquidation fee), so they can only receive $68.6

This is extremely unprofitable since they have to pay off $90 worth of debt, and only receive $68.6 as a reward.

The correct approach to calculating fee would be the following:

  1. Calculate liquidator profit = Reward - Cost = $98 - $90 = $8
  2. Calculate liquidator fee = feePercentage*profit = 30% of $8 = $2.4

This ensures that liquidations are still incentivised

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

Liquidations are unprofitable due to liquidation fee being calculated incorrectly.

This leads to bad debt and insolvency since there is no incentive to liquidate.

PoC

No response

Mitigation

Consider calculating the profit of the liquidation first, and take the fee based on that

@github-actions github-actions bot added the Medium A Medium severity issue. label Sep 5, 2024
@sherlock-admin3 sherlock-admin3 added Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed labels Sep 10, 2024
@z3s z3s added the Has Duplicates A valid issue with 1+ other issues describing the same vulnerability label Sep 15, 2024
This was referenced Sep 15, 2024
@sherlock-admin4 sherlock-admin4 changed the title Glamorous Blush Gecko - Liquidation fee is incorrectly calculated, leading to unprofitable liquidations Obsidian - Liquidation fee is incorrectly calculated, leading to unprofitable liquidations Sep 15, 2024
@sherlock-admin4 sherlock-admin4 added the Reward A payout will be made for this issue label Sep 15, 2024
@0xjuaan
Copy link

0xjuaan commented Oct 4, 2024

Hi @cvetanovv I forgot to escalate this (hard to keep track of so many), but I think everyone would agree this is high severity

@sherlock-admin2
Copy link
Contributor

The protocol team fixed this issue in the following PRs/commits:
sentimentxyz/protocol-v2#339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A Medium severity issue. Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

5 participants