Skip to content

Instantly share code, notes, and snippets.

@m9800
Created October 12, 2022 16:26
Show Gist options
  • Save m9800/f1692dd6ca0590b85db66ca5d7b26041 to your computer and use it in GitHub Desktop.
Save m9800/f1692dd6ca0590b85db66ca5d7b26041 to your computer and use it in GitHub Desktop.
re-entrancy project
function _checkOnERC721Received(
       address from,
       address to,
       uint256 tokenId,
       bytes memory data
   ) private returns (bool) {
       if (to.isContract()) {
           try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
               return retval == IERC721Receiver.onERC721Received.selector;
           } catch (bytes memory reason) {
               if (reason.length == 0) {
                   revert("ERC721: transfer to non ERC721Receiver implementer");
               } else {
                   /// @solidity memory-safe-assembly
                   assembly {
                       revert(add(32, reason), mload(reason))
                   }
               }
           }
       } else {
           return true;
       }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment