Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui): fix ERC721 and ERC1155 detection in NFT bridge #16680

Merged
merged 3 commits into from
Apr 9, 2024
Merged

fix(bridge-ui): fix ERC721 and ERC1155 detection in NFT bridge #16680

merged 3 commits into from
Apr 9, 2024

Conversation

ricecodekhmer
Copy link
Contributor

@ricecodekhmer ricecodekhmer commented Apr 6, 2024

I wanted to try out the NFT bridging feature, so I created my own NFT, which is an ERC-721 contract on holesky, but I encountered an issue where the 'Scan for NFT' button wasn't working as expected. So, attempting to use the "Add Manually" option, I encountered an error message saying "You must be the owner of all tokens" when entering the address and token id for my NFT.

After setting up the bridge locally and looking at the code, I came to the implementation of the isERC721 function in packages/bridge-ui/src/libs/token/detectContractType.ts, and I realised that the readContract call would always throw an exception if the specified token id didn't match the owner's token id, regardless of whether the contract was ERC-721 or not.

To fix this, I have altered both isERC721 and isERC1155 functions to properly check things by using the standard identifiers (0xd9b67a26 for ERC-1155 and 0x80ac58cd for ERC-721) which adhere to the EIP specifications for the contracts.

Screenshots

Before

Screenshot from 2024-04-06 20-40-29

After

Screenshot from 2024-04-06 20-42-05

Testing

I made sure to test with ERC-20, ERC-1155 and ERC-721 to check if all contracts are identified properly.

@KorbinianK KorbinianK self-assigned this Apr 7, 2024
@KorbinianK
Copy link
Contributor

KorbinianK commented Apr 7, 2024

@ricecodekhmer Thanks for this enhancement, been meaning to change it but tbh. it worked, supportsInterface is just checking it on contract level and requires more than a single function, so certainly the correct approach.

But: I am curious how this changes your ownership check. If the contract type check reverts or fails, you get This is not a valid NFT address on the current network not the one in your screenshot.
That one should only appear if ownerOf(tokenID) fails. Can you send me your verified contract address so I can have a look?

Regardless of this, please fix the comment and adjust the unit tests if you want to have this merged :)

@ricecodekhmer
Copy link
Contributor Author

ricecodekhmer commented Apr 8, 2024

Hi @KorbinianK ,

If the contract type check reverts or fails, you get This is not a valid NFT address on the current network not the one in your screenshot.
That one should only appear if ownerOf(tokenID) fails.

Yes, it's the call to ownerOf that fails because it's wrongly detecting my NFT as an ERC1155 instead of ERC721, if it detected my NFT as an ERC20 or other then it would return This is not a valid NFT address on the current network instead.

After my fix, the functions isERC721 and isERC1155 now are dependant on readContract returning true or false as well as throwing an exception, so I had to change the unit tests because of this.

With regards to the change affecting checking ownership, because the file checkOwnership.ts has the call to readContract with the ownerOf function, it's not an issue.

My NFT is 0x8afe0455f3063426929d3b973d2366a914c47344, it's an ERC721. I've tested also with NFTs I've found on etherscan like this ERC1155 0xab50971078225d365994dc1edcb9b7fd72bb4862 and this ERC20 0x73d9a99c4bd6e5588df7681a1cd0d60e9b8b331c

This screenshot is when I try to input the wrong tokenid:

Screenshot2

This is when I enter an ERC20 address:
Screenshot1

Thank you.

@davidtaikocha davidtaikocha added this pull request to the merge queue Apr 9, 2024
Merged via the queue into taikoxyz:main with commit ca45aa6 Apr 9, 2024
4 checks passed
Copy link

gitpoap-bot bot commented Apr 9, 2024

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2024 Taiko Contributor:

GitPOAP: 2024 Taiko Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants