Skip to content
Business logic Audit finding Intermediate

Convenience contract fails to function if asset or collateral is an ERC20 token with fees

The Convenience contract sends a flat token amount when calling the Pair contract, but if the token charges a transfer fee, the Pair receives less than expected and reverts. This makes the Convenience contract unusable with fee-on-transfer tokens, and outgoing transfers may deliver less collateral to the borrower.

Ruhum Follow

Originally disclosed on Code4rena

Submitted by Ruhum

There are ERC20 tokens that collect fees with each transfer. If the asset or collateral used in a pair is of that type, the Convenience contract fails to function. It always sends the flat amount specified in the function’s parameter. If the token collects fees, the amount the Pair contract receives is less than it expects to get and reverts the transaction.

Proof of Concept

The function used to trigger the callback function and verify the received value: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/libraries/Callback.sol#L50

Convenience contract’s callback function uses the amount specified in collateralIn in the transfer function: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Convenience/contracts/TimeswapConvenience.sol#L535

If the token collects fees, the value the Pair contract receives will be less than collateralIn. The following require statement will fail: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/libraries/Callback.sol#L52

The same thing applies to all the other callback functions in the library.

This issue doesn’t impact the Pair contract itself. Because of the safety checks for each callback, the contract always receives the amount it expects or the transaction is reverted. Meaning, the user has to adapt and cover the fees themselves. The convenience contract doesn’t do that and thus always fails.

The only issue would be outgoing transfers. For example, if a borrower pays back their debt, the pair contract receives the correct amount. But, the borrower will receive less collateral because of the fees. Since there’s no such check in those cases: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L374

Mathepreneur (Timeswap) acknowledged:

Hi what projects out there are using this fee mechanism in their transfer function? And what do you think is the mitigation for this?

Almost all tokens don’t have this fee implementation. If someone wants to utilize this, they can create their own convenience contract to interact with Timeswap V1 Core

0xean (judge) commented:

Would be worth documenting the behavior for fee on transfer tokens and also expected behavior for rebasing tokens as well.

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

The Convenience contract does not account for transfer fees when sending tokens, so the received amount is less than the expected amount and the Pair contract's check reverts.

Impact

The Convenience contract fails to function with fee-on-transfer tokens, and outgoing transfers may result in the recipient receiving less collateral due to fees.

What the attacker needed

Asset or collateral is a fee-on-transfer ERC20 token

The fix

The project should document the behaviour for fee-on-transfer tokens and users can create their own convenience contract to interact with Timeswap V1 Core.

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 each time they are transferred, so the receiver gets less than the sender sent. The Convenience contract assumes the full amount arrives and checks for that, so the transaction fails. This means the contract cannot be used with such 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 Ruhum

View all

55 more disclosed reports, best first.

More from Timeswap 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.