In order to steals Alice NFT on the Game contract, there's some way to do that:
Step to reproduce:
- This method will need Bob to deploy his own NFT (fake) and mint an NFT with the same id that Alice deposited to the Game contract.
- Then, Bob will transfer his NFT to the Game contract. This action will rewrite the mapping tokenId 10 to Bob's address.
- Next, Bob will call
withdrawfunction on the Game contract. This action will success because the validation doing check by comparingoriginalOwner[tokenId] == msg.sender
Code example: With fake attacker NFT
Step to reproduce:
- Bob call public function
onERC721Receivedon Game contract. There's 4 args on itoperator,from,tokenId, anddata. Make sure Bob fillfromwith his address. - In the Game contract implementation, there's a line of code that modify the state of mapping tokenId with
form
originalOwner[tokenId] = from;4.Next, Bob will call withdraw and it will be success.
Code example: Calling onERC721Received function directly