Skip to content

fix: eip712 domains not being valid for gen 5 devices - #624

Merged
montelaidev merged 2 commits into
mainfrom
fix/mul-2054
Aug 20, 2026
Merged

montelaidev merged 2 commits into
mainfrom
fix/mul-2054

Conversation

@montelaidev

@montelaidev montelaidev commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

EIP-712 signing fails on Ledger Gen5 devices with "the signature doesn't match the right address" when the payload omits the EIP712Domain type (common — ethers-style dapps infer it from the domain object keys).
The missing type gets defaulted to an empty list, so both the device and local verification hash an empty domain struct instead of the real domain values. Gen5 devices handle this undefined case differently than older devices, causing the signature check to fail.

Fix: derive the EIP712Domain type from the domain object keys before signing and verification. Payloads that already declare it are untouched — zero behavior change for well-formed input.


Note

Medium Risk
Changes EIP-712 normalization and signature recovery for payloads missing EIP712Domain; well-formed payloads are untouched, but incorrect derivation could affect permit/NFT signing on hardware wallets.

Overview
Fixes Ledger Gen5 failures when dapps send EIP-712 payloads with a populated domain but no types.EIP712Domain (common ethers-style shape). Without this, @metamask/eth-sig-util sanitization treats the domain type as empty, so the host hashes a zero-field domain while the device behaves differently—leading to “The signature doesn't match the right address”.

Adds withDerivedEip712Domain, which builds EIP712Domain from canonical domain keys (in contract order, skipping null/undefined and non-standard keys) when the type is missing or empty; payloads that already declare it are returned unchanged. LedgerKeyring.signTypedData runs this normalization before sanitizeData, sends the derived types to the device, and verifies with the same normalized data. The helper is re-exported from the package entry; unit and keyring tests cover NFT permit-style payloads and on-chain domain separator alignment.

Reviewed by Cursor Bugbot for commit c99a1a1. Bugbot is set up for automated code reviews on this repo. Configure here.

@montelaidev

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "2.0.0-de95397",
  "@metamask-previews/hw-wallet-sdk": "1.0.0-de95397",
  "@metamask-previews/keyring-api": "24.1.0-de95397",
  "@metamask-previews/eth-hd-keyring": "15.0.0-de95397",
  "@metamask-previews/eth-ledger-bridge-keyring": "13.0.2-de95397",
  "@metamask-previews/eth-money-keyring": "4.0.0-de95397",
  "@metamask-previews/eth-qr-keyring": "3.0.0-de95397",
  "@metamask-previews/eth-simple-keyring": "13.0.0-de95397",
  "@metamask-previews/eth-trezor-keyring": "11.0.0-de95397",
  "@metamask-previews/keyring-internal-api": "12.1.0-de95397",
  "@metamask-previews/keyring-internal-snap-client": "11.1.0-de95397",
  "@metamask-previews/keyring-sdk": "3.1.0-de95397",
  "@metamask-previews/eth-snap-keyring": "24.1.0-de95397",
  "@metamask-previews/keyring-snap-client": "10.0.0-de95397",
  "@metamask-previews/keyring-snap-sdk": "10.0.0-de95397",
  "@metamask-previews/keyring-utils": "5.0.0-de95397"
}

@montelaidev montelaidev self-assigned this Aug 20, 2026
@montelaidev
montelaidev marked this pull request as ready for review August 20, 2026 02:53
@montelaidev
montelaidev requested a review from a team as a code owner August 20, 2026 02:53
@montelaidev
montelaidev added this pull request to the merge queue Aug 20, 2026
Merged via the queue into main with commit ad00a66 Aug 20, 2026
24 checks passed
@montelaidev
montelaidev deleted the fix/mul-2054 branch August 20, 2026 09:33
montelaidev added a commit that referenced this pull request Sep 21, 2026
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues or other links reviewers should consult to
understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->
**Description**

EIP-712 signing fails on Ledger Gen5 devices with "the signature doesn't
match the right address" when the payload omits the EIP712Domain type
(common — ethers-style dapps infer it from the domain object keys).
The missing type gets defaulted to an empty list, so both the device and
local verification hash an empty domain struct instead of the real
domain values. Gen5 devices handle this undefined case differently than
older devices, causing the signature check to fail.

Fix: derive the EIP712Domain type from the domain object keys before
signing and verification. Payloads that already declare it are untouched
— zero behavior change for well-formed input.

<!--
Are there any examples of this change being used in another repository?

When considering changes to the MetaMask module template, it's strongly
preferred that the change be experimented with in another repository
first. This gives reviewers a better sense of how the change works,
making it less likely the change will need to be reverted or adjusted
later.
-->


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes EIP-712 normalization and signature recovery for payloads
missing EIP712Domain; well-formed payloads are untouched, but incorrect
derivation could affect permit/NFT signing on hardware wallets.
> 
> **Overview**
> Fixes **Ledger Gen5** failures when dapps send EIP-712 payloads with a
populated `domain` but no `types.EIP712Domain` (common ethers-style
shape). Without this, `@metamask/eth-sig-util` sanitization treats the
domain type as empty, so the host hashes a zero-field domain while the
device behaves differently—leading to **“The signature doesn't match the
right address”**.
> 
> Adds **`withDerivedEip712Domain`**, which builds `EIP712Domain` from
canonical domain keys (in contract order, skipping null/undefined and
non-standard keys) when the type is missing or empty; payloads that
already declare it are returned unchanged.
**`LedgerKeyring.signTypedData`** runs this normalization before
`sanitizeData`, sends the derived types to the device, and verifies with
the same normalized data. The helper is **re-exported** from the package
entry; unit and keyring tests cover NFT permit-style payloads and
on-chain domain separator alignment.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c99a1a1. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants