# Price limit is used as the price range in internal swaps, causing swap TXs to revert

Flayer's Uniswap V4 hook passed the user's sqrtPriceLimit as the swap step target instead of deriving a target, causing internal swap math to miscompute and revert swaps.

- Payout: Audit contest
- Severity: medium
- Program: Flayer
- Found by: 0xAlix2
- Disclosed: 2024-08-06
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/402
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AM-13
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** UniswapImplementation.beforeSwap internal swap math (Uniswap V4 hook)
**Root cause:** Internal swap calls SwapMath.computeSwapStep with params.sqrtPriceLimitX96 as sqrtPriceTargetX96, but a price limit is not a price target; the target must be derived via SwapMath.getSqrtPriceTarget from the next step price and the limit.
**Steps:**
1. Set up pool with liquidity and deposit fees via uniswapImplementation.depositFees.
2. Call poolSwap.swap with SwapParams{zeroForOne: true, amountSpecified: 15 ether, sqrtPriceLimitX96: TickMath.MIN_SQRT_PRICE + 1}.
3. Observe the swap reverts because computeSwapStep uses the limit directly as target, miscomputing ethIn/tokenOut.
**How found:** Code-reading of Uniswap V4 semantics: noticed SwapParams.sqrtPriceLimitX96 is documented as a stop price, and Pool.swap translates it via SwapMath.getSqrtPriceTarget before computeSwapStep, while Flayer passes it directly as sqrtPriceTargetX96.
**Insight:** When integrating Uniswap V4 (or any AMM) math libraries, verify each parameter's semantic contract against upstream usage; a limit price and a target price are distinct and must be converted with getSqrtPriceTarget before computeSwapStep.

