Skip to content
Business logic Audit finding Intermediate

safeTransferFrom in TransferHelper is not safeTransferFrom

The TransferHelper contract's _safeTransferFrom function does not use the SafeERC20 library, so it fails when interacting with non-standard ERC20 tokens like USDT. An attacker could exploit this to cause deposits to revert, preventing users from depositing into pools.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005, also found by 0xRajeev, shw, JMukesh, and cmichel

A non standard ERC20 token would always raise error when calling _safeTransferFrom. If a user creates a USDT/DAI pool and deposit into the pool he would find out there’s never a counterpart deposit. See TransferHelper.sol #L19.

TransferHelper does not uses SafeERC20 library as the function name implies.

A sample POC:

usdt.functions.approve(lending_pair.address, deposit_amount).transact({'from': w3.eth.accounts[0]})
lending_pair.functions.deposit(w3.eth.accounts[0], usdt.address, deposit_amount).transact({'from': w3.eth.accounts[0]})

Error Message:

  Error: Transaction reverted: function returned an unexpected amount of data
      at LendingPair._safeTransferFrom (contracts/TransferHelper.sol:20)
      at LendingPair.deposit (contracts/LendingPair.sol:95)

Recommend using openzeppelin SafeERC20 in transferHelper (and any other contract that uses IERC20).

talegift (Wild Credit) confirmed

ghoul-sol (Judge) commented:

This can effect deposits so it’s a medium risk.

The original report as published on Code4rena, by jonah1005. 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 TransferHelper contract implemented its own transfer logic instead of using a library like OpenZeppelin's SafeERC20 that handles non-standard ERC20 tokens.

Impact

Deposits with non-standard ERC20 tokens like USDT would always fail, preventing users from using those tokens in the pool.

What the attacker needed

The pool supports a non-standard ERC20 token like USDT; User attempts to deposit that token

The fix

The TransferHelper should use OpenZeppelin's SafeERC20 library (and any other contract that uses IERC20) to handle non-standard tokens correctly.

How it was found

  1. Approve the lending pair contract to spend USDT on behalf of the user.
  2. Call the deposit function on the lending pair with USDT as the token and the deposit amount.
  3. Observe that the transaction reverts with an error about unexpected data.

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, like USDT, don't behave exactly like the standard ERC20 token specification. The helper function assumed all tokens behave the same way, so when a user tried to deposit USDT, the transaction failed and the deposit never went through. This means users couldn't use those tokens in the pool.

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 jonah1005

View all

39 more disclosed reports, best first.

More from Wild Credit 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.