Shift-Overflow in getEquivalentLiq Inflates LP Shares
The function getEquivalentLiq computes a liquidity value using a left shift before division, which can overflow 256 bits and truncate high bits, inflating the equivalent liquidity. An attacker can exploit this to mint more shares than fair value, diluting other liquidity providers.
Source: https://github.com/sherlock-audit/2025-09-ammplify-judging/issues/442
Found by
K42, maigadoh
Summary
PoolLib.getEquivalentLiq computes the liquidity-equivalent value of token balances using left shifts prior to division. The term (lyX128 << 96) / sqrtPriceX96 can overflow 256 bits before division, silently truncating high bits and shrinking the denominator. This inflates equivLiq, corrupts share/compounding math, and causes unfair value reallocation between LPs.
Root Cause
getEquivalentLiq builds a denominator-like value liqValueX128 via a left shift by 96 bits before dividing by sqrtPriceX96. For wide ranges, lyX128 can be on the order of 2^192 (with liq = X128), so (lyX128 << 96) can exceed 2^256 and wrap, reducing liqValueX128. That inflates equivLiq and misprices compounding liquidity and shares.
Link: https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/Pool.sol#L241-L259
function getEquivalentLiq(
int24 lowTick,
int24 highTick,
uint256 x,
uint256 y,
uint160 sqrtPriceX96,
bool roundUp
) internal pure returns (uint128 equivLiq) {
(uint256 lxX128, uint256 lyX128) = getAmounts(sqrtPriceX96, lowTick, highTick, X128, roundUp);
uint256 liqValueX128 = (FullMath.mulX64(lxX128, sqrtPriceX96, false) >> 32)
+ (lyX128 << 96) / sqrtPriceX96; // vulnerable: left shift can overflow 256-bit before division → truncated denominator
uint256 myValue = FullMath.mulX128(x, uint256(sqrtPriceX96) << 32, false)
+ (y << 96) / sqrtPriceX96; // similar pattern; shift before div risks overflow
// ...
}
Link: https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/walkers/Liq.sol#L248-L266
// For adding liquidity, we need to consider existing fees
// and what amount of equivalent liq they're worth.
uint128 equivLiq = PoolLib.getEquivalentLiq(
iter.lowTick,
iter.highTick,
node.fees.xCFees,
node.fees.yCFees,
data.sqrtPriceX96,
true
);
// reachable: inflated equivLiq corrupts compoundingLiq and subsequent share math
compoundingLiq = node.liq.mLiq - node.liq.ncLiq + equivLiq;
currentLiq = uint128(FullMath.mulDiv(compoundingLiq, sliq, node.liq.shares));
Attack Path
Path Misvaluation via overflow during Maker modify compounding
- Set up a pool and deposit Maker liquidity so a high-level (wide-range) node accumulates compounding fees (routine usage).
- Trigger a Maker modify on that node (e.g., add/adjust position) so
Liq.modifycallsPoolLib.getEquivalentLiq(...)withiter.lowTick/highTickcovering a wide range. - For wide ranges,
lyX128 = getAmount1Delta(low, high, X128, ...)becomes large (~2^192). The expression(lyX128 << 96) / sqrtPriceX96overflows 256 bits before the division and truncates high bits, reducingliqValueX128. - Reduced
liqValueX128inflatesequivLiq, which then inflatescompoundingLiqand miscomputesshares. The caller receives an outsized share of future fees/principal; other LPs are diluted.
Impact
Direct, material value misallocation due to core math error:
- LP share dilution: The attacker mints more compounding shares than fair value, siphoning future fees from other LPs in the affected node.
- Over-withdrawal/under-payment: Subsequent redemptions/claim paths realize the misvaluation as net loss to other users or protocol fee accounting.
Mitigation
- Replace shift-before-division with precise 512-bit math:
FullMath.mulDiv(lyX128, 1 << 96, sqrtPriceX96)instead of(lyX128 << 96) / sqrtPriceX96.- Likewise
FullMath.mulDiv(y, 1 << 96, sqrtPriceX96)instead of(y << 96) / sqrtPriceX96.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Ammplify/pull/41
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 code performs a left shift by 96 bits on a value that can be around 2^192, causing the intermediate result to exceed 256 bits and wrap around before the division, leading to an incorrect smaller denominator and inflated equivalent liquidity.
Impact
The attacker could mint more compounding shares than fair value, diluting other LPs and causing them to lose future fees or principal.
What the attacker needed
A pool with wide-range liquidity; ability to trigger a Maker modify
The fix
The protocol team fixed this issue by replacing the shift-before-division with precise 512-bit math using FullMath.mulDiv.
How it was found
- Set up a pool and deposit Maker liquidity so a wide-range node accumulates compounding fees.
- Trigger a Maker modify on that node so Liq.modify calls PoolLib.getEquivalentLiq with a wide range.
- The left shift overflows, reducing liqValueX128 and inflating equivLiq.
- The inflated equivLiq increases compoundingLiq and miscomputes shares, giving the caller more shares than fair.
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.
In smart contracts, numbers have a fixed size (256 bits). If you shift a number left too many times, it can wrap around and lose its high bits, making it smaller. Here, the code shifts before dividing, so the result can be wrong, letting someone get more shares than they should.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.