Skip to content
Business logic Audit finding Advanced

A swapper defeats the per-block price-velocity cap to amplify oracle-shock LP losses on pools using PriceVelocityGuardExtension

The PriceVelocityGuardExtension overwrites its stored reference price and block on every swap before checking the velocity limit, so multiple same-block swaps each get a fresh full maxChange budget. A swapper can therefore move the pool price by roughly N times maxChange within one block, amplifying oracle-shock losses for liquidity providers.

0x23r0 Follow with 0x3b, 0x4nonX and 47 others

Originally disclosed on Sherlock

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

This issue has been acknowledged by the team but won't be fixed at this time.

Found by

0x23r0, 0x3b, 0x4nonX, 0xAsh, 0xMehediSec, 0xSpec, 0xbepresent, 0xbzbee42, 0xeix, 0xlucky, 4987914613, AbSattar, Afriaudit, AlexScherbatyuk, Athenea, BaiMaStryke, BensonDynasty, Bizarro, Brianite, CaptSinBad, D4N0GOTHACKED, Dheeraj_Shah, Draxen, Emmy, GPT-wrapper, Gaara_, ITT, IcoinX, JeRRy0422, Jesse639, KassyOlisakwe, Kodyvim, Kvar, LeoGold, NicingMan, OrangeSantra, Orionn, Paulwilson, Peter1992, RV, Rareone, Redteamer231, Robert, Ronke, Saai, Scheggia89, Scout.007, Sky399, TheBestAuditorAlive, Tradi3, TradingViews, VeyrionSec, ViquetourOnTop, WolKalp, Yahaya-Salisu, ZeroTrust, aaron, angus14, axelot, bavin, blackgrease, bladeee, canhnguyen26, chyptex, cryptosfinders, damianbazior, daoth1nh, demonx, deyu4133, dumebi042, ekomukanga, emmet, golu25012000, hacko, heavyw8t, hiram, humaira45, hunraj, iamephraim, id57, iepathos, itsjust0xsp, jayjoshix, jesjupyer, johnnyyy, jovemjeune, khaye26, klaus, lanrebayode77, lazymio, lyubomir-slavchev1, michae2xl, mrmtazk, n0fr33w1f14u, nirohgo, opickabu, piki_eth, pkqs90, qna123321, rj_ethh26, serial-coder, shkedo, skybluescar, solomonerous, spokodev, taticuvostru, thun77, tjonair, vanoxp, vivekd, was3d, xchk, xxiv, yahia_sherif, yaohao159258, ydam113, yonko, z-AI-d, zubyoz, zuhaibmohd, zxriptor

Summary

The per-swap reference reset in PriceVelocityGuardExtension.beforeSwap will cause an amplified oracle-shock drain for LPs of pools relying on this guard, as a swapper will split an intra-block price move into N same-block swaps that each pass a fresh full maxChange budget (blockDiff==0), so cumulative per-block movement reaches ~N*maxChange with no revert.

Root Cause

Referenced code: https://github.com/sherlock-audit/2026-07-metric/blob/main/metric-periphery/contracts/extensions/PriceVelocityGuardExtension.sol#L57-L75

In metric-periphery/contracts/extensions/PriceVelocityGuardExtension.sol:57-58 the reference (lastMidPriceX64/lastUpdateBlock) is overwritten on every beforeSwap call BEFORE the velocity check at :60-75, so the check measures the delta against the previous swap's mid, not a block-anchored mid. For same-block swaps blockDiff = block.number - prevBlock = 0, so allowedSq = maxChange^2 * (1 + 0) and each swap gets a fresh full maxChange budget. This contradicts the NatSpec (:10,:15: "Caps how fast the provided price can move between blocks" / "maxChangePerBlockE18 * sqrt(1 + blockDifference)"). Under the per-swap reset the sqrt(1+blockDiff) term is inoperative dead logic, confirming per-block accumulation was the intended semantics and the per-swap reset is the defect.

Internal Pre-conditions

  1. Pool admin enables PriceVelocityGuardExtension and calls setMaxChangePerBlock(pool, maxChange) with maxChange != 0 (the guard is the pool's velocity defense).
  2. The pool uses a pull-based in-scope price provider (Pyth/Lazer via PythOracle/LazerConsumer) whose anchored mid can be updated within a block.

External Pre-conditions

  1. The referenced asset price moves within one block by more than maxChangePerBlock — i.e. multiple valid signed price updates exist in the block's replayable window (ordinary fast-market conditions). No stale, incorrect, or fabricated price is required.

Attack Path

  1. In a single transaction/block, the attacker submits a valid signed price update moving the anchored mid by <= maxChange, then calls MetricOmmPool.swap — the pool fetches the fresh quote and calls the guard's beforeSwap, which passes and resets the reference to the new mid.
  2. The attacker repeats update -> swap N times in the same block. Each step's delta vs the previous swap's mid is <= maxChange, so blockDiff == 0 and every swap passes (no PriceVelocityExceeded).
  3. The executed price walks ~N*maxChange within the block; the attacker trades LP inventory at each manipulated intermediate level, realizing in one block the drain the guard was configured to cap per block.

Impact

LPs of a pool relying on this guard suffer an amplified oracle-shock drain. A working guard caps intra-block effective price change to maxChange (e.g. 1%), bounding per-block drain to drain(maxChange); broken, one block realizes drain(N*maxChange) up to the half-bin-width ceiling — compressing a multi-block price trajectory into one atomic block. On a representative ~$1M-per-side pool with maxChange = 1% and N >= 5 (~5% intra-block vs the 1% intended), marginal extraction is on the order of hundreds of dollars per event, replayable each block with real movement — above the Medium bar (>0.01% and >$10). Driven by a non-admin swapper (the guard's "assume admin is not adversary" caveat does not apply) and needs no incorrect/stale price. This amplifies the accepted oracle-shock drain by defeating the in-scope per-block cap that the contest known-issues doc itself names as the intended mitigation ("update bounds — limit effective change between trades"); worst case is a pool also running a near-zero base fee (minMargin=0), removing the fee friction that otherwise blunts the drain.

PoC

Full runnable test in the contest repo: metric-periphery/test/PoC_VelocityPerBlock.t.sol. Run: forge test --match-path test/PoC_VelocityPerBlock.t.sol -vv (2/2 pass). It calls the real PriceVelocityGuardExtension exactly as MetricOmmPool.swap does (msg.sender = pool; geometric mid = sqrt(bid*ask), so bid==ask==P pins the mid to P). With maxChangePerBlock = 1e16 (1%):

  • test_sameBlockSwaps_accumulateBeyondPerBlockCap: 5 sequential +1% beforeSwap calls in ONE block all pass; mid goes 1e20 -> 1.01^5*1e20 = 105101005010000000000; cumulative change = 51010050100000000 (~5.101%) >> the 1e16 (1%) per-block cap; block.number never advanced.
  • test_singleStep_sameTotalMove_reverts: the identical ~5.101% move in a SINGLE swap reverts PriceVelocityExceeded(actualSq=2602025211204510010000000000000000, allowedSq=100000000000000000000000000000000) — isolating that the guard bounds only per-step distance, not cumulative-per-block.

Mitigation

Only advance the reference when the block changes, so same-block swaps compare against the block-open mid:

Solidity
if (block.number > prevBlock) {
  s.lastMidPriceX64 = midPrice;
  s.lastUpdateBlock = uint64(block.number);
}

Within a block blockDiff==0 and every same-block swap is measured against the first mid seen that block, bounding cumulative per-block movement to maxChange; across blocks the sqrt(1+blockDiff) scaling still applies. Alternatively accumulate a per-block movement budget.

Discussion

Taridoku

Invalid. The mechanism is real: each swap overwrites the stored reference price and block before the velocity check runs, so same-block swaps are measured per call rather than against the block-opening price. However, the only demonstrated harm is amplifying the oracle-shock two-leg drain that the known issues document excludes, together with its mitigation levers such as oracle and update bounds. No independent token loss outside that excluded class is proven, and the residual mismatch between the guard's documentation and behavior is below Medium.

Duplicates: #22, #38, #73, #103, #117, #139, #184, #207, #214, #261, #290, #298, #309, #347, #368, #430, #462, #489, #504, #512, #551, #566, #605, #614, #618, #623, #647, #678, #691, #730, #743, #783, #808, #858, #897, #917, #956, #1014, #1100, #1102, #1225, #1232, #1250, #1264, #1268, #1285, #1298, #1440, #1496, #1664, #1748, #1785, #1788, #1789, #1792, #1839, #1875, #1880, #1913, #1924, #1942, #2019, #2024, #2051, #2056, #2057, #2067, #2145, #2177, #2187, #2208, #2239, #2253, #2321, #2322, #2340, #2341, #2363, #2390, #2421, #2425, #2495, #2506, #2522, #2539, #2550, #2560, #2576, #2612, #2624, #2715, #2716, #2717, #2727, #2748, #2760, #2765, #2816

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

Impact

Liquidity providers could suffer an amplified oracle-shock drain, with one block realising roughly N times the intended per-block price movement; the judge ruled this harm falls within the excluded oracle-shock class and is below Medium.

What the attacker needed

Pool admin enables the guard with non-zero maxChange; pool uses a pull-based price provider; multiple valid signed price updates in one block; attacker can submit swaps

The fix

The guard should only advance its stored reference when the block number changes, so same-block swaps are compared against the block-opening mid; the team acknowledged the issue but will not fix it at this time.

How it was found

  1. Submit a valid signed price update moving the anchored mid by no more than maxChange.
  2. Call the pool swap; the guard passes and resets its reference to the new mid.
  3. Repeat the update and swap N times in the same block, each step within maxChange.
  4. The executed price walks about N times maxChange within the block, letting the attacker trade LP inventory at each intermediate level.

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 uses a guard that is meant to stop the price moving too far in one block. The guard saves the latest price before it checks how far the price has moved, so each swap in the same block is compared only with the swap just before it. An attacker can make several small swaps in one block, each within the limit, and together move the price much further than intended.

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

View all

23 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.