Skip to content
Business logic Audit finding Intermediate

`Maker.collectFees` re-targets liquidity to original amount even if the maker position was adjusted, causing unexpected position change when the user expected to collect fees only

The collectFees function re-targets liquidity to the original amount stored in the asset, which is not updated when a user adjusts their position. An attacker could cause a user's position to be unexpectedly increased or decreased when collecting fees, leading to fund loss from impermanent loss or reduced fees.

Peter1992 Follow with SOPROBRO, Theseersec and 4 others

Originally disclosed on Sherlock

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

Found by

Peter1992, SOPROBRO, Theseersec, anonymousjoe, panprog, samm-code, vtim

Summary

When Maker.collectFees is called, it simply re-targets the liquidity to the asset's original amount:

Solidity
        // We collect simply by targeting the original liq balance.
        Data memory data = DataImpl.make(pInfo, asset, minSqrtPriceX96, maxSqrtPriceX96, asset.liq);

The issue is that asset.liq is set in newMaker, but is not modified in adjustMaker. The data is set to new target liquidity, but the asset node itself is never changed:

Solidity
        Data memory data = DataImpl.make(pInfo, asset, minSqrtPriceX96, maxSqrtPriceX96, targetLiq);

This means that if the user has ever adjusted his position and later tries to collect fees, his position will be unexpectedly modified along with collecting fees. Unsuspecting users can thus lose funds. For example, if his position has unexpectedly increases due to fee collection, he might lose funds from impermanent loss before realizing the issue and reducing again.

Additionally, the Maker.collectFees function doesn't expect that the user might have to pay, so the order of settlement is:

Solidity
        PoolWalker.settle(pInfo, asset.lowTick, asset.highTick, data);
...
        RFTLib.settle(recipient, tokens, balances, rftData);

If the user position is increased in this function, PoolWalker.settle will first mint a new uniswap position for the diamond, and only then the user will be charged with the amounts of tokens to mint it. Transaction might revert if diamond doesn't have enough funds (from takers collaterals).

Root Cause

Maker.adjustMaker doesn't change asset's liquidity, which is used to re-target liquidity in Maker.collectFees: https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/facets/Maker.sol#L55-L68 https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/facets/Maker.sol#L142-L143

Internal Pre-conditions

  • User adjusted his position before collecting fees.
  • Secondary condition: user reduced position before collecting fees and diamond doesn't have enough funds to mint the liquidity equal to this change (from taker collateral and previously collected fees not yet claimed or compounded).

External Pre-conditions

None.

Attack Path

Always happens by itself when internal pre-condition is met

Impact

  • User position is unexpectedly increased or decreased when collectFees is called
  • User loses funds from either increased impermanent loss or decreased fees earned (from the time position changes until user finds out it has changed and adjusts it again)
  • Unexpected behaviour of core functionality (collectFees)

Secondary impact:

  • If user has decreased position before collecting fees, user's maker liquidity will increase in collectFees, and if diamond doesn't have enough tokens balance to mint this additional liquidity, the transaction will revert (core functionality not working in some cases). It can happen either for large user liquidity change, or if there is not too much taker collateral.

Notes:

  • Since the user doesn't expect his position to change when doing collectFees, it can take some time before this position change is discovered. This allows for the funds loss from, e.g., increased impermanent loss, to become significant. For example, if user reduced liquidity from 1000e18 to 10e18 and then collected fees, his position will be back to 1000e18 and additional impermanent loss after 1 hour can be 1e18, which is 10% funds loss from the position amount of 10e18.

Proof of concept

Add this test to Maker.t.sol:

Solidity
    // adjust maker position, then collect fees
    // instead of keeping liquidity, it will modify it back to original size
   function testAdjustMakerCollect() public {
        bytes memory rftData = "";

        // add funds to diamond so that it has some extra to mint before collecting from the user
        takerFacet.collateralize(recipient, address(token1), 1e20, "");

        // current price above the range we'll work at
        swapTo(0, TickMath.getSqrtRatioAtTick(1000));

        // Create maker
        uint256 makerAssetId = makerFacet.newMaker(
            recipient,
            poolAddr,
            720,
            960,
            300e18,
            false, // non-compounding
            minSqrtPriceX96,
            maxSqrtPriceX96,
            rftData
        );

        // reduce maker
        makerFacet.adjustMaker(recipient, makerAssetId, 100e18, minSqrtPriceX96, maxSqrtPriceX96, rftData);

        // collect maker
        // instead of keeping liquidity the same, it is increased
        makerFacet.collectFees(recipient, makerAssetId, minSqrtPriceX96, maxSqrtPriceX96, rftData);

        (,,,,, uint128 liq) = viewFacet.getAssetInfo(makerAssetId);
        console2.log("Liquidity after collecting: ", liq);
    }

The test creates new maker with 300e18 liquidity, reduces it to 100e18, the collects fees. After fees collection, liquidity is 300e18 instead of 100e18.

Console output from running the test:

Solidity
  Liquidity after collecting:  300000000000000000000

Mitigation

Change the asset.liq amount to target liquidity in Maker.adjustMaker.

Discussion

sherlock-admin2

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

The original report as published on Sherlock, by Peter1992. 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 adjustMaker function does not update the asset's stored liquidity value, so collectFees uses the outdated original liquidity as the target.

Impact

User position is unexpectedly increased or decreased when collectFees is called, causing fund loss from increased impermanent loss or decreased fees; additionally, the transaction may revert if the diamond lacks sufficient funds to mint the additional liquidity.

What the attacker needed

User adjusted position before collecting fees; Diamond may lack funds to mint additional liquidity

The fix

The protocol team fixed this issue by changing the asset.liq amount to target liquidity in Maker.adjustMaker.

How it was found

  1. Create a maker position with a certain liquidity.
  2. Adjust the maker position to a different liquidity.
  3. Call collectFees on the maker position.
  4. Observe that the liquidity is reset to the original amount instead of remaining at the adjusted amount.

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.

When you adjust your position in this system, the system forgets to update the original amount it remembers. Later, when you try to collect fees, it resets your position back to that old amount, which can change your position without you expecting it and potentially lose you money.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Ammplify

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.