Skip to content

fix: remove metadata for unsupported keyrings #5725

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Apr 29, 2025

Explanation

When the user vault is decrypted and there is an attempt to restore an unsupported/deprecated/faulty keyring there's no mechanism to remove related metadata, which leads to a situation where no further action can be made on the controller, because checks for keyrings and metadata length will fail.

We can remove the related metadata object when the keyring restore fails.

References

Changelog

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Comment on lines +2528 to +2532
if (this.#keyringsMetadata.length > this.#keyrings.length) {
// There was already a metadata entry for the keyring, so
// we need to remove it
this.#keyringsMetadata.splice(this.#keyrings.length, 1);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The downside of this solution is that if we consider the following scenario:

  • There is some metadata for a keyring
  • The keyring fails to restore, for any reason, and metadata will be removed
  • The keyring is then supported again

The keyring will then have a different ID, compared to what it had initially. Unfortunately, to avoid this, we'd have to store the metadata along with its keyring in the vault directly.

Copy link
Member

Choose a reason for hiding this comment

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

We have no mechanism today for moving a keyring from "unsupported" to "supported", to my knowledge. If and when we implement this, we can perhaps treat it like a new keyring and generate new metadata on-the-spot.

That should work OK.

Any other state relying on the metadata would get cleared when it was first moved to unsupported, that is one downside that would not avoid. But I think that's acceptable. Making a keyring unsupported must inevitably impact state that depends on that keyring.

@v-goyal
Copy link

v-goyal commented May 6, 2025

If we remove the metadata, there's no way to get it back yeah? What's the purpose of adding the keyring to unsupportedKeyrings? Should we consider adding unsupportedKeyringsMetadata?

@mikesposito
Copy link
Member Author

If we remove the metadata, there's no way to get it back yeah? What's the purpose of adding the keyring to unsupportedKeyrings? Should we consider adding unsupportedKeyringsMetadata?

@v-goyal Correct, if we remove metadata we won't get it back (that's the downside I was describing here). Unfortunately, we can't apply the same strategy we use for the unsupported keyrings because metadata is stored in the state directly instead of the vault, so removing them from the state would mean immediately persisting the new array of metadata. With keyrings, we don't need to worry about that because even if we skip one of them in the state (because unsupported), it'll still be kept in the vault unchanged and retried at the next unlock.

A solution to do that with metadata would probably be to save them in the vault along with the keyring itself - that would save us a lot of headaches, but it's a more complex solution that would also require a strategy to migrate the existing metadata for users that already have it in the state

@mikesposito mikesposito marked this pull request as ready for review May 7, 2025 11:37
@mikesposito mikesposito requested review from a team as code owners May 7, 2025 11:37
@mikesposito
Copy link
Member Author

@metamaskbot publish-preview

Copy link
Contributor

github-actions bot commented May 7, 2025

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "28.0.0-preview-dedc8739",
  "@metamask-previews/address-book-controller": "6.0.3-preview-dedc8739",
  "@metamask-previews/announcement-controller": "7.0.3-preview-dedc8739",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-dedc8739",
  "@metamask-previews/approval-controller": "7.1.3-preview-dedc8739",
  "@metamask-previews/assets-controllers": "61.0.0-preview-dedc8739",
  "@metamask-previews/base-controller": "8.0.1-preview-dedc8739",
  "@metamask-previews/bridge-controller": "21.0.0-preview-dedc8739",
  "@metamask-previews/bridge-status-controller": "18.0.0-preview-dedc8739",
  "@metamask-previews/build-utils": "3.0.3-preview-dedc8739",
  "@metamask-previews/chain-agnostic-permission": "0.6.0-preview-dedc8739",
  "@metamask-previews/composable-controller": "11.0.0-preview-dedc8739",
  "@metamask-previews/controller-utils": "11.8.0-preview-dedc8739",
  "@metamask-previews/delegation-controller": "0.2.0-preview-dedc8739",
  "@metamask-previews/earn-controller": "0.13.0-preview-dedc8739",
  "@metamask-previews/eip1193-permission-middleware": "0.1.0-preview-dedc8739",
  "@metamask-previews/ens-controller": "16.0.0-preview-dedc8739",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-dedc8739",
  "@metamask-previews/gas-fee-controller": "23.0.0-preview-dedc8739",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-dedc8739",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-dedc8739",
  "@metamask-previews/keyring-controller": "21.0.6-preview-dedc8739",
  "@metamask-previews/logging-controller": "6.0.4-preview-dedc8739",
  "@metamask-previews/message-manager": "12.0.1-preview-dedc8739",
  "@metamask-previews/multichain": "4.0.0-preview-dedc8739",
  "@metamask-previews/multichain-api-middleware": "0.2.0-preview-dedc8739",
  "@metamask-previews/multichain-network-controller": "0.6.0-preview-dedc8739",
  "@metamask-previews/multichain-transactions-controller": "0.10.0-preview-dedc8739",
  "@metamask-previews/name-controller": "8.0.3-preview-dedc8739",
  "@metamask-previews/network-controller": "23.4.0-preview-dedc8739",
  "@metamask-previews/notification-services-controller": "7.0.0-preview-dedc8739",
  "@metamask-previews/permission-controller": "11.0.6-preview-dedc8739",
  "@metamask-previews/permission-log-controller": "3.0.3-preview-dedc8739",
  "@metamask-previews/phishing-controller": "12.5.0-preview-dedc8739",
  "@metamask-previews/polling-controller": "13.0.0-preview-dedc8739",
  "@metamask-previews/preferences-controller": "17.0.0-preview-dedc8739",
  "@metamask-previews/profile-sync-controller": "13.0.0-preview-dedc8739",
  "@metamask-previews/queued-request-controller": "10.0.0-preview-dedc8739",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-dedc8739",
  "@metamask-previews/remote-feature-flag-controller": "1.6.0-preview-dedc8739",
  "@metamask-previews/sample-controllers": "0.1.0-preview-dedc8739",
  "@metamask-previews/selected-network-controller": "22.0.0-preview-dedc8739",
  "@metamask-previews/signature-controller": "28.0.0-preview-dedc8739",
  "@metamask-previews/token-search-discovery-controller": "3.1.0-preview-dedc8739",
  "@metamask-previews/transaction-controller": "55.0.0-preview-dedc8739",
  "@metamask-previews/user-operation-controller": "34.0.0-preview-dedc8739"
}

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.

Keyring metadata mismatch for unsupported keyrings
3 participants