DoS in Liquidity Migration due to Unit Mismatch in UniswapPriceOracle
The UniswapPriceOracle.validatePrice() function compares a price deviation scaled to 1e16 against a slippage value given in raw percentage units, so almost any deviation fails the check. This causes all calls to LiquidityManagerETH.convertToV3() to revert, blocking V2-to-V3 liquidity migration.
ElmInNyc99 Follow with 0xcode, 0xdonchev and 6 others
Originally disclosed on Code4rena
Submitted by ElmInNyc99, also found by 0xcode, 0xdonchev, harry, jkk812812, NeuroSpire, NexusAudits, osok, and Viveksh0062
autonolas-tokenomics/../contracts/oracles/UniswapPriceOracle.sol #L86-L90
The UniswapPriceOracle.validatePrice() function suffers from a logic error due to a unit mismatch. It calculates price derivation using 1e16 precision but compares it against a slippage parameter provided in raw percentage units. This causes the validation to fail for almost any price deviation, effectively causing a Denial of Service (DoS) for the V2-to-V3 liquidity migration in LiquidityManagerETH.
Root Cause
The validatePrice() function calculates derivation scaled to 1e16 (where 1e16 = 100%), but the input slippage is provided as a raw integer (e.g., 50 represents 50%).
uint256 derivation = (tradePrice > timeWeightedAverage)
? ((tradePrice - timeWeightedAverage) * 1e16) / timeWeightedAverage
: ((timeWeightedAverage - tradePrice) * 1e16) / timeWeightedAverage;
return derivation <= slippage;
-
- Formula:
derivation = (diff * 1e16) / timeWeightedAverage - Scenario: A 5% price deviation results in
derivation = 5e14. - Check:
5e14 <= 50evaluates toFALSE. - Consequently, any deviation greater than
0.00000005%triggers a revert.
- Formula:
-
Inconsistent Implementation: Unlike
BalancerPriceOracle, which correctly normalizes these values,UniswapPriceOraclelacks the necessary scaling logic. -
All calls to
LiquidityManagerETH.convertToV3()(which internally calls_checkTokensAndRemoveLiquidityV2) will revert withSlippageLimitBreached().// Apply slippage protection via V2 oracle: transform BPS into % as required by the function if (!IOracle(oracleV2).validatePrice(maxSlippage / 100)) { revert SlippageLimitBreached(); }
Impact
Users are unable to migrate liquidity from Uniswap V2 to V3, rendering the feature unusable.
Recommendation
Scale the slippage parameter to match the 1e16 precision used for derivation.
Recommended Fix:
function validatePrice(uint256 slippage) external view returns (bool) {
require(slippage <= maxSlippage, "Slippage overflow");
// ... calculate derivation ...
uint256 derivation = (tradePrice > timeWeightedAverage)
? ((tradePrice - timeWeightedAverage) * 1e16) / timeWeightedAverage
: ((timeWeightedAverage - tradePrice) * 1e16) / timeWeightedAverage;
// FIX: Convert slippage from % to 1e16 format (multiply by 1e14)
return derivation <= (slippage * 1e14);
}
Proof of Concept
View detailed Proof of Concept
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 derivation value is scaled to 1e16 (where 1e16 represents 100%), but the slippage parameter is passed as a raw percentage integer, so the comparison is between mismatched units.
Impact
Users are unable to migrate liquidity from Uniswap V2 to V3, making the feature unusable.
What the attacker needed
None
The fix
The slippage parameter should be scaled to match the 1e16 precision used for derivation, for example by multiplying it by 1e14.
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 smart contract checks whether the current price is close enough to an average price before allowing a liquidity move. It calculates the difference as a tiny scaled number but compares it to a plain percentage number, so the check almost always says 'too far' and stops the move. This means users cannot migrate their liquidity.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.