Skip to content
Business logic Audit finding Intermediate

VoteEscrowCore.safeTransferFrom does not check correct magic bytes returned from receiver contract’s onERC721Received function

The VoteEscrowCore.safeTransferFrom function calls onERC721Received on the receiver but does not verify that the returned value equals the required magic bytes. An attacker could send NFTs to a non-compliant contract that implements a fallback function, causing the tokens to be lost.

sseefried Follow

Originally disclosed on Code4rena

Submitted by sseefried, also found by 0x4non, arcoun, berndartmueller, cccz, csanuragjain, IllIllI, Jmaxmanblue, JohnSmith, Lambda, minhquanym, rbserver, and rotcivegaf

ERC721.sol#L395-L417

While VoteEscrowCore.safeTransferFrom does try to call onERC721Received on the receiver it does not check the for the required “magic bytes” which is IERC721.onERC721received.selector in this case. See OpenZeppelin docs for more information.

It’s quite possible that a call to onERC721Received could succeed because the contract had a fallback function implemented, but the contract is not ERC721 compliant.

The impact is that NFT tokens may be sent to non-compliant contracts and lost.

Proof of Concept

Lines 604 - 605 are:

try IERC721Receiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data) returns (bytes4) {} catch (
    bytes memory reason

but they should be:

try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
    return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason)

Recommended Mitigation Steps

Implement safeTransferReturn so that it checks the required magic bytes: IERC721Receiver.onERC721Received.selector.

zeroexdead (Golom) confirmed

zeroexdead (Golom) commented:

Fixed. Ref: https://github.com/golom-protocol/contracts/commit/19ba6e83892e24b859f081525c7e0f751f5e7ebb

0xsaruman (Golom) resolved, but disagreed with severity


The original report as published on Code4rena, by sseefried. 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 safeTransferFrom function does not verify that the receiver's onERC721Received returns the expected selector, so any successful call (even via a fallback) is accepted.

Impact

NFT tokens may be sent to non-compliant contracts and lost.

What the attacker needed

A non-compliant receiver contract; a user initiates a transfer

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 you transfer an NFT to a smart contract, the contract is supposed to confirm it can handle NFTs by returning a specific code. This report says the transfer function didn't check that code, so NFTs could be sent to a contract that can't handle them and get stuck there forever.

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 sseefried

View all

6 more disclosed reports, best first.

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