Variable Overwrite in checkPoolAndGetCenterPrice() Creates Dead-Code Deviation Check, Leaving All V3 Protocol-Owned Liquidity Operations Unprotected
A variable overwrite in the price-check function causes the deviation check to compare the TWAP against itself, always yielding zero deviation, so the guard never triggers. Additionally, two early-return paths skip the check entirely for stale or new pools, leaving all protocol-owned liquidity operations unprotected against flash-loan price manipulation.
fx Follow with 0x_oi, 0xastronatey and 48 others
Originally disclosed on Code4rena
Submitted by fx, also found by 0x_oi, 0xastronatey, 0xDemon, 0xFBI, 0xSeer, abdelhaq16, AcsonBarbosa, AnonOpcode, Aristos, Auditor3, Avalance, DanXIII, Egbe, emerald7017, ESG, Funen, Gakarot, gesha17, golem0, grearlake, humaira45, I1iveF0rTh1Sh1t, inh3l, Inspecktor, jayx, jkk812812, jo13, konstantinos193, KuwaTakushi, martila_iO, mrdafidi, mrMorningstar, NexusAudits, Nyx, oct0pwn, odeili, osok, peazzycole, PlayboiEvokid, rox_k, rzizah, s3ma4, sahuang, santipu_, saraswati, Silvermist, udaykiranpedda, Uhudsavasindankacanokcu2, uwezkhan06, Valves, Varun_05, and Yu4n
autonolas-tokenomics/../contracts/pol/LiquidityManagerCore.sol#L1091-L1137autonolas-tokenomics/../contracts/pol/LiquidityManagerCore.sol#L1104-L1106autonolas-tokenomics/../contracts/pol/LiquidityManagerCore.sol#L1113-L1116/autonolas-tokenomics/../contracts/pol/LiquidityManagerCore.sol#L1119/autonolas-tokenomics/../contracts/pol/LiquidityManagerCore.sol#L1123
LiquidityManagerCore.checkPoolAndGetCenterPrice() is the sole TWAP oracle guard for all V3 protocol-owned liquidity operations. It protects five LiquidityManager functions that manage protocol-owned concentrated liquidity positions, plus two BuyBackBurner call sites:
LiquidityManager operations (protocol-owned liquidity):
convertToV3()(line 689) — migrating V2 liquidity to V3changeRanges()(line 761) — adjusting concentrated liquidity tick rangescollectFees()(line 822) — collecting accrued trading feesdecreaseLiquidity()(line 893) — removing liquidity from positionsincreaseLiquidity()(line 974) — adding liquidity to positions
BuyBackBurner call sites:
BuyBackBurner._buyOLAS()(line 231) — V3 swap pathBuyBackBurner.checkPoolPrices()(line 367) — legacy compatibility
The function is supposed to compare the pool’s current spot price against a TWAP and revert if the deviation exceeds MAX_ALLOWED_DEVIATION (10%). However, a variable overwrite at line 1119 causes the deviation check to compare the TWAP against itself, producing a deviation of zero on every call. The MAX_ALLOWED_DEVIATION check is dead code — it can never trigger.
Additionally, two early-return paths bypass the deviation check entirely for stale or new pools, returning the raw spot price without any validation. Together, these bugs cover every possible execution path:
Root Cause A: Early-Return Bypasses (Lines 1104, 1114)
Two early-return paths skip TWAP validation entirely and return the raw spot price:
// PATH 1: Stale observations (line 1104-1106)
(uint32 oldestTimestamp,,,) = IUniswapV3(pool).observations(observationIndex);
if (oldestTimestamp + SECONDS_AGO < block.timestamp) {
return centerSqrtPriceX96; // Returns SPOT price, NO TWAP check
}
// PATH 2: TWAP call failure (line 1113-1115)
(bool success, bytes memory returnData) = address(this).staticcall(payload);
if (!success) {
return centerSqrtPriceX96; // Returns SPOT price, NO TWAP check
}
Path 1 triggers when the pool’s most recent observation is more than SECONDS_AGO (1800s = 30 min) old. This fires for any pool that hasn’t had a swap in 30+ minutes.
Path 2 triggers when getTwapFromOracle() fails, which happens for newly created pools (e.g., immediately after convertToV3()) that don’t have enough observation history for a 30-minute TWAP.
Both return the current spot price with no manipulation check.
Root Cause B: Return-Variable Overwrite at Line 1119 Makes Deviation Check Dead Code (Primary Bug)
When the function passes both early-return checks (active pool with sufficient history), the TWAP deviation check executes — but a variable overwrite causes it to compare the TWAP price against itself, producing zero deviation on every call. The mechanism is a reuse of the function’s return variable centerSqrtPriceX96 as the decode target for the TWAP result:
function checkPoolAndGetCenterPrice(address pool) public view returns (uint160 centerSqrtPriceX96) {
// Line 1094: centerSqrtPriceX96 = SPOT price from slot0
(centerSqrtPriceX96, observationIndex) = _getPriceAndObservationIndexFromSlot0(pool);
// ... early returns (Root Cause A) ...
// Line 1119: centerSqrtPriceX96 is OVERWRITTEN with TWAP-derived sqrt price
(twapPrice, centerSqrtPriceX96) = abi.decode(returnData, (uint256, uint160));
// ^^^^^^^^^^^^^^^^^ original spot price is LOST
// Line 1123: "instant price" is computed from the OVERWRITTEN variable
uint256 instantPrice = mulDiv(uint256(centerSqrtPriceX96), uint256(centerSqrtPriceX96), (1 << 64));
// instantPrice == twapPrice (both derive from the same centerSqrtPriceX96)
// Lines 1128-1130: deviation = |twapPrice - twapPrice| / twapPrice = 0 ALWAYS
deviation = (instantPrice > twapPrice)
? mulDiv((instantPrice - twapPrice), 1e18, twapPrice)
: mulDiv((twapPrice - instantPrice), 1e18, twapPrice);
// Line 1134: This NEVER triggers because deviation is always 0
if (deviation > MAX_ALLOWED_DEVIATION) {
revert Overflow(deviation, MAX_ALLOWED_DEVIATION);
}
}
The precise mechanism: centerSqrtPriceX96 is the function’s named return variable, initialized to the spot price from slot0() at line 1094. At line 1119, abi.decode(returnData, (uint256, uint160)) overwrites this variable with the TWAP-derived sqrt price from getTwapFromOracle(). The getTwapFromOracle() function (line 1067-1086) returns (price, centerSqrtPriceX96) where price = centerSqrtPriceX96^2 / 2^64 — the two return values are mathematically coupled. When line 1123 then computes instantPrice = centerSqrtPriceX96^2 / 2^64, it reproduces the exact same computation that produced twapPrice, because centerSqrtPriceX96 now holds the TWAP sqrt price instead of the spot sqrt price. The deviation is mathematically guaranteed to be zero:
instantPrice = overwritten_centerSqrtPriceX96^2 / 2^64
= twap_sqrt^2 / 2^64
= twapPrice (by definition from getTwapFromOracle)
deviation = |twapPrice - twapPrice| / twapPrice = 0 (ALWAYS)
Combined Effect
Pool State | Code Path | Result |
Stale observations (>30 min since last swap) | Root Cause A, Path 1 (line 1104) | Returns spot price, no TWAP check |
New pool (insufficient observation history) | Root Cause A, Path 2 (line 1114) | Returns spot price, no TWAP check |
Active pool with sufficient history | Root Cause B (line 1119) | TWAP check runs but deviation = 0 always |
There is no condition under which this function detects price manipulation.
Risk
Likelihood: Medium
Root Cause A requires a pool in a specific state (stale or new). This is realistic — OLAS is not a high-frequency trading token, and 30+ minutes without a swap on a specific pool is common, especially on L2 chains. New pools are immediately vulnerable after convertToV3().
Root Cause B fires on every call where the TWAP oracle succeeds — the “normal” code path for active pools with sufficient history. This is the default condition for established pools.
Together, every possible pool state is covered. An attacker can monitor pool activity and act when conditions align (Root Cause A), or attack any active pool at any time (Root Cause B).
Impact: Medium
The MAX_ALLOWED_DEVIATION check is dead code — it cannot trigger under any condition. This leaves all five LiquidityManager operations exposed to flash-loan price manipulation:
changeRanges()(line 761): UsescenterSqrtPriceX96to calculate new tick ranges. An attacker can manipulate the pool price, causing the protocol to rebalance its concentrated liquidity position to a range centered on the manipulated price. When the attacker restores the price, the protocol’s position is out of range and earns no fees.convertToV3()(line 689): UsescenterSqrtPriceX96to calculate tick ranges for the new V3 position. Manipulation causes the protocol to create its initial position at the wrong price range, permanently locking liquidity in an unfavorable range.decreaseLiquidity()(line 893): The price check is supposed to prevent removal of liquidity during manipulation (which affects the token ratio received). Without it, an attacker can manipulate the price to extract a more favorable token ratio from the protocol’s position.increaseLiquidity()(line 974): The price check is supposed to prevent adding liquidity at a manipulated price (which affects the token ratio deposited). Without it, the protocol deposits at an unfavorable ratio.collectFees()(line 822): The price check prevents fee collection during manipulation (which could affect swap calculations in the same transaction).
These are protocol-owned liquidity management operations — they control the protocol’s own concentrated liquidity positions on Uniswap V3. The oracle guard is their sole defense against flash-loan manipulation. The impact is Medium because exploitation requires a flash-loan manipulation of a V3 pool in the same block as a protocol operation, and the loss magnitude depends on the pool’s liquidity depth and the size of the affected operation.
Proof of Concept
View detailed Proof of Concept
Recommended Mitigation
Two fixes are needed — one for each root cause:
Root Cause A: Revert when TWAP is unavailable instead of silently returning unprotected spot price:
// Line 1104-1106: REVERT instead of early return
if (oldestTimestamp + SECONDS_AGO < block.timestamp) {
revert InsufficientObservationHistory(pool, oldestTimestamp, SECONDS_AGO);
}
// Line 1113-1115: REVERT instead of early return
if (!success) {
revert TwapCalculationFailed(pool);
}
Root Cause B: Preserve the original spot price before the overwrite:
// After line 1094, before the TWAP fetch:
uint160 spotSqrtPriceX96 = centerSqrtPriceX96; // Preserve spot price
// Line 1119 still overwrites centerSqrtPriceX96 (needed for return value):
(twapPrice, centerSqrtPriceX96) = abi.decode(returnData, (uint256, uint160));
// Line 1123: Use the ORIGINAL spot price, not the overwritten TWAP value:
uint256 instantPrice = mulDiv(uint256(spotSqrtPriceX96), uint256(spotSqrtPriceX96), (1 << 64));
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 function reuses its named return variable to store the TWAP result, overwriting the original spot price before computing the deviation, and two early-return paths bypass the check entirely.
Impact
All five LiquidityManager operations and two BuyBackBurner call sites are exposed to flash-loan price manipulation, potentially causing the protocol to rebalance or add/remove liquidity at unfavourable prices, though exploitation requires a same-block flash loan and the loss depends on pool depth.
What the attacker needed
Flash loan available; pool with sufficient liquidity; protocol operation in same block
The fix
The function should revert when TWAP is unavailable instead of returning spot price, and should preserve the original spot price in a separate variable before overwriting the return variable.
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.
This smart contract is supposed to protect the protocol's own trading positions by checking that the current pool price is not too far from a time-weighted average price (TWAP). A coding mistake makes the check compare the average price with itself, so it always sees zero difference and never stops anything. Two other shortcuts also skip the check for certain pool states, so the protection is effectively missing in every case.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.