Skip to content
Business logic Audit finding Intermediate

`ViewFacet.queryAssetBalances` doesn't unclude uncollected uniswap fees for compounded maker position

The ViewFacet.queryAssetBalances function under-reports earnings for compounded maker positions because it omits uncollected Uniswap fees that are normally added to the maker's fees when liquidity is removed. An attacker could exploit this incorrect value to break dependent logic and potentially lose funds as unrecoverable assets.

panprog Follow

Originally disclosed on Sherlock

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

Found by

panprog

Summary

When ViewFacet.queryAssetBalances calculates the earnings for compounded maker, it ignores the uncollected uniswap fees:

Solidity
        uint256 fee0DiffX128 = newFeeGrowthInside0X128 - node.liq.feeGrowthInside0X128;
        uint256 fee1DiffX128 = newFeeGrowthInside1X128 - node.liq.feeGrowthInside1X128;
        if (data.liq.liqType == LiqType.MAKER) {
            // We just claim our shares.
            // If the sliq and shares are zero, you should fail anyways.
            // @audit-issue compounded maker should also include fee0DiffX128/fee1DiffX128 here
            data.earningsX += FullMath.mulDiv(node.fees.xCFees, aNode.sliq, node.liq.shares);
            data.earningsY += FullMath.mulDiv(node.fees.yCFees, aNode.sliq, node.liq.shares);
        } else if (data.liq.liqType == LiqType.MAKER_NC) {
            data.earningsX += FullMath.mulX128(
                aNode.sliq,
                fee0DiffX128 + node.fees.makerXFeesPerLiqX128 - aNode.fee0CheckX128,
                false
            );
            data.earningsY += FullMath.mulX128(
                aNode.sliq,
                fee1DiffX128 + node.fees.makerYFeesPerLiqX128 - aNode.fee1CheckX128,
                false
            );
        } else {

When the actual compounded maker asset is removed, the uncollected uniswap fees are added to node.fees.xCFees and node.fees.yCFees and compounded as additional liquidity. If liquidity is not increased (fees below compound threshold), then these fees are simply added to xCfees/yCFees. Either way, the value of these uniswap uncollected fees is added to maker earnings, which doesn't happen for ViewFacet.

This results in incorrect earnings reported (less than actual amount) and user can fail to account for these fees, breaking any further logic it has and possibly losing the difference as unrecoverable asset.

Root Cause

Uncollected uniswap fees not included for compounded maker in the View walker: https://github.com/sherlock-audit/2025-09-ammplify/blob/main/Ammplify/src/walkers/View.sol#L335-L336

Internal Pre-conditions

None.

External Pre-conditions

None.

Attack Path

Happens by itself almost always:

  • Any time someone tries to query assets via ViewFacet, the amount for compounded maker earnings is under-reported.

Impact

Amount reported is less than the actual amount received if maker position is closed. User can fail to account for these fees, breaking any further logic it has and possibly losing the difference as unrecoverable asset.

According to README:

Q: Additional audit information. Issues that lead to getting incorrect return values (i.e. deviates from the withdrawal value of the asset by more than 0.01%) from the queryAssetBalance function (even if the appropriate input is used), which will lead to issues when executing other functions, may be considered valid with Medium severity at max.

The amount under-reported due to this issue can often be more than 0.01% (depending on the frequency of fees collection of the specific range, which can easily be very infrequent, especially on less popular ranges).

Mitigation

Solidity
            data.earningsX += FullMath.mulDiv(fee0DiffX128 + node.fees.xCFees, aNode.sliq, node.liq.shares);
            data.earningsY += FullMath.mulDiv(fee1DiffX128 + node.fees.yCFees, aNode.sliq, node.liq.shares);

The original report as published on Sherlock, by panprog. 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 ViewFacet's calculation for compounded maker positions does not add the uncollected Uniswap fee differences (fee0DiffX128 and fee1DiffX128) to the earnings, unlike the actual withdrawal logic.

Impact

The reported earnings are less than the actual amount, which could break dependent logic and cause the user to lose the difference as an unrecoverable asset.

What the attacker needed

None

The fix

The fix should include the uncollected fee differences in the earnings calculation for compounded maker positions, as shown in the mitigation.

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.

This is a smart contract bug where a function that reports how much a user has earned forgets to include some fees that the user is owed. Because the reported number is too low, other parts of the system that rely on it can make wrong decisions, and the user might lose 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 by panprog

View all

66 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.

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.