# Reallocation depends on the slot0 price, which can be manipulated

Predy's permissionless reallocate reads manipulable Uniswap V3 slot0 spot price/tick, letting an attacker force reallocation to an extreme tick range and drain LP funds via swap fees.

- Payout: Audit contest
- Severity: high
- Program: Predy
- Found by: ayden
- Disclosed: 2024-07-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-predy-findings/issues/209
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-predy%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:oracle-manipulation

**Target:** Perp.sol reallocate / Uniswap V3 slot0 price consumption
**Root cause:** reallocate() trusts the manipulable Uniswap V3 slot0 spot sqrtPrice and currentTick to decide whether and where to rebalance, instead of a manipulation-resistant TWAP.
**Steps:**
1. Attacker observes reallocate() is permissionless and reads slot0 currentSqrtPrice/currentTick in Perp.sol::reallocate
2. Manipulate the Uniswap V3 pool spot price momentarily so currentTick falls outside [tickLower, tickUpper]
3. Call reallocate(); isOutOfRange becomes true and tick is set to tickLower/tickUpper
4. swapForOutOfRange computes deltaPosition0/1 from the manipulated currentSqrtPrice vs tickSqrtPrice and updates rebalance position
5. Restore price and capitalize on liquidity reallocated into an extreme tick range, causing LP loss; repeat to accrue swap fees
**How found:** Code reading of reallocate() revealed it consumes slot0 spot sqrtPrice and currentTick directly; since slot0 is spot-manipulable and reallocate is permissionless, the out-of-range branch can be forced.
**Exploitation:** Attacker flash-manipulates the Uniswap V3 spot price to push the tick out of range, triggers the permissionless reallocate so the LP position is moved to an extreme tick, then unwinds the price move and profits from the mispriced/reallocated liquidity while the pool eats swap fees.
**Escalation:** Repeated reallocations each incur swap fees, continuously draining a pairId's LP funds.
**Insight:** When a permissionless keeper-style function reads slot0 to decide state changes, check both sqrtPrice AND currentTick — a TWAP fix for price alone is insufficient because the tick is also attacker-malleable.

