Skip to content
Business logic Audit finding Advanced

One pair can steal another pair’s Uniswap liquidity during reallocate() call if both pairs operate on the same Uniswap pool and both have the same upper and lower tick during reallocation

The Predy protocol's reallocate() function does not verify that the Uniswap liquidity in a given tick range belongs exclusively to the calling pair. If two pairs share the same Uniswap pool and tick range, reallocating one pair can steal liquidity from the other, breaking internal accounting and preventing users from closing or liquidating positions.

Eeyore Follow with nnez

Originally disclosed on Code4rena

Submitted by Eeyore, also found by nnez

During the reallocation of a pair, the Predy protocol does not verify that the liquidity in the Uniswap pool between the upper and lower tick belongs exclusively to that pair. Instead, it takes the entire liquidity from the range that the pair currently operates within.

In a scenario where a trusted operator creates two pairs for the same Uniswap pool, perhaps to have different quote tokens as margin tokens, there is a possibility that both pairs will have the same upper and lower tick setup.

In such a situation, if a user trades gamma on the first pair, and later the price moves outside the threshold of the second pair, if anyone performs a reallocation on that second pair, even if there were no gamma trades on the second pair, the second pair will steal liquidity from the user’s open gamma position.

This will cause all accounting within the protocol for these two pairs to be compromised.

Impact

Internal protocol accounting will be disrupted, potentially making it impossible to close or liquidate positions properly.

Proof of Concept

  1. A trusted operator registers a pair for USDC/ETH with USDC as the quote token.
  2. The same trusted operator registers another pair for USDC/ETH with ETH as the quote token.
  3. Both pairs have the same lower and upper tick settings.
  4. A user trades gamma on the first pair.
  5. The price moves outside the threshold of the second pair, threshold setting can differ between them.
  6. Any user can trigger a reallocate() function call on the second pair, even if it originally had no liquidity because there were no gamma trades.
  7. Liquidity is diverted from the first pair, despite no benefit to any user, resulting in incorrect accounting for users of the first pair.

Note: In such a scenario, the user’s gamma position in the first pair cannot be closed properly. Any reallocation done on the first pair operates with empty liquidity, making it impossible to liquidate the user’s gamma positions.

PoC Tests

This test illustrates how to one pair steals other pair liquidity.

Create test/PoC/TestPoCReallocate.t.sol and run forge test --match-test testPoCReallocateStealFromOtherPair -vvvv.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {TestPool} from "../pool/Setup.t.sol";
import {TestTradeMarket} from "../mocks/TestTradeMarket.sol";
import {IPredyPool} from "../../src/interfaces/IPredyPool.sol";
import {IFillerMarket} from "../../src/interfaces/IFillerMarket.sol";
import {Constants} from "../../src/libraries/Constants.sol";

contract TestPoCReallocate is TestPool {
    TestTradeMarket private tradeMarket;
    address private filler;

    function setUp() public override {
        TestPool.setUp();

        registerPair(address(currency1), address(0));
        registerPair(address(currency1), address(0));

        predyPool.supply(1, true, 1e8);
        predyPool.supply(1, false, 1e8);

        predyPool.supply(2, true, 1e8);
        predyPool.supply(2, false, 1e8);

        tradeMarket = new TestTradeMarket(predyPool);

        filler = vm.addr(12);

        currency0.transfer(address(tradeMarket), 1e8);
        currency1.transfer(address(tradeMarket), 1e8);

        currency0.approve(address(tradeMarket), 1e8);
        currency1.approve(address(tradeMarket), 1e8);

        currency0.mint(filler, 1e10);
        currency1.mint(filler, 1e10);
        vm.startPrank(filler);
        currency0.approve(address(tradeMarket), 1e10);
        currency1.approve(address(tradeMarket), 1e10);
        vm.stopPrank();
    }

    function testPoCReallocateStealFromOtherPair() public {
        // user opens gamma position on pair with id = 1
        {
            IPredyPool.TradeParams memory tradeParams =
                IPredyPool.TradeParams(1, 0, -90000, 100000, abi.encode(_getTradeAfterParams(2 * 1e6)));

            tradeMarket.trade(tradeParams, _getSettlementData(Constants.Q96));
        }

        _movePrice(true, 5 * 1e16);

        // reallocation on pair id = 2 steals from pair id = 1
        assertTrue(tradeMarket.reallocate(2, _getSettlementData(Constants.Q96 * 15000 / 10000)));

        _movePrice(true, 5 * 1e16);

        // reallocation on pair id = 1 can be done but there is 0 liquidity
        assertTrue(tradeMarket.reallocate(1, _getSettlementData(Constants.Q96 * 15000 / 10000)));

        // user can't close his position on pair with id = 1, internal accounting is broken
        {
            IPredyPool.TradeParams memory tradeParams =
                IPredyPool.TradeParams(1, 1, 90000, -100000, abi.encode(_getTradeAfterParams(2 * 1e6)));

            tradeMarket.trade(tradeParams, _getSettlementData(Constants.Q96));
        }
    }
}

Recommended Mitigation Steps

  1. Perform internal accounting of the liquidity mined within each pair and allow reallocation of only that amount of liquidity during the reallocate() function call.
  2. Collect fees from the range proportionally to the liquidity held by each pair.

Assessed type

Uniswap

syuhei176 (Predy) confirmed and commented:

A great find.

0xsomeone (judge) commented:

The Warden and its duplicate have demonstrated that the accounting system of the Predy pool will be compromised in case overlapping Uniswap V3 tick ranges are utilized in distinct pair instances with the same tokens.

The severity of the submission has been aptly demonstrated by the PoC provided, and a trusted party is involved within it. Per the audit’s description, the trusted operator role should only be able to add new pairs to the system, and being able to maliciously take advantage of this permission to the effect described by the PoC is sufficient in rendering this submission a valid HM vulnerability.

In reality, the operator will add pairs requested by normal users (per the duplicate submission’s contents) and a pair configuration with the same range and token pair but a different quote token would appear innocuous and could easily be presumed as a valid action.


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

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 reallocate() function assumes all liquidity in the tick range belongs to the pair, without tracking per-pair liquidity contributions.

Impact

Internal protocol accounting will be disrupted, potentially making it impossible to close or liquidate positions properly.

What the attacker needed

Trusted operator creates two pairs; same Uniswap pool and tick range; user has open gamma position; price moves outside threshold

The fix

The protocol should track liquidity per pair internally and only allow reallocation of that pair's own liquidity, and collect fees proportionally.

How it was found

  1. A trusted operator registers a pair for USDC/ETH with USDC as the quote token.
  2. The same trusted operator registers another pair for USDC/ETH with ETH as the quote token.
  3. Both pairs have the same lower and upper tick settings.
  4. A user trades gamma on the first pair.
  5. The price moves outside the threshold of the second pair.
  6. Any user triggers reallocate() on the second pair, diverting liquidity from the first pair.

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.

A pair is a trading pool in Predy that uses Uniswap underneath. When someone reallocates a pair, the code grabs all the liquidity in a certain price range from Uniswap, without checking if that liquidity actually belongs to this pair. If two pairs use the same Uniswap pool and same price range, one can take the other's liquidity, messing up the accounting so users cannot close their positions.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Eeyore

View all

7 more disclosed reports, best first.

More from Predy

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.