# PanopticFactory uses spot price when deploying new pools, resulting in liquidity manipulation when minting

PanopticFactory reads Uniswap v3 slot0 spot price to size initial full-range liquidity, letting an attacker manipulate price via flashloan so deployer over-deposits one token.

- Payout: Audit contest
- Severity: medium
- Program: Panoptic
- Found by: DadeKuma
- Disclosed: 2024-06-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-panoptic-findings/issues/537
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-panoptic%3AM-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:flash-loan vuln:oracle-manipulation

**Target:** PanopticFactory.deployNewPool / Uniswap v3 pool slot0
**Root cause:** deployNewPool derives fullRangeLiquidity from v3Pool.slot0() spot sqrtPriceX96 with no TWAP or oracle check, so the token0/token1 liquidity split follows a manipulable price.
**Steps:**
1. Deployer calls deployNewPool with approvals to the factory.
2. Attacker flashloans and swaps in the target v3 pool to move slot0 sqrtPriceX96.
3. deployNewPool reads manipulated currentSqrtPriceX96 and computes fullRangeLiquidity via Math.mulDiv96RoundingUp / mulDivRoundingUp.
4. Resulting mint is unbalanced, depositing excess of one token; attacker sandwiches/reverts price to profit at deployer's expense.
**How found:** Code review noting deployNewPool uses slot0() spot price while other Panoptic paths rely on oracles/TWAP, flagging absence of price checks.
**Exploitation:** Attacker manipulates the pool spot price with a flashloan immediately before the deployer's deployNewPool transaction, causing the factory to mint liquidity skewed toward one token; attacker unwinds the swap to capture the value the deployer over-deposited, especially where deployer granted infinite approval.
**Insight:** When auditing pool-deployment or liquidity-sizing logic, check whether initial liquidity math reads slot0 spot price rather than TWAP; any spot read combined with user approvals is sandwichable even if the function seems benign.

## Proof of concept (copied exactly from the original report)

**Spot price used to compute full-range liquidity**

```
(uint160 currentSqrtPriceX96, , , , , , ) = v3Pool.slot0();

	// For full range: L = Δx * sqrt(P) = Δy / sqrt(P)
	// We start with fixed token amounts and apply this equation to calculate the liquidity
	// Note that for pools with a tickSpacing that is not a power of 2 or greater than 8 (887272 % ts != 0),
	// a position at the maximum and minimum allowable ticks will be wide, but not necessarily full-range.
	// In this case, the `fullRangeLiquidity` will always be an underestimate in respect to the token amounts required to mint.
	uint128 fullRangeLiquidity;
	unchecked {
	    // Since we know one of the tokens is WETH, we simply add 0.1 ETH + worth in tokens
	    if (token0 == WETH) {
	        fullRangeLiquidity = uint128(
@>	            Math.mulDiv96RoundingUp(FULL_RANGE_LIQUIDITY_AMOUNT_WETH, currentSqrtPriceX96)
	        );
	    } else if (token1 == WETH) {
	        fullRangeLiquidity = uint128(
	            Math.mulDivRoundingUp(
	                FULL_RANGE_LIQUIDITY_AMOUNT_WETH,
	                Constants.FP96,
@>	                currentSqrtPriceX96
	            )
	        );
	    } else {
	        // Find the resulting liquidity for providing 1e6 of both tokens
	        uint128 liquidity0 = uint128(
@>	            Math.mulDiv96RoundingUp(FULL_RANGE_LIQUIDITY_AMOUNT_TOKEN, currentSqrtPriceX96)
	        );
	        uint128 liquidity1 = uint128(
	            Math.mulDivRoundingUp(
	                FULL_RANGE_LIQUIDITY_AMOUNT_TOKEN,
	                Constants.FP96,
@>	                currentSqrtPriceX96
	            )
	        );

	        // Pick the greater of the liquidities - i.e the more "expensive" option
	        // This ensures that the liquidity added is sufficiently large
	        fullRangeLiquidity = liquidity0 > liquidity1 ? liquidity0 : liquidity1;
```

