sherlock-audit / 2024-02-perpetual-judging

2 stars 2 forks source link

PUSH0 - LP can instantly arbitrage and drain any Maker by updating the Pyth price #58

Closed sherlock-admin2 closed 6 months ago

sherlock-admin2 commented 7 months ago

PUSH0

high

LP can instantly arbitrage and drain any Maker by updating the Pyth price

Summary

An LP who turns malicious can arbitrage any Maker pool by self-frontrun and self-backrun a Pyth price update, thereby manipulating the pool shares exchange rate.

Furthermore, this attack can be done in combination with a flashloan, enabling an almost-complete draining of Maker LP pool.

Vulnerability Detail

The Pyth oracle setting allows users to fetch a signed price from the Wormhole messaging bridge, then transfer it to the Pyth contract to update the price. Since the user can act on a new price right away, this opens up room for instant-arbing as the market is dependent on the Pyth price.

While there is a mitigation in place for traders against an Oracle Maker (every orders must go through the relayer), depositing and withdrawing by LPs is not protected against such an attack.

This opens up room for an instant-arbing scenario that will allow a malicious LP to siphon away the pool, eventually draining it.

Proof of concept

Let's say:

They can perform the following attack:

Repeating this attack will eventually allow Alice to get away with much value before the admin can act.

This attack is easily possible without many of the conditions mentioned above:

Impact

LP can drain the pool based on a very small price difference by the Pyth oracle.

Code Snippet

https://github.com/sherlock-audit/2024-02-perpetual/blob/main/perp-contract-v3/src/maker/OracleMaker.sol#L228

https://github.com/sherlock-audit/2024-02-perpetual/blob/main/perp-contract-v3/src/maker/SpotHedgeBaseMaker.sol#L303

Tool used

Manual Review

Recommendation

Providing and/or withdrawing liquidity (for either makers) should go through a relayer, much like the current setting for Oracle Maker traders. This will severely limit arbing possibilities (equal to that of the Oracle Maker), and will completely eliminate the possibility of flashloan.

Duplicate of #123

sherlock-admin4 commented 6 months ago

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

takarez commented:

the pyth is expected to provide an accurate data

IllIllI000 commented 6 months ago

@nevillehuang I believe this should have been a duplicate of https://github.com/sherlock-audit/2024-02-perpetual-judging/issues/123