code-423n4 / 2024-08-superposition-findings

0 stars 0 forks source link

Incorrect Validation in `_onTransferReceived` Function Leads to Stuck Tokens and Failed Transfers #133

Closed howlbot-integration[bot] closed 1 month ago

howlbot-integration[bot] commented 1 month ago

Lines of code

https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/sol/OwnershipNFTs.sol#L93

Vulnerability details

There is an incorrect check in the _onTransferReceived function that results in improper validation of the recipient contract when transferring NFTs. Specifically, the function is designed to ensure that the recipient contract implements the onERC721Received interface by checking the returned selector. However, the current implementation incorrectly checks return data.

Impact

The incorrect condition causes two major issues:

Recommended Mitigation Steps

    function _onTransferReceived(
        address _sender,
        address _from,
        address _to,
        uint256 _tokenId
    ) internal {
        // only call the callback if the receiver is a contract
        if (_to.code.length == 0) return;

        bytes4 data = IERC721TokenReceiver(_to).onERC721Received(
            _sender,
            _from,
            _tokenId,

            // this is empty byte data that can be optionally passed to
            // the contract we're confirming is able to receive NFTs
            ""
        );

        require(
-           data != IERC721TokenReceiver.onERC721Received.selector,
+           data == IERC721TokenReceiver.onERC721Received.selector,
            "bad nft transfer received data"
        );
    }

Assessed type

Error

c4-judge commented 3 weeks ago

alex-ppg changed the severity to 2 (Med Risk)

c4-judge commented 3 weeks ago

alex-ppg marked the issue as satisfactory