Users can avoid paying fees for ETH swaps
The swap function allowed users to avoid paying swap fees on ETH swaps by using a malicious contract as the buy token address, which tricked the system into treating the ETH output as a refund. An attacker could execute ETH swaps without paying the associated fees.
Submitted by pants
Users can call Swap.swapByQuote() to execute an ETH swap (where they receive ETH) without paying swap fee for the gained ETH. They can trick the system by setting zrxBuyTokenAddress to an address of a malicious contract and making it think they have executed an ERC20 swap when they have actually executed an ETH swap. In this case, the system will give them the ETH they got from the swap (boughtETHAmount) without charging any swap fees for it, because the systems consideres this ETH as “refunded ETH” that wasn’t part of the “ERC20” swap.
Impact
Users can execute ETH swap without paying swap fees for the ETH the got from the swap.
Proof of Concept
The steps of the attack are:
- Deploy a malicious contract (denoted by
M), that will be used forzrxBuyTokenAddress. - Call
Swap.swapByQuote()withzrxBuyTokenAddress=MandminimumAmountReceived=0. The rest of the arguments should specify our ETH swap, nothing special here. - Define
Mto return0and1at the first and second times whenfillZrxQuotecallszrxBuyTokenAddress.balanceOf(address(this)), respectively. - As a result,
boughtERC20Amountnow equals1and the function will “return any refunded ETH” to the caller, without charging any swap fees on it. This ETH is actually the output of that ETH swap.
Tool Used
Manual code review.
Recommended Mitigation Steps
Charge swap fees for the “refunded ETH” on ERC20 swaps (when boughtERC20Amount > 0), or require boughtETHAmount == 0.
Shadowfiend (Tally) acknowledged:
Still working through whether this is an issue we’re truly worried about; in particular, if you want to do this, you probably might as well use the 0x API to swap directly.
Nonetheless, it’s overshadowed by #37, which will likely lead to changes that will make this impractical as well.
Downgrading to severity 2 as this would lead to “leaked value” as only the fees are lost by the protocol in this attack vector and customer assets aren’t being stolen.
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 did not charge fees on ETH that was returned as a refund, and it trusted the balance reported by the user-supplied buy token contract.
What the attacker needed
Ability to deploy a malicious contract; access to the swap function
The fix
The swap function should charge fees on refunded ETH when an ERC20 swap has occurred, or require that no ETH is bought in such cases.
How it was found
- Deploy a malicious contract to be used as the buy token address.
- Call the swap function with the malicious contract as the buy token and a minimum amount received of zero.
- Make the malicious contract return 0 and then 1 when its balance is checked during the swap.
- The system then treats the ETH output as a refund and returns it without charging swap fees.
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.
When you swap tokens on a decentralized exchange, you usually pay a small fee. This report shows a way to trick the system into thinking the ETH you received was just a refund, so no fee was charged. The attacker used a fake token contract to make the system believe an ERC20 swap had happened.
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.