Skip to content
DoS Audit finding Intermediate

X/Y mix-up in ViewWalker.down will underreport X fees and block taker closes

A view function that walks a fee tree assigns the right-branch remainder of X fees to a Y field, so X fees for right-subtree positions are underreported. Users who size their token0 approval from that query then have their taker close revert because the contract tries to pull more than approved.

DSbeX Follow with JeRRy0422, Slayer and 9 others

Originally disclosed on Sherlock

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

Found by

DSbeX, JeRRy0422, Slayer, TheSavageTeddy, Ziusz, blockace, coin2own, jayjoshix, maigadoh, rubencrxz, serenity1337, v_2110

Summary

The X/Y assignment bug in ViewWalker.down will cause an underreporting of token0 (X) taker fees for right-subtree positions, as the view walk writes the right-branch X remainder into a Y field, dropping it from propagation.

This makes queryAssetBalances() deviate by well over 0.01% for affected takers, leading users to approve too little token0 and causing removeTaker() settlements to revert.

Root Cause

In ViewWalker.down the X-fee split stores the right-branch remainder into the wrong field:

Solidity
// X split
data.leftChildUnpaidX  = leftPaid;
data.rightChildUnpaidY = unpaidX - leftPaid; // should be rightChildUnpaidX

Fix:

Diff
- data.rightChildUnpaidY = unpaidX - leftPaid;
+ data.rightChildUnpaidX = unpaidX - leftPaid;

This typo nukes the right branch’s inherited X taker-fees; later reads use rightChildUnpaidX, which was never written for this branch.

Internal Pre-conditions

  1. There exists a node on the route whose node.fees.unpaidTakerXFees > 0 (fees to be propagated).

  2. A taker asset’s visited node lies in that node’s right subtree with aNode.sliq > 0.

  3. The user (or frontend/automation) calls ViewFacet.queryAssetBalances(assetId) to size approvals based on fees0.

  4. The user then attempts to close via TakerFacet.removeTaker(...), which internally settles via RFTLib.settle(...).

External Pre-conditions

None.

Attack Path

  1. A taker with a right-subtree position accrues X-fees upstream (unpaidTakerXFees > 0).

  2. User/automation queries queryAssetBalances(assetId). Due to the mix-up, fees0 (X) is underreported (potentially by almost the entire right-branch share), exceeding the 0.01% threshold.

  3. User approves token0 equal to the underreported fees0.

  4. User calls removeTaker(...). During RFTLib.settle, the contract tries to pull the true X owed (greater than approved), causing transferFrom to fail and the transaction to revert—blocking the close until the user increases approval.

Impact

The user cannot close taker positions (DoS) unless they over-approve or trial-and-error approvals. Gas is wasted on reverting txs. Deviation in queryAssetBalances() can be >>0.01% (up to nearly all X fees attributable to the right branch), satisfying the contest’s “Additional audit information”.

PoC

No response

Mitigation

  • Apply the one-line fix shown above.

  • Add symmetry tests asserting that after an X/Y split at a non-leaf:

    • X: leftChildUnpaidX + rightChildUnpaidX == unpaidX

    • Y: leftChildUnpaidY + rightChildUnpaidY == unpaidY

Similar checks for Unclaimed maker fields.

Discussion

sherlock-admin2

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

The original report as published on Sherlock, by DSbeX. 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 a copy-paste typo in the view walker: the right-branch X remainder is stored in rightChildUnpaidY instead of rightChildUnpaidX.

Impact

Users may be unable to close taker positions unless they over-approve or retry with larger approvals, wasting gas on reverting transactions.

What the attacker needed

A taker position in a right subtree; unpaid X taker fees upstream; approval sized from queryAssetBalances

The fix

The protocol team fixed this issue by correcting the field assignment and adding symmetry tests for the fee splits.

How it was found

  1. A taker position in a right subtree accrues unpaid X fees upstream.
  2. The user or automation calls queryAssetBalances for the asset.
  3. The query underreports the X fees because of the field mix-up.
  4. The user approves token0 equal to the underreported amount.
  5. The user calls removeTaker, which settles via RFTLib.settle.
  6. The settlement tries to pull more X than approved, so transferFrom fails and 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 smart contract tracks fees owed to users in a tree structure. A read-only helper function is supposed to add up those fees, but it puts one number into the wrong slot, so the total it reports is too low. If you approve only that low amount and then try to close your position, the contract asks for the real, higher amount and the transaction fails.

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 DSbeX

View all

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