# Attackers can sandwich their own trades up to the price bands

SpotHedgeBaseMaker accepts direct ClearingHouse calls, letting an attacker sandwich their own trade against the UniswapV3 hedge pool to extract value or create bad debt.

- Payout: Contest reward
- Severity: medium
- Program: Perpetual
- Credited: IllIllI
- Disclosed: 2024-02-19
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-02-perpetual-judging/issues/119
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-8
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:business-logic vuln:oracle-manipulation

**Target:** SpotHedgeBaseMaker / ClearingHouse settlement against UniswapV3 pool
**Root cause:** SpotHedgeBaseMaker.isValidSender() returns true for any address, so anyone can settle trades directly through ClearingHouse instead of only the permissioned Gateway/relayer, and the hedge swap price is taken from a manipulable UniswapV3 pool.
**Steps:**
1. Deposit margin for attacker and liquidity into SpotHedgeBaseMaker.
2. Skew UniswapV3 pool via `uniswapV3Router.exactInput` swapping base tokens to move price.
3. Call `clearingHouse.openPosition` with `maker=SpotHedgeBaseMaker`, `isBaseToQuote=true`, opening a short so SHBM hedges at the skewed price.
4. Swap back via `exactInput` on the reverse path to unwind the skew and realize profit.
5. Abandon the perp account holding bad debt.
**How found:** Code reading: noticed isValidSender returns true unconditionally, so ClearingHouse settlement isn't restricted to the Gateway; hypothesized the UniswapV3 hedge price could be sandwiched and built a Foundry PoC.
**Exploitation:** Attacker flash-loans/uses own capital to imbalance the UniswapV3 pool, opens a position directly against SpotHedgeBaseMaker (bypassing the keeper) so the maker hedges at the skewed price, then rebalances the pool in the same transaction, capturing the difference while leaving the perp position in bad debt.
**Escalation:** Larger capital and larger price gaps increase extraction; price-band bypass via differing Pyth prices noted in a companion issue.
**Insight:** When a maker hedges against an AMM, check whether settlement entrypoints are permissioned; if any caller can invoke settlement directly, the AMM price used for hedging becomes attacker-controllable within one transaction.
