# Strategy main ticks are set according to the tick in slot0, leading to incorrect allocation and loss of funds

Yieldoor Strategy sets main position ticks from slot0 tick instead of sqrtPrice, misallocating liquidity at tick boundaries and losing fees.

- Payout: Audit contest
- Severity: high
- Program: Yieldoor
- Found by: 0x73696d616f
- Disclosed: 2025-02-21
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-02-yieldoor-judging/issues/93
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-02-yieldoor%3AH-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:oracle-manipulation

**Target:** Uniswap V3 LP strategy contract (Strategy.sol)
**Root cause:** Strategy uses pool.slot0() tick to derive main position ticks; when price sits at a tick boundary the stored tick is off by one (tick = priceTick-1), so the range is asymmetric around the true price.
**Steps:**
1. Fork Base at block 26874136 with pool 0x20E0...3e7e, WBTC/USDC, add 1e18 liquidity.
2. Swap 100e18 WBTC with sqrtPriceLimitX96 = TickMath.getSqrtRatioAtTick(-1769) to push price to boundary.
3. Call `strategy.rebalance()` as rebalancer after 10 min skip.
4. Observe slot0 tick = -1770 but sqrtPriceX96 equals sqrtRatioAtTick(-1769); mainPos ticks = [-1772,-1768].
5. Swap 1 wei USDC; tick moves to -1769, proving only 1 spacing to upper bound vs 3 to lower.
**How found:** Noticed slot0 tick is set to priceTick-1 when price crosses a left boundary, so the tick lags the actual sqrtPrice; hypothesized the strategy's tick-based range would be asymmetric and confirmed with a boundary swap PoC.
**Insight:** When deriving ranges from Uniswap V3 slot0, convert sqrtPriceX96 via TickMath rather than trusting the cached tick, since the tick is only updated on crossing and can be off by one at boundaries.

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

**Foundry PoC test for wrong ticks from slot0**

```
function test_POC_WrongTicks_DueToNotUsingSqrtPriceX96() public {
    (uint160 sqrtPriceX96, int24 tick,,,,,) = pool.slot0();
    assertEq(tick, -1769);

    //@audit swap to clear current tick token0 liquidity
    uint256 amountToSwap = 100e18;
    deal(address(wbtc), depositor, amountToSwap);
    vm.startPrank(depositor);
    IMainnetRouter.ExactInputSingleParamsV2 memory swapParams;
    swapParams.tokenIn = address(wbtc);
    swapParams.tokenOut = address(usdc);
    swapParams.recipient = depositor;
    swapParams.fee = 100;
    swapParams.amountIn = amountToSwap;
    swapParams.sqrtPriceLimitX96 = TickMath.getSqrtRatioAtTick(-1769);
    wbtc.approve(uniRouter, amountToSwap);
    IMainnetRouter(uniRouter).exactInputSingle(swapParams);

    vm.startPrank(rebalancer);
    skip(10 minutes);
    IStrategy(strategy).rebalance();

    IStrategy.Position memory mainPos = IStrategy(strategy).getMainPosition();
    (sqrtPriceX96, tick,,,,,) = pool.slot0();
    assertEq(sqrtPriceX96, TickMath.getSqrtRatioAtTick(tick + 1)); //@audit price is in tick -1769 actually
    assertEq(tick, -1770); //@audit but current tick is 1 more
    assertEq(mainPos.tickLower, -1772);
    assertEq(mainPos.tickUpper, -1768);

    //@audit swaps just 1 wei, which is enough to cross to next tick.
    //@audit thus, the position is not 50/50 symmetric.
    amountToSwap = 1;
    deal(address(usdc), depositor, amountToSwap);
    vm.startPrank(depositor);
    swapParams.tokenIn = address(usdc);
    swapParams.tokenOut = address(wbtc);
    swapParams.recipient = depositor;
    swapParams.fee = 100;
    swapParams.amountIn = amountToSwap;
    swapParams.sqrtPriceLimitX96 = 0;
    usdc.approve(uniRouter, amountToSwap);
    IMainnetRouter(uniRouter).exactInputSingle(swapParams);

    mainPos = IStrategy(strategy).getMainPosition();
    (, tick,,,,,) = pool.slot0();
    assertEq(tick, -1769); //@audit proves price moves outside range in just 1 wei swap
}
```

