idx can be bigger than (userTokenIds.length - 1) and bridgeNftToAnotherChain will not work as expected
In the bridgeNftToAnotherChain function, the contract bridges the NFT from a user to another chain. The idx variable in catInfo basically means how many NFTs has this user, taking in consideration the ones that he has not anymore. This happens because when he transfers an NFT to someone else, his s_ownerToCatsTokenId mapping is not updated and the tokenId is not removed from it. So consider this scenario :
User A has 5 NFTS [0, 1, 2, 3, 4].
He want to bridge the NFT with the ID of 1 to another chain and the array will result like this : [0, 4, 2, 3]
Now he wants to bridge the NFT with the id of 4 to another chain. Here the bug it is. The idx of 4. In this if statement:
the condition will not be satisfied since 4 (idx) = 4 (userTokenIds.length - 1). This means that the array of tokenIds of user will result like this [0, 4, 3] but this is not the expected scenario since he lost NFT with the ID of 2, instead of this one with ID of 4, which he wanted to transfer.
Basically messes up the functionallity of the protocol and can lead to a loss of NFTs since the s_ownerToCatsTokenId mapping will be not right.
Manual review
##Proof of Concept
Add this test in your test suite after commenting out the last line of the bridgeNftToAnotherChain function for simplicity's sake:
Consider updating index of an NFT when making a transfer to another user or chain.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.