fix: handle calldata tags in custom approvals#23527
fix: handle calldata tags in custom approvals#23527adonesky1 merged 9 commits intoMetaMask:developfrom
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
I have read the CLA Document and I hereby sign the CLA |
efec747 to
b2597bf
Compare
b2597bf to
824e078
Compare
| const [signature, rest] = data.split(spender); | ||
| if (!signature || !rest) { | ||
| throw new Error('Invalid data'); | ||
| } else if (tokenValue.length !== 64) { |
There was a problem hiding this comment.
Perhaps we ought to continue to throw if rest value is less than 64 characters?
There was a problem hiding this comment.
Good call. I added a test for this case here, and added back this check, but it turns out we will throw here before hitting it. If the calldata length is shorter than expected, parseStandardTokenTransactionData will return undefined.
There was a problem hiding this comment.
Could we perhaps add the logic here just in case that upstream code changes?
There was a problem hiding this comment.
Sure, just added this check back!
Co-authored-by: Alex Donesky <alex.donesky@consensys.net>
|
No release label on PR. Adding release label release-11.17.0 on PR, as PR was added to branch 11.17.0 when release was cut. |
Description
The custom token approval utility function in
ui/pages/confirmations/confirm-approve/confirm-approve.util.jsparses ERC20approvecalldata and reconstructs it with an optional custom value.This utility validates that the length of the parsed
valueamount is exactly 64 hex digits, assuming all calldata bytes after thespenderare thevalueand the value is auint256. However, this validation is too strict: it's possible for the calldata to include extra bytes following the value, which the contract will ignore in the call toapprove. These are valid transactions.Including a "calldata tag" for onchain attribution or analytics is an increasingly popular pattern. For example, Seaport uses calldata tags for order attribution, Viem provides a
dataSuffixoption, and Farcaster clients append an attribution suffix to transactions from Farcaster frames.This utility should instead parse the first 64 bytes of the
valueand preserve any extra calldata.Screenshots
Error screenshot:
Related issues
Previous issue in seaport-js: ProjectOpenSea/seaport-js#215
Manual testing steps
approvewith a calldata suffix. For example, using Viem:Pre-merge author checklist
Pre-merge reviewer checklist