Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

WATCHPUG - Liquidation should not put the market into a worse state (more bad debt). #140

Closed
sherlock-admin opened this issue Aug 15, 2023 · 1 comment
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Aug 15, 2023

WATCHPUG

high

Liquidation should not put the market into a worse state (more bad debt).

Summary

Vulnerability Detail

LiquidationFee should not exceed the total collateral of the position because that would mean that the market is paying for the liquidation with system-wide bad debt and putting the market in a worse state.

In the current implementation, liquidationFee is a percentage based on the size of the position (bounded by minLiquidationFee and maxLiquidationFee). In normal circumstances, this should work without causing any trouble. However, when the time comes that the price suddenly drops ("flash crash") or a special occurrence happens where the entire blockchain experiences downtime (happened to OP, Polygon, Arbitrum, and BSC), resulting in an inevitable sudden price change, liquidations that result in shortfalls will become possible and result in an increase of system bad debt.

PoC

Given:

There are only two users, one with a long position and another one with a short position:

  • long: 10, collateral: 100
  • short: 10, collateral: 100
  • maker: 0
  • price: 8

When:

  1. The price suddenly rises to 18
  2. PNL to long: 10 * 10 == 100, PNL to short: -100
  3. While the remaining collateral of the short user is 0, liquidation will take a fee and incur a bad debt which will result in the long user being unable to redeem all the profits.

Impact

Code Snippet

https://github.com/sherlock-audit/2023-07-perennial/blob/main/perennial-v2/packages/perennial/contracts/types/Position.sol#L292-L322

Tool used

Manual Review

Recommendation

Based on the fact that the liquidation will most certainly be executed by the bots and for the bots, as long as the return to execute a transaction is greater than the gas cost, they would do it without complaining about the low margin.

A better design is to ask for a fixed amount of liquidation deposit denominated in the native token when opening the account for the first time (similar to GMX, MakerDAO, Liquity), and combine it with a portion of the remaining collateral, but never go beyond and cause any bad debt.

Duplicate of #72

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Aug 18, 2023
@sherlock-admin
Copy link
Contributor Author

2 comment(s) were left on this issue during the judging contest.

141345 commented:

d

panprog commented:

medium or low because it's a protocol design choice and during high volatility gas prices and uncertaincy can be very high (lots of transactions can revert) so that liquidators need bigger incentive to keep liquidating.

@sherlock-admin sherlock-admin changed the title Happy Mocha Worm - Liquidation should not put the market into a worse state (more bad debt). WATCHPUG - Liquidation should not put the market into a worse state (more bad debt). Aug 23, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant