# Incorrect price for negative ticks due to lack of rounding down

Predy's callUniswapObserve truncates instead of rounding toward negative infinity for negative tick deltas, yielding a tick up to one too high and mispriced TWAP.

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

**Target:** Uniswap V3 TWAP oracle helper (UniHelper.callUniswapObserve)
**Root cause:** Integer division of a negative tickCumulatives delta truncates toward zero rather than rounding toward negative infinity, so the derived int24 tick is up to one tick higher than Uniswap's OracleLibrary.consult would return.
**Steps:**
1. Call `callUniswapObserve` which invokes `IUniswapV3PoolOracle.observe` and decodes `int56[] tickCumulatives`.
2. Compute `int24((tickCumulatives[1] - tickCumulatives[0]) / int56(int256(ago)))` — Solidity truncates toward zero.
3. When delta is negative and `delta % secondsAgo != 0`, the resulting tick is one higher than the correct floor value.
4. Compare with Uniswap `OracleLibrary.consult`, which decrements `arithmeticMeanTick` when `tickCumulativesDelta < 0 && tickCumulativesDelta % secondsAgo != 0`.
5. Feed the inflated tick into `TickMath.getSqrtRatioAtTick` to observe the resulting price deviation.
**How found:** Compared Predy's UniHelper TWAP tick computation against Uniswap's canonical OracleLibrary.consult implementation and noticed the missing negative-infinity rounding branch.
**Insight:** When porting Uniswap OracleLibrary TWAP math, check that signed integer division rounds toward negative infinity; Solidity truncates toward zero, biasing negative ticks upward by one.

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

**Vulnerable tick calculation in callUniswapObserve**

```
int56[] memory tickCumulatives = abi.decode(data, (int56[]));

        int24 tick = int24((tickCumulatives[1] - tickCumulatives[0]) / int56(int256(ago)));

        uint160 sqrtPriceX96 = TickMath.getSqrtRatioAtTick(tick);
```

**Uniswap OracleLibrary consult rounding-down reference**

```
arithmeticMeanTick = int24(tickCumulativesDelta / secondsAgo);
        // Always round to negative infinity
        if (tickCumulativesDelta < 0 && (tickCumulativesDelta % secondsAgo != 0)) arithmeticMeanTick--;
```

**Recommended mitigation rounding-down fix**

```
if (tickCumulativesDelta < 0 && (tickCumulativesDelta % secondsAgo != 0)) tick--;
```

