# Incorrect modulo calculation in secondary position ticks leads to active position and division by zero

Negative-tick modulo bug in Yieldoor's secondary position tick math makes the out-of-range position active and can cause division-by-zero reverts in rebalance.

- Payout: Audit contest
- Severity: medium
- Program: Yieldoor
- Found by: 000000
- Disclosed: 2025-02-21
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-02-yieldoor-judging/issues/126
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-02-yieldoor%3AM-6
- Tags: area:web3 domain:web3 impact:dos impact:integrity kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** Uniswap V3 strategy contract (Strategy.sol)
**Root cause:** `_setSecondaryPositionsTicks` computes `tick % tickSpacing` without correcting negative modulo (unlike `_setMainTicks`), so tickLower/tickUpper are misaligned; with positionWidth=4*tickSpacing and isLowerSided, tickLower==tickUpper.
**Steps:**
1. Set tickSpacing=60, positionWidth=240, current tick=-91, bal0in1>=bal1.
2. Call `rebalance()`; `_setMainTicks` corrects modulo to 29, isLowerSided=true, mainPosition.tickUpper=0.
3. `_setSecondaryPositionsTicks` uses modulo=-31: tickLower=-91-(-31)+60=0, tickUpper=0.
4. `_addLiquidityToSecondaryPosition` calls `LiquidityAmounts#getLiquidityForAmounts` with equal ticks -> division by zero, revert.
5. Case 1: tick=-121, bal0in1<bal1 -> tickUpper=-120 > current tick (-121), secondary position becomes active.
**How found:** Noticed `_setMainTicks` explicitly corrects negative modulo (`if (modulo<0) modulo+=tickSpacing`) but `_setSecondaryPositionsTicks` omits the same correction; traced concrete negative-tick examples to show active position and equal-tick division by zero.
**Insight:** When one function in a codebase patches a language quirk (Solidity's truncated-toward-zero `%` for negatives) and a sibling function copies the math without the patch, that asymmetry is a reliable bug signal—diff the two implementations.

