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.
Submitted by 0x52
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
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.