Skip to content
Business logic Audit finding Intermediate

AlgebraPool: swapSupportingFeeOnInputTokens loses exact output functionality

The swap function for fee-on-transfer tokens calculates the required amount as a positive balance difference, so it can never signal an exact-output swap. As a result, users cannot perform exact-output swaps with these tokens.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52

AlgebraPool.sol#L626-L673

Exact output functionality does not exist for fee on transfer tokens.

Proof of Concept

require((amountRequired = int256(balanceToken0().sub(balance0Before))) > 0, 'IIA');

Exact output swaps are signaled by setting amountRequired to a negative number. When calling AlgebraPool#swapSupportingFeeOnInputTokens amount required is set to the difference in token balances before and after which will always be positive. Since amountRequired can’t be negative, the exact output functionality is impossible to use for those tokens.

Recommended Mitigation Steps

Fee on transfer tokens are messy and there is no standard implementation to query the fee from the token contract. Ultimately support for these tokens should be added through either user inputs (i.e. allowing high slippage) or a specialized router.

vladyan18 (QuickSwap & StellaSwap) acknowledged


The original report as published on Code4rena, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 swap function computes the required amount as a positive balance difference, which cannot represent the negative value needed for exact-output swaps.

What the attacker needed

Fee-on-transfer token; use of swapSupportingFeeOnInputTokens

The fix

Support for fee-on-transfer tokens should be added through user inputs (e.g., allowing high slippage) or a specialised router.

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.

Some tokens take a small fee when transferred, so the amount received is less than the amount sent. This code calculates the swap amount from the balance change, which is always positive, but exact-output swaps need a negative value to indicate the desired output. Therefore, exact-output swaps are impossible for these tokens.

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 0x52

View all

211 more disclosed reports, best first.

More from QuickSwap and StellaSwap contest

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.