-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug]: ethers signTypedData returns incorrect signature / recovered address #7792
[Bug]: ethers signTypedData returns incorrect signature / recovered address #7792
Comments
Can confirm seeing similar issues with https://nft.coinbase.com .. Confirmed that switching wallets solved the issue for us. |
Thanks for the report! We're trying to reproduce the issue but haven't had success yet. Could you share an example message that demonstrates the problem? I see that you provided a partial example already, but quite a few details are missing (e.g. the ABI types and the example value) |
Sure, here is a more expanded version of the snippet above.
|
Thanks, that was very helpful! I have been able to reproduce the problem |
In v7.10.0, signatures including a `bytes` field with the value `0x` were being encoded differently than before. Previously the string `0x` was interpreted as an "empty" hex number, but as of v7.10.0 they were encoded as the string "0x". This change was not intentional, and it resulted in invalid signatures. This problem was introduced in `@metamask/eth-sig-util@6.0.1` (see here for details: MetaMask/eth-sig-util#340). This package was introduced to mobile when `@metamask/keyring-controller` was updated to v6 (#7267). The keyrings themselves still use `@metamask/eth-sig-util@5.0.1`, but the `KeyringController` is signing these messages directly rather than delegating to the keyrings, which is why the newer `@metamask/eth-sig-util` package is used here. This has been resovled by patching `@metamask/keyring-controller` to delegate signing typed messages to the keyrings. The very next release of that package includes that change anyway. We will wait until this bug is fixed before updating `@metamask/eth-sig-util` in the keyrings. Fixes #7792
The example `eth_signTypedData_v4` message has been updated to include a field that can reproduce this bug: MetaMask/metamask-mobile#7792 That signing bug results in invalid signatures for any messages that include a `bytes` field with the value `0x`.
In v7.10.0, signatures including a `bytes` field with the value `0x` were being encoded differently than before. Previously the string `0x` was interpreted as an "empty" hex number, but as of v7.10.0 they were encoded as the string "0x". This change was not intentional, and it resulted in invalid signatures. This problem was introduced in `@metamask/eth-sig-util@6.0.1` (see here for details: MetaMask/eth-sig-util#340). This package was introduced to mobile when `@metamask/keyring-controller` was updated to v6 (#7267). The keyrings themselves still use `@metamask/eth-sig-util@5.0.1`, but the `KeyringController` is signing these messages directly rather than delegating to the keyrings, which is why the newer `@metamask/eth-sig-util` package is used here. This has been resolved by patching `@metamask/keyring-controller` to delegate signing typed messages to the keyrings. The very next release of that package includes that change anyway. We will wait until this bug is fixed before updating `@metamask/eth-sig-util` in the keyrings. Fixes #7792
The example `eth_signTypedData_v4` message has been updated to include a field that can reproduce this bug: MetaMask/metamask-mobile#7792 That signing bug results in invalid signatures for any messages that include a `bytes` field with the value `0x`.
## **Description** In v7.10.0, signatures including a `bytes` field with the value `0x` were being encoded differently than before. Previously the string `0x` was interpreted as an "empty" hex number, but as of v7.10.0 they were encoded as the string "0x". This change was not intentional, and it resulted in invalid signatures. This problem was introduced in `@metamask/eth-sig-util@6.0.1` (see here for details: MetaMask/eth-sig-util#340). This package was introduced to mobile when `@metamask/keyring-controller` was updated to v6 (#7267). The keyrings themselves still use `@metamask/eth-sig-util@5.0.1`, but the `KeyringController` is signing these messages directly rather than delegating to the keyrings, which is why the newer `@metamask/eth-sig-util` package is used here. This has been resolved by updating all affected versions of `@metamask/eth-sig-util`. ## **Related issues** Fixes #7792 ## **Manual testing steps** 1. Navigate to https://gudahtt.github.io/test-dapp/ in the in-app browser 2. Sign a message using `eth_signTypedData_v4` 3. Attempt to verify that message. On production (v7.10.0) this does not work. It should work correctly on this branch, returning the signing account address. ## **Screenshots/Recordings** **Before** https://recordit.co/xejXpo4mlh **After** https://recordit.co/NnnpxbCVRB ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I’ve properly set the pull request status: - [x] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: legobt <6wbvkn0j@anonaddy.me>
Hey there, just to let you know that the fix above still didn't remove the issue in the most recent MetaMask app. We went with a workaround: using empty string |
It's unclear if this fix was even included in the 7.12.0 release? @Gudahtt for clarity if this fix is active in the app store version of the Metamask app? |
## **Description** In v7.10.0, signatures including a `bytes` field with the value `0x` were being encoded differently than before. Previously the string `0x` was interpreted as an "empty" hex number, but as of v7.10.0 they were encoded as the string "0x". This change was not intentional, and it resulted in invalid signatures. This problem was introduced in `@metamask/eth-sig-util@6.0.1` (see here for details: MetaMask/eth-sig-util#340). This package was introduced to mobile when `@metamask/keyring-controller` was updated to v6 (#7267). The keyrings themselves still use `@metamask/eth-sig-util@5.0.1`, but the `KeyringController` is signing these messages directly rather than delegating to the keyrings, which is why the newer `@metamask/eth-sig-util` package is used here. This has been resolved by updating all affected versions of `@metamask/eth-sig-util`. ## **Related issues** Fixes #7792 ## **Manual testing steps** 1. Navigate to https://gudahtt.github.io/test-dapp/ in the in-app browser 2. Sign a message using `eth_signTypedData_v4` 3. Attempt to verify that message. On production (v7.10.0) this does not work. It should work correctly on this branch, returning the signing account address. ## **Screenshots/Recordings** **Before** https://recordit.co/xejXpo4mlh **After** https://recordit.co/NnnpxbCVRB ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I’ve properly set the pull request status: - [x] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: legobt <6wbvkn0j@anonaddy.me>
Missing release label release-7.12.5 on issue. Adding release label release-7.12.5 on issue, as issue is linked to PR #7886 which has this release label. |
Sorry for the mix-up, this fix will be included in v7.12.5 |
The example `eth_signTypedData_v4` message has been updated to include a field that can reproduce this bug: MetaMask/metamask-mobile#7792 That signing bug results in invalid signatures for any messages that include a `bytes` field with the value `0x`.
Describe the bug
Over the last week, when using the ethers signTypedData function on Metamask Mobile, the returned signature does not return the correct signer address when trying to recover it using the ethers verifyTypedData function.
This behavior on Metamask mobile is completely different from the desktop extension. When going through the same flow on desktop, the returned signature is correctly recovered with the correct address when using the verifyTypedData function.
This bug is affecting all users interacting/performing marketplace actions such as listing/delisting with NFT marketplaces based on the Avalanche network that require signing messages.
I'm just trying to get clarity as to how these functions might behave differently on mobile vs desktop. In the E2E metamask dapp, the signTypedData function seems to still work correctly.
Expected behavior
The ethers signTypedData function should returns a signature that can recover the signer on mobile. This function works as expected on desktop with the Metamask extension.
Screenshots/Recordings
No response
Steps to reproduce
Error messages or log output
No response
Version
7.10.0
Build type
None
Device
iPhone 13 Pro Max
Operating system
iOS
Additional context
This is an example of how we're structuring the message to be signed. This is recoverable on desktop but not on Metamask Mobile.
Severity
No response
The text was updated successfully, but these errors were encountered: