sherlock-audit / 2024-02-perpetual-judging

2 stars 2 forks source link

PUSH0 - USDT/USDC depeg event will pit both makers at a highly risky position due to arbitrage #26

Closed sherlock-admin4 closed 5 months ago

sherlock-admin4 commented 5 months ago

PUSH0

medium

USDT/USDC depeg event will pit both makers at a highly risky position due to arbitrage

Summary

The issue has two highlights:

While the peg normally does not matter for a perpetual exchange (as it is only used to calculate the PnL), we show that in the event of a stablecoin depeg, there is an arbitrage route through the two makers that will pit both makers at a highly risky position. Furthermore, we also show that at least one of the makers will incur damage due to the following price movement.

We also show some other possible impacts on the Spot Maker in the event of a depeg.

Vulnerability Detail

First of all, we note that Pyth does not have feeds for ASSET/USD, but not ASSET/USDT or ASSET/USDC. That means that during a depegging event, assets will be wrongly priced.

For a perpetual exchange, this is not a problem yet, as collaterals do not need to be pegged, but is only used as a denominator/collateral asset to settle PnLs.

However since the Oracle Maker quotes price based on Oracles, and the Spot Hedge Based Maker quotes price based on AMM prices, there is a sizeable price discrepancy between the two makers in the event of a stablecoin depeg. An arbitrage between this price discrepancy will:

This issue assumes that the market in question has both types of makers, which is how it is described in the audit doc's ClearingHouse sequence diagram.

Proof of concept

We directly describe this scenario using an example of a depeg event.

Assuming the Uniswap pool is sufficiently liquid (as it should be). In a normal operation without a depeg:

Now what happens during a depeg here is that:

The arbitrage happens when the position is closed using the Oracle maker:

The final outcome is:

In other words:

When the peg is returned, the damage is not reversed. Since the AMM and Oracle price are roughly equal during a peg, there is no incentives nor a potential arbitrage to reverse the two makers' positions. It will take another depeg in the opposite direction to get a natural movement in the de-risking position, which is highly unlikely to occur soon enough right after the initial depeg event.

While pitting opposite positions is technically possible even without the depeg, the attacker will incur loss due to price impacts by AMM, and the price spread by the Oracle Maker. However with the depeg, there is a large price discrepancy between the two makers (i.e. oracle price and external AMM price), and this "attack" becomes profitable in the form of a natural arbitrage scenario, albeit with the same risk impact, which is the actual problem here.

Other impacts

There are also other impacts that affects the Spot Based Maker, due to its reliant on both the oracle price and AMM price:

Impact

During a stablecoin depeg, there is an arbitrage scenario that:

There are also several other impacts mentioned above.

Code Snippet

https://github.com/sherlock-audit/2024-02-perpetual/blob/main/perp-contract-v3/src/oracle/pythOracleAdapter/PythOracleAdapter.sol#L12

Also affects any occurence of _getPrice() throughout the codebase.

Tool used

Manual review

Recommendation

The Pyth Oracle Adapter (or any instance of _getPrice() in general) should combine two feeds, ASSET/USD and the inverse of COLLATERAL/USD to ensure accurate pricing against the external market, preventing the price discrepancy in a depeg event.

Duplicate of #118

sherlock-admin3 commented 5 months ago

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

santipu_ commented:

Medium

takarez commented:

its trusted to provide accurate data