Skip to content
Smart contracts Audit finding Intermediate

Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom

The contract used transfer/transferFrom without checking return values, so a token that fails silently could cause transfers to appear successful while token accounting is wrong. This could lead to a loss of funds under the right external conditions.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz, also found by 0x1f8b, bobi, byterocket, Dravee, hack3r-0m, sirhashalot, TomFrenchBlockchain, UncleGrandpa925, and WatchPug

It is good to add a require() statement that checks the return value of token transfers or to use something like OpenZeppelin’s safeTransfer/safeTransferFrom unless one is sure the given token reverts in case of a failure. Failure to do so will cause silent failures of transfers and affect token accounting in contract.

Proof of Concept

https://github.com/code-423n4/2022-01-trader-joe/blob/main/contracts/LaunchEvent.sol#L457

https://github.com/code-423n4/2022-01-trader-joe/blob/main/contracts/LaunchEvent.sol#L463

https://github.com/code-423n4/2022-01-trader-joe/blob/main/contracts/LaunchEvent.sol#L489

https://github.com/code-423n4/2022-01-trader-joe/blob/main/contracts/LaunchEvent.sol#L513

https://github.com/code-423n4/2022-01-trader-joe/blob/main/contracts/LaunchEvent.sol#L537

Recommended Mitigation Steps

Consider using safeTransfer/safeTransferFrom or require() consistently.

cryptofish7 (Trader Joe) confirmed and commented:

Fix: https://github.com/traderjoe-xyz/rocket-joe/commit/9e11786ffbfe71f324bc67411270900ec21355fc

LSDan (judge) increased severity from Low to Medium and commented:

This could result in a loss of funds given the right external conditions.

2 — Med (M): vulns have a risk of 2 and are considered “Medium” severity when assets are not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.


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

Impact

This could result in a loss of funds given the right external conditions.

What the attacker needed

A token that returns false on failure; external conditions

The fix

The issue was fixed by using safeTransfer/safeTransferFrom or require() consistently.

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 don't revert when a transfer fails; they just return false. If the contract ignores that return value, it may think the transfer worked and update its records incorrectly, which can lose money. Using safeTransfer or checking the return value prevents this.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by cccz

View all

104 more disclosed reports, best first.

More from Trader Joe contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.