# Integer overflow in observation index calculation leads to denial of service

uint16 overflow in Strategy.checkPoolActivity observation index calc reverts, bricking rebalance/compound/leveraged opens once cardinality+currentIndex exceeds 2^16.

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

**Target:** Strategy.sol checkPoolActivity / Uniswap V3 pool oracle
**Root cause:** observationCardinality and currentIndex are uint16; their sum overflows when >= 2^16, reverting the index computation.
**Steps:**
1. Attacker calls UniswapV3Pool.increaseObservationCardinalityNext(60000) on the pool used by Strategy (~$8.75 on Base).
2. Wait until currentIndex grows so observationCardinality + currentIndex >= 2^16.
3. checkPoolActivity reverts with panic 0x11; rebalance/compound/addVestingPosition/openLeveragedPosition all revert until currentIndex wraps to 0.
**How found:** Code review of the observation index arithmetic in checkPoolActivity, noticing both operands are uint16 and the addition can exceed 2^16; confirmed with a Foundry PoC and gas-cost appendix.
**Exploitation:** Attacker cheaply raises observation cardinality on the underlying Uniswap V3 pool; once currentIndex advances enough, the uint16 addition overflows and every Strategy function calling checkPoolActivity reverts, freezing rebalances and locking out-of-range funds.
**Insight:** When a contract reads Uniswap V3 slot0 fields (observationCardinality, currentIndex) as uint16 and does arithmetic on them, check for overflow in sums; an attacker can cheaply inflate cardinality via increaseObservationCardinalityNext to force the overflow.

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

**Foundry PoC triggering uint16 overflow**

```
uint16 observationCardinality = 2**15 + 1;
        uint16 currentIndex = 2**15;
        uint16 i = 1;
    
        uint256 index = (observationCardinality + currentIndex - i) % observationCardinality;
```

**PoC increasing observation cardinality on pool**

```
IUniswapV3Pool pool = IUniswapV3Pool(factory.getPool(WETH, USDT, 500));
        (uint160 sqrtPriceX96, int24 tick,, uint16 observationCardinality, uint16 observationCardinalityNext,,) = pool.slot0();
        console.log("observationCardinality", observationCardinality);
        console.log("observationCardinalityNext", observationCardinalityNext);

        uint256 gasStart = gasleft();
        pool.increaseObservationCardinalityNext(observationCardinality + 100);
```

