fix: include safeTransferFrom in first-time interaction recipient decoding#8723
Open
vinistevam wants to merge 2 commits intomainfrom
Open
fix: include safeTransferFrom in first-time interaction recipient decoding#8723vinistevam wants to merge 2 commits intomainfrom
safeTransferFrom in first-time interaction recipient decoding#8723vinistevam wants to merge 2 commits intomainfrom
Conversation
2bd91ea to
6dae597
Compare
6dae597 to
d80dab4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Follow-up to #8130. Extends the first-time-interaction recipient-decoding fix to ERC721/ERC1155
safeTransferFromtransfers, which were not covered by the original change and silently suppress the first-time-interaction warning when sending NFTs to a new recipient.Problem
getEffectiveRecipientinfirst-time-interaction.tsonly treatedtokenMethodTransferandtokenMethodTransferFromas token-transfer types. FortokenMethodSafeTransferFrom(ERC721safeTransferFrom(from,to,tokenId), ERC721safeTransferFrom(from,to,tokenId,data), and ERC1155safeTransferFrom/safeBatchTransferFrom), it fell through totxParams.to— i.e. the NFT contract address — instead of decoding the actual recipient.This caused two failure paths, both suppressing the warning:
getAccountAddressRelationshipwas queried with the NFT contract address asto. Any popular collection returnscount > 0, soisFirstTimeInteraction = falseand the alert never fires.safeTransferFromto the same NFT contract,existingTransactions.find()matched on contract address and skipped the API call entirely, even when the new transfer's recipient was a never-before-seen address.Net effect: the first-time-interaction warning was silently suppressed for NFT transfers — including transfers to lookalike/attacker addresses.
Solution
Add
TransactionType.tokenMethodSafeTransferFromtoTOKEN_TRANSFER_TYPESsogetEffectiveRecipientdecodes the recipient fromtxParams.data. The existingparsed?.args?._to ?? parsed?.args?.to ?? tofallback chain already handles all three relevant ABI shapes (ERC721 3-arg, ERC721 4-arg withbytes, and ERC1155safeTransferFrom/safeBatchTransferFrom).Comments updated to reflect that the rationale applies to ERC20/ERC721/ERC1155, not just ERC20.
References
Fixes https://consensyssoftware.atlassian.net/browse/CONF-1350
Checklist
Note
Medium Risk
Updates first-time-interaction recipient resolution for
safeTransferFromtoken/NFT transfers, affecting when security warnings are shown and when API calls are skipped based on prior transactions.Overview
Fixes first-time-interaction detection for NFT/token
safeTransferFromtransfers by treatingTransactionType.tokenMethodSafeTransferFromas a token-transfer type and decoding the effective recipient fromtxParams.datainstead of using the token contract address.This ensures both the account-relationship API request and the existing-transaction short-circuit compare against the decoded recipient, and adds targeted tests covering ERC721 (3-arg/4-arg) and ERC1155
safeTransferFromshapes plus effective-recipient matching behavior. Documentation/changelog entries were updated accordingly.Reviewed by Cursor Bugbot for commit d80dab4. Bugbot is set up for automated code reviews on this repo. Configure here.