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.
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:
// X split
data.leftChildUnpaidX = leftPaid;
data.rightChildUnpaidY = unpaidX - leftPaid; // should be rightChildUnpaidX
Fix:
- 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
-
There exists a node on the route whose node.fees.unpaidTakerXFees > 0 (fees to be propagated).
-
A taker asset’s visited node lies in that node’s right subtree with aNode.sliq > 0.
-
The user (or frontend/automation) calls ViewFacet.queryAssetBalances(assetId) to size approvals based on fees0.
-
The user then attempts to close via TakerFacet.removeTaker(...), which internally settles via RFTLib.settle(...).
External Pre-conditions
None.
Attack Path
-
A taker with a right-subtree position accrues X-fees upstream (unpaidTakerXFees > 0).
-
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.
-
User approves token0 equal to the underreported fees0.
-
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
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
- A taker position in a right subtree accrues unpaid X fees upstream.
- The user or automation calls queryAssetBalances for the asset.
- The query underreports the X fees because of the field mix-up.
- The user approves token0 equal to the underreported amount.
- The user calls removeTaker, which settles via RFTLib.settle.
- 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.