Skip to content
DoS Audit finding Intermediate

Wide cross-zero ranges revert (InvertedRange) due to sign-loss in tick→index and no wrap support

A sign-loss bug in tick-to-index conversion and a lack of wrap-around support in route construction cause wide cross-zero ranges to revert with InvertedRange. An attacker cannot exploit this for gain, but legitimate users cannot open, modify, or close such ranges without manually splitting the interval.

0xpinkman Follow with anonymousjoe, iam0ti and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-ammplify-judging/issues/336

Found by

0xpinkman, anonymousjoe, iam0ti, vtim, web3made

Summary

TreeTickLib.tickToTreeIndex casts int→uint24 before adding the offset and never applies % rootWidth. RouteImpl.make reverts whenever _right < _left and does not accept wrapped intervals. For wide cross-zero ranges (e.g., [-k, +k] with k > rootWidth/2 * tickSpacing), left > right occurs and route construction reverts. Normal cross-zero bands succeed; the failure starts exactly at the threshold.

Root Cause

Sign lost + no normalization in TreeTickLib.tickToTreeIndex

Solidity
return uint24(tick / tickSpacing) + rootWidth / 2; // cast-before-offset; no % rootWidth

No wrap-around acceptance in RouteImpl.make

Solidity
function make(uint24 _rootWidth, uint24 _left, uint24 _right) internal pure returns (Route memory) {
        if (_right < _left) revert InvertedRange(_left, _right);

The WalkerLib.modify builds the route without splitting wrapped spans

Internal Pre-conditions

  1. User (taker/maker) chooses a cross-zero range [-k, +k] where k > (rootWidth/2) * tickSpacing.
  2. A walker path is invoked (e.g., WalkerLib.modify) to build a route from the mapped indices.

External Pre-conditions

None required, pure index/route logic.

Attack Path

  1. User calls a flow that computes route for [-k, +k] (wide cross-zero).
  2. TreeTickLib.tickToTreeIndex maps ticks so that leftIndex > rightIndex-1.
  3. Route construction RouteImpl.make(rootWidth, left, right) sees _right < _left and reverts InvertedRange.
  4. The walker bubbles the revert; the operation cannot proceed.

Impact

  • Operational DoS of legitimate “very wide” cross-zero ranges: attempts to open/modify/close such ranges revert at route construction.
  • This includes near-full-range on Uniswap v3–style pools when tickSpacing=60, because rootWidth (power-of-two) is < full tick domain, so |tick/spacing| > rootWidth/2 is reachable.
  • No direct fund loss; it blocks user actions unless the caller manually splits the interval.

PoC

Solidity
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;

import { Test } from "forge-std/Test.sol";
import { TickMath } from "v4-core/libraries/TickMath.sol";
import { TreeTickLib } from "src/tree/Tick.sol";
import { Route, RouteImpl } from "src/tree/Route.sol";

contract RouteInvoker {
    function make(uint24 rootWidth, uint24 left, uint24 right) external pure returns (Route memory) {
        return RouteImpl.make(rootWidth, left, right);
    }
}

error InvertedRange(uint24 left, uint24 right);

contract PoC_Tree_CrossZero is Test {
    int24 constant TICK_SPACING = 60;

    RouteInvoker internal invoker;

    struct CaseResult {
        int24 lowTick;
        int24 highTick;
        uint24 rootWidth;
        uint24 lowIndex;
        uint24 highIndexMinus1;
        bool lowGreaterThanHigh;
        bool routeReverted;
        bytes revertData;
    }

    function setUp() public {
        invoker = new RouteInvoker();
    }

    function _normalize(uint24 idx, uint24 rootWidth) internal pure returns (uint24) {
        return idx % rootWidth;
    }

    /// @dev boundary (k = rootWidth/2 * spacing) succeeds; boundary+1 inverts & reverts.
    function test_crossZeroBoundary_thresholds() public {
        uint24 rootWidth = TreeTickLib.calcRootWidth(TickMath.MIN_TICK, TickMath.MAX_TICK, TICK_SPACING);
        uint24 half = rootWidth / 2;

        // boundary = half*spacing  → should NOT invert (wrap lands inside [0,rootWidth))
        int24 k0 = int24(int256(uint256(half))) * TICK_SPACING;
        CaseResult memory c0 = _runCase(rootWidth, -k0, k0);
        assertFalse(c0.lowGreaterThanHigh, "boundary case must not invert");
        assertFalse(c0.routeReverted, "Route.make must succeed at boundary");

        // boundary+1 → inversion: lowIndex > highIndexMinus1, Route.make reverts InvertedRange
        int24 k1 = int24(int256(uint256(half + 1))) * TICK_SPACING;
        CaseResult memory c1 = _runCase(rootWidth, -k1, k1);
        assertTrue(c1.lowGreaterThanHigh, "boundary+1 must invert");
        assertTrue(c1.routeReverted, "Route.make must revert (InvertedRange) at boundary+1");
    }

    /// @dev raw route reverts, but splitting into two wrapped routes ([left..rootWidth-1] and [0..right]) both succeed.
    function test_wrappedNormalization_succeeds() public {
        uint24 rootWidth = TreeTickLib.calcRootWidth(TickMath.MIN_TICK, TickMath.MAX_TICK, TICK_SPACING);
        uint24 half = rootWidth / 2;
        int24 k1 = int24(int256(uint256(half + 1))) * TICK_SPACING;

        // Raw indices (as used today) → invert & revert
        CaseResult memory rawCase = _runCase(rootWidth, -k1, k1);
        assertTrue(rawCase.lowGreaterThanHigh && rawCase.routeReverted, "raw must invert & revert");

        // Normalized indices (wrap-aware): split into two segments if left > right
        uint24 leftNorm = rawCase.lowIndex % rootWidth;
        uint24 rightNormMinus1 = rawCase.highIndexMinus1 % rootWidth;

        if (leftNorm <= rightNormMinus1) {
            // no wrap; single route must succeed
            (bool ok, ) = _callMake(rootWidth, leftNorm, rightNormMinus1);
            assertTrue(ok, "single normalized route should succeed");
        } else {
            // wrap; two routes must each succeed
            (bool ok1, ) = _callMake(rootWidth, leftNorm, rootWidth - 1);
            (bool ok2, ) = _callMake(rootWidth, 0, rightNormMinus1);
            assertTrue(ok1 && ok2, "wrapped normalized routes should both succeed");
        }
    }

    function _callMake(uint24 rootWidth, uint24 left, uint24 right) internal returns (bool ok, bytes memory data) {
        (ok, data) = address(invoker).call(abi.encodeWithSelector(RouteInvoker.make.selector, rootWidth, left, right));
    }

    function _runCase(
        uint24 rootWidth,
        int24 lowTick,
        int24 highTick
    ) internal view returns (CaseResult memory result) {
        result.lowTick = lowTick;
        result.highTick = highTick;
        result.rootWidth = rootWidth;

        uint24 lowIndex = TreeTickLib.tickToTreeIndex(lowTick, rootWidth, TICK_SPACING);
        uint24 highIndex = TreeTickLib.tickToTreeIndex(highTick, rootWidth, TICK_SPACING);
        uint24 highMinusOne = highIndex - 1;

        result.lowIndex = lowIndex;
        result.highIndexMinus1 = highMinusOne;
        result.lowGreaterThanHigh = lowIndex > highMinusOne;

        try invoker.make(rootWidth, lowIndex, highMinusOne) returns (Route memory) {
            result.routeReverted = false;
        } catch (bytes memory revertData) {
            result.routeReverted = true;
            result.revertData = revertData;
        }
    }
}

Mitigation

Normalize indices after applying the signed offset (e.g., (q + rootWidth/2) % rootWidth) or accept wrap in RouteImpl.make or split wrapped spans in WalkerLib.modify before calling RouteImpl.make.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Ammplify/pull/25

The original report as published on Sherlock, by 0xpinkman. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the tick-to-index conversion casts a signed integer to an unsigned one before adding an offset and never normalises the result modulo the root width, while route construction rejects any interval where the right bound is less than the left bound.

Impact

Legitimate wide cross-zero ranges, including near-full-range on Uniswap v3-style pools with tick spacing 60, cannot be opened, modified, or closed because route construction reverts; no direct fund loss occurs, but user actions are blocked unless the caller manually splits the interval.

What the attacker needed

User selects a wide cross-zero range; Range width exceeds half root width times tick spacing; No external conditions required

The fix

The protocol team fixed this issue by normalising indices after applying the signed offset, accepting wrap in route construction, or splitting wrapped spans before calling route construction.

How it was found

  1. Choose a cross-zero range where the absolute tick divided by tick spacing exceeds half the root width.
  2. Compute the tree indices for the low and high ticks using the tick-to-index function.
  3. Observe that the low index is greater than the high index minus one.
  4. Call route construction with those indices and see it revert with InvertedRange.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a smart contract bug where a calculation that converts price ticks to array indices loses the sign of negative numbers. When a user tries to set a very wide price range that crosses zero, the computed start index ends up larger than the end index, so the code rejects it as an inverted range and the transaction fails.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xpinkman

View all

1 more disclosed report, best first.

More from Ammplify

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.