Skip to content
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

fix: Fix eth_signTypedData signatures containing 0x #7886

Merged
merged 2 commits into from
Nov 29, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Nov 20, 2023

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

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • 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.

@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (13acaa7) 37.44% compared to head (a835b4f) 37.44%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7886   +/-   ##
=======================================
  Coverage   37.44%   37.44%           
=======================================
  Files        1052     1052           
  Lines       28193    28193           
  Branches     2517     2517           
=======================================
  Hits        10557    10557           
  Misses      17037    17037           
  Partials      599      599           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@legobeat
Copy link
Contributor

FYI, pending release proposals for actually fixing the issue in @metamask/eth-sig-util:

@Gudahtt Gudahtt added the needs-qa Any New Features that needs a full manual QA prior to being added to a release. label Nov 21, 2023
@Gudahtt Gudahtt force-pushed the fix-eth-signed-type-data-0x-bug branch from a639e5f to d9957de Compare November 21, 2023 21:24
@legobeat
Copy link
Contributor

legobeat commented Nov 22, 2023

We will wait until this bug is fixed before updating @metamask/eth-sig-util in the keyrings.

Alternatively/additionally, #7902 should resolve the issue by replacing both affected versions with fixed updates.

Copy link
Contributor

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.

Copy link

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/test-dapp 7.2.0...8.0.0 None +0/-0 4.45 MB gudahtt

Copy link

socket-security bot commented Nov 22, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: @metamask/eth-sig-util@6.0.2

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

@Gudahtt
Copy link
Member Author

Gudahtt commented Nov 22, 2023

Thanks @legobeat ! That does look like a simpler solution than a patch. I've stolen that commit from your PR and paired it with a test-dapp bump, so that we can consolidate the e2e test coverage and test evidence in one place.

@Gudahtt
Copy link
Member Author

Gudahtt commented Nov 22, 2023

@SocketSecurity ignore @metamask/eth-sig-util@6.0.2

lgbot is a trusted maintainer

@Gudahtt
Copy link
Member Author

Gudahtt commented Nov 23, 2023

This would be ready for review, except that attempts to test this are blocked by #7920

The e2e regression tests are failing for that same reason

@Gudahtt Gudahtt force-pushed the fix-eth-signed-type-data-0x-bug branch 2 times, most recently from 9c2523c to 1b308bf Compare November 24, 2023 15:07
@Gudahtt
Copy link
Member Author

Gudahtt commented Nov 24, 2023

Passing e2e smoke test run: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/5b720d88-8e03-4a03-aa55-e55452fa0bb2

Passing e2e regression test run: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/36bd1108-3d0e-46b2-8273-bd0b46849cfc

@Gudahtt Gudahtt force-pushed the fix-eth-signed-type-data-0x-bug branch from 1b308bf to a835b4f Compare November 24, 2023 18:33
@Gudahtt Gudahtt marked this pull request as ready for review November 24, 2023 18:35
@Gudahtt Gudahtt requested a review from a team as a code owner November 24, 2023 18:35
Copy link
Contributor

E2E test started on Bitrise: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/aabbb8b7-bda6-4046-af19-c34f754644fa
You can also kick off another Bitrise E2E smoke test by removing and re-applying the (Run Smoke E2E) label

legobeat and others added 2 commits November 28, 2023 12:22
The v8 release includes an update to the example message used by the
`eth_signTypedData_v4` button. The updated message was affected by the
bug that this PR should resolve.
@Gudahtt Gudahtt force-pushed the fix-eth-signed-type-data-0x-bug branch from a835b4f to 1805d16 Compare November 28, 2023 15:53
Copy link

sonarcloud bot commented Nov 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@cortisiko cortisiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gudahtt this PR is ✅

In addition to what the E2E tests covered, I also tested signing transactions using keystone.

Additionally I went ahead and did a quick smoke test on one of the dapps used to reproduce the issue.

Scenario:
connect to dapp via WC
proceed to sign a txn.
upon doing so I no longer can reproduce the bug:

iOS: http://recordit.co/aPTiJWrDDq
Android: http://recordit.co/Xpu37j5zVI

Compared to prod where the bug is reproducible: http://recordit.co/UjZ4hqsjHy

@cortisiko cortisiko added QA Passed A successful QA run through has been done and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels Nov 29, 2023
@Gudahtt Gudahtt merged commit 71321b3 into main Nov 29, 2023
28 of 29 checks passed
@Gudahtt Gudahtt deleted the fix-eth-signed-type-data-0x-bug branch November 29, 2023 14:13
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2023
@metamaskbot metamaskbot added the release-7.13.0 Issue or pull request that will be included in release 7.13.0 label Nov 29, 2023
@gauthierpetetin
Copy link
Contributor

Hi @Gudahtt , do you think this issue is related?
#7913 (comment)

@metamaskbot metamaskbot added release-7.12.5 Issue or pull request that will be included in release 7.12.5 and removed release-7.13.0 Issue or pull request that will be included in release 7.13.0 labels Jan 2, 2024
@metamaskbot
Copy link
Collaborator

No release label at all on PR. Adding release label release-7.12.5 on PR, as PR was cherry-picked in branch 7.12.5.

@MetaMask MetaMask deleted a comment from metamaskbot Jan 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
QA Passed A successful QA run through has been done release-7.12.5 Issue or pull request that will be included in release 7.12.5 team-wallet-framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: ethers signTypedData returns incorrect signature / recovered address
7 participants