DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: low
Valid

Use safeTransferFrom() instead of transferFrom() for outgoing erc721 transfers

Summary

It is recommended to use safeTransferFrom() instead of transferFrom() when transferring ERC721s.

Vulnerability Details

The transferFrom() method is used instead of safeTransferFrom(), which I assume is a gas-saving measure. I however argue that this isn’t recommended because:

OpenZeppelin’s documentation discourages the use of transferFrom(); use safeTransferFrom() whenever possible
The recipient could have logic in the onERC721Received() function, which is only triggered in the safeTransferFrom() function and not in transferFrom(). A notable example of such contracts is the Sudoswap pair:

function onERC721Received(
address,
address,
uint256 id,
bytes memory
) public virtual returns (bytes4) {
IERC721 _nft = nft();
// If it's from the pair's NFT, add the ID to ID set
if (msg.sender == address(_nft)) {
idSet.add(id);
}
return this.onERC721Received.selector;
}

NOTE: Although it is written in the comment that "the caller is responsible to confirm that the recipient is capable of receiving ERC721

 * `or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must`

 * `understand this adds an external call which potentially creates a reentrancy vulnerability."`

But this issue can be easily avoided by adding a re-entrancy guard so it is better to use safeTransferFrom with re-entrancy guard and avoid this issue

Impact

While unlikely because the recipient is the function caller, there is the potential loss of NFTs should the recipient is unable to handle the sent ERC721s.

Tools Used

Manual Review

Recommendations

Use safeTransferFrom() when sending out the NFT.

Updates

Lead Judging Commences

0xnevi Lead Judge
almost 2 years ago
0xnevi Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-114

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.