Use safeTransferFrom instead of transferFrom for ERC721 transfers
The Cally contract used transferFrom instead of safeTransferFrom for ERC721 transfers, which bypasses the onERC721Received callback. This could cause NFTs with receiver logic to be stuck or mishandled when used as call options.
Submitted by hickuphh3, also found by antonttc, berndartmueller, catchup, cccz, dipp, FSchmoede, GimelSec, hake, jah, jayjonah8, joestakey, kebabsec, Kenshin, Kumpa, MiloTruck, minhquanym, peritoflores, rfa, shenwilly, WatchPug, and ynnad
Details & Impact
The transferFrom() method is used instead of safeTransferFrom(), presumably to save gas. I however argue that this isn’t recommended because:
- OpenZeppelin’s documentation discourages the use of
transferFrom(), usesafeTransferFrom()whenever possible - Given that any NFT can be used for the call option, there are a few NFTs (here’s an example) that have logic in the
onERC721Received()function, which is only triggered in thesafeTransferFrom()function and not intransferFrom()
Recommended Mitigation Steps
Call the safeTransferFrom() method instead of transferFrom() for NFT transfers. Note that the CallyNft contract should inherit the ERC721TokenReceiver contract as a consequence.
abstract contract CallyNft is ERC721("Cally", "CALL"), ERC721TokenReceiver {...}
outdoteth (Cally) confirmed and resolved:
the fix for this issue is here; https://github.com/outdoteth/cally/pull/4
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
What the attacker needed
NFT with onERC721Received logic; NFT used as call option
The fix
The contract should call safeTransferFrom instead of transferFrom and inherit ERC721TokenReceiver; the finding was confirmed and resolved.
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.
When an NFT is sent to a contract, the safe version of the transfer function asks the receiving contract if it can handle NFTs. The unsafe version skips that check. Here the contract used the unsafe version, so some NFTs that need that check might not work correctly.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.