Skip to content
Business logic Audit finding Intermediate

The router is not compatible with fee on transfers tokens

The router contract does not correctly handle tokens that charge a fee on transfer, so when removing liquidity the recipient receives less than the expected amount and the transaction may revert or cause loss of funds. The router also charges double fees in some functions because tokens are transferred twice.

1337 Follow with MohammedRizwan, Solidity_ATL_Team_2 and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-goat-trading-judging/issues/67

Found by

1337, MohammedRizwan, Solidity_ATL_Team_2, joshuajee, juan, zzykxx

Summary

The router is not compatible with fee on transfers tokens.

Vulnerability Detail

Let's take as example the removeLiquidity function:

Solidity
address pair = GoatV1Factory(FACTORY).getPool(token);

IERC20(pair).safeTransferFrom(msg.sender, pair, liquidity); //-> 1. Transfers liquidity tokens to the pair
(amountWeth, amountToken) = GoatV1Pair(pair).burn(to); //-> 2. Burns the liquidity tokens and sends WETH and TOKEN to the recipient
if (amountWeth < wethMin) { //-> 3. Ensures enough WETH has been transferred
    revert GoatErrors.InsufficientWethAmount();
}
if (amountToken < tokenMin) { //4. Ensures enough TOKEN has been transferred
    revert GoatErrors.InsufficientTokenAmount();
}

It does the following:

  1. Transfers liquidity tokens to the pair.
  2. Burns the liquidity tokens and sends WETH and TOKEN to the recipient to.
  3. Ensures enough WETH has been transferred.
  4. Ensures enough TOKEN has been transferred.

At point 4 the router doesn't account for the fee paid to transfer TOKEN. The recipient didn't actually receive amountToken, but slightly less because a fee has been charged.

Another interesting example is the removeLiquidityETH which first burns the liquidity and transfers the tokens to the router itself, and then from the router the tokens are transferred to the recipient. This will charge double the fees.

This is just two examples to highlight the fact that these kind of tokens are not supported, but the other functions in the router have similar issues that can cause all sorts of trouble including reverts and loss of funds.

Impact

The router is not compatible with fee on transfers tokens.

Code Snippet

Tool used

Manual Review

Recommendation

Add functionality to the router to support fee on transfer tokens, a good example of where this is correctly implememented is the Uniswap Router02.

Discussion

sherlock-admin4

1 comment(s) were left on this issue during the judging contest.

takarez commented:

as per the readMe the contract should support FOT; medium(1)

F01ivor4

I think issue https://github.com/sherlock-audit/2024-03-goat-trading-judging/issues/40 is not same

F01ivor4

The problem is on the router. And https://github.com/sherlock-audit/2024-03-goat-trading-judging/issues/40 is wrong.

F01ivor4

Also, https://github.com/sherlock-audit/2024-03-goat-trading-judging/issues/3 is wrong

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/inedibleX/goat-trading/pull/7

zzykxx

Looks good, the following functions have been added to the GoatRouterV1 contract in order to support fee on transfer tokens:

  • removeLiquidityETHSupportingFeeOnTransferTokens()
  • swapExactTokensForTokensSupportingFeeOnTransferTokens()
  • swapExactWethForTokensSupportingFeeOnTransferTokens()
  • swapETHForExactTokensSupportingFeeOnTransferTokens()
  • swapExactTokensForWethSupportingFeeOnTransferTokens()

sherlock-admin4

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by 1337. 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

Impact

Users may receive less than expected or transactions may revert, and in some functions double fees are charged, potentially leading to loss of funds.

What the attacker needed

Token charges fee on transfer; user interacts with router

The fix

The router was updated with functions that support fee-on-transfer tokens, as confirmed by the protocol team and the lead senior watson.

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 they are sent from one address to another. The router contract assumes the full amount arrives, so it checks for more than the recipient actually gets. This can make the transaction fail or leave the user with less than expected.

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 1337

View all

1 more disclosed report, best first.

More from Goat Trading

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.