Skip to content
DoS Audit finding Intermediate

Can't remove compounding maker asset if any visit node in route has only liquidity for it

A wrong use of a fixed-point division helper in the liquidity walker makes removing a compounding maker asset revert when any visited node holds only that asset's liquidity. The asset owner cannot withdraw until every visited node has more liquidity than the asset itself.

0xnija Follow with KlosMitSoss, SOPROBRO and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-ammplify-judging/issues/260

Found by

0xnija, KlosMitSoss, SOPROBRO, holtzzx, neeloy, panprog, v_2110

Summary

When remove a maker asset, it walking through route and remove liquidity for that maker asset in each relevant node.

But because of wrong usage of FullMath.mulDivX256 in LiqWalker.modify function, it can't remove the maker asset if any visit node(means that the node reaching LiqWalker.modify function) only has liquidity for that asset.

So the owner of that asset can't remove it until all of visit nodes have more liquidty than it's own.

This restriction may temporarily lock user funds for an indeterminate period when they want to remove the asset, reducing flexibility and introducing potential usability and liquidity risks.

Root Cause

In LiqWalker.modify function, it calculates shareRatioX256 using FullMath.mulDivX256 function for compounding maker's nodes when currentLiq > targetLiq.

Solidity
uint128 sliq = aNode.sliq; // Our current liquidity balance.
bool dirty = true;
uint128 targetSliq = targetLiq; // Only changed in the MAKER case
if (data.liq.liqType == LiqType.MAKER) {
    uint128 compoundingLiq = 0;
    uint128 currentLiq = 0;
    targetSliq = targetLiq; // Shares start equal to liq.
    if (node.liq.shares != 0) {
        ...
        compoundingLiq = node.liq.mLiq - node.liq.ncLiq + equivLiq;
        currentLiq = uint128(FullMath.mulDiv(compoundingLiq, sliq, node.liq.shares));
        // The shares we'll have afterwards.
        targetSliq = uint128(FullMath.mulDiv(node.liq.shares, targetLiq, compoundingLiq));
    }
    if (currentLiq < targetLiq) {
        ...
    } else if (currentLiq > targetLiq) {
        // When subtracting liquidity, since we've already considered the equiv liq in adding,
        // we can just remove the share-proportion of liq and fees (not equiv).
        compoundingLiq = node.liq.mLiq - node.liq.ncLiq;
        uint128 sliqDiff = sliq - targetSliq;
        uint256 shareRatioX256 = FullMath.mulDivX256(sliqDiff, node.liq.shares, false);
        uint128 liq = uint128(FullMath.mulX256(compoundingLiq, shareRatioX256, false));
        node.liq.mLiq -= liq;
        node.liq.shares -= sliqDiff;
        node.liq.subtreeMLiq -= iter.width * liq;
        uint256 xClaim = FullMath.mulX256(node.fees.xCFees, shareRatioX256, false);
        node.fees.xCFees -= uint128(xClaim);
        data.xBalance -= int256(xClaim);
        uint256 yClaim = FullMath.mulX256(node.fees.yCFees, shareRatioX256, false);
        node.fees.yCFees -= uint128(yClaim);
        data.yBalance -= int256(yClaim);
        // Now we claim the balances from the liquidity itself.
        (uint256 xOwed, uint256 yOwed) = data.computeBalances(iter.key, liq, false);
        data.xBalance -= int256(xOwed);
        data.yBalance -= int256(yOwed);
    } else {
        dirty = false;
    }
}

When owner of the compounding maker asset try to remove it, it definitely matchs in the above conditions(data.liq.liqType == LiqType.MAKER and currentLiq > targetLiq as targetLiq = 0).

As targetLiq=0, targetSliq is being calculated as 0.

So in this case, sliqDiff = sliq - targetSliq = sliq - 0 = sliq = aNode.sliq.

On the other hand, FullMath.mulDivX256 function requires denominator > num and if this condition isn't meet, it reverts.

Solidity
require(denominator > num, "0");

If the processing node only contains the liquidity for this asset, aNode.sliq = node.liq.shares and because of that, it will revert when try to call FullMath.mulDivX256 function for shareRatioX256 calcuation.

Internal Pre-conditions

Any visit node of the route(means that the node reaching out to LiqWalker.modify function) only contains liquidity for the compounding maker asset being removed.

External Pre-conditions

None

Attack Path

Owner of a compounding maker asset that meets the internal pre-condition try to remove the asset.

Impact

Users may be unable to withdraw their compounding maker assets on demand if the asset is in certain liquidity conditions.

Specifically, withdrawals can only succeed once all relevant nodes contain more liquidity than the removing asset's own liquidity within them.

This restriction may temporarily lock user funds for an indeterminate period when they want to remove the asset, reducing flexibility and introducing potential usability and liquidity risks.

PoC

Add below test function to Ammplify\test\facets\Maker.t.sol and run forge test --mt testRemoveMakerForCompoundingNotWorkingProperly -vvvv in terminal.

Solidity
function testRemoveMakerForCompoundingNotWorkingProperly() public {
    // First create a maker position
    bytes memory rftData = "";
    uint256 assetId = makerFacet.newMaker(
        recipient,
        poolAddr,
        lowTick,
        highTick,
        liquidity,
        true, // Compounding maker
        minSqrtPriceX96,
        maxSqrtPriceX96,
        rftData
    );

    // Mock the asset owner
    vm.prank(recipient);

    // Remove the maker position
    vm.expectRevert();
    makerFacet.removeMaker(
        recipient,
        assetId,
        uint128(minSqrtPriceX96),
        uint128(maxSqrtPriceX96),
        rftData
    );
}

Mitigation

Don't call FullMath.mulDivX256 function when sliqDiff == node.liq.shares.

Remove below line of the function

Solidity
uint256 shareRatioX256 = FullMath.mulDivX256(sliqDiff, node.liq.shares, false);

And add below code snippet

Solidity
uint256 shareRatioX256;
if (sliqDiff == node.liq.shares) {
    shareRatioX256 = type(uint256).max;
} else {
    shareRatioX256 = FullMath.mulDivX256(sliqDiff, node.liq.shares, false);
}

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Ammplify/pull/39

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

Root cause

Likely the share-ratio calculation calls a helper that requires the denominator to be strictly greater than the numerator, but when the node's shares equal the amount being removed the two are equal and the helper reverts.

Impact

Users may be unable to withdraw their compounding maker assets on demand, temporarily locking funds until all relevant nodes hold more liquidity than the asset being removed.

What the attacker needed

A compounding maker position; a visited node holds only that asset's liquidity

The fix

The protocol team fixed this issue by handling the case where the share difference equals the node's shares without calling the reverting helper.

How it was found

  1. Create a compounding maker position.
  2. Call removeMaker for that position.
  3. Observe the transaction reverts.

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 maker asset is a deposit that earns fees in a liquidity pool. When the owner removes it, the code walks through pool nodes and takes back the deposit's share. A maths helper used for that share calculation refuses to run when the two numbers are equal, so the withdrawal fails in that specific case.

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.

More by 0xnija

View all

4 more disclosed reports, best first.

More from Ammplify

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.