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!: bug 4157, use getAccounts on HD Keyring when calling addNewAccount #4158

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

montelaidev
Copy link
Contributor

@montelaidev montelaidev commented Apr 15, 2024

Explanation

This PR addresses a bug in the keyring controller where invoking addNewAccount inadvertently retrieves addresses from all keyrings, rather than exclusively from the HD keyring. This behavior leads to inconsistencies and errors when accounts from different keyring types are present. The primary symptom of this bug is the retrieval of an incorrect number of accounts, with some operations potentially resulting in an undefined address. This issue is notably impactful as it can cause the selectedAddress to be undefined in clients, leading to unexpected behavior and degraded user experience.

References

Changelog

@metamask/keyring-controller

  • BREAKING: Use getAccounts on HD keyring when calling addNewAccount instead of this.getAccounts which retrieves every account.

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 highlighted breaking changes using the "BREAKING" category above as appropriate

@montelaidev montelaidev requested a review from a team as a code owner April 15, 2024 08:18
@montelaidev montelaidev force-pushed the fix/add-accounts-for-hd-keyring branch from 3adcfb8 to 3207511 Compare April 15, 2024 08:23
@montelaidev montelaidev changed the title fix: bug 4157, don't use this.getAccounts() to get accounts for only hd keyring fix: bug 4157, use getAccounts on HD Keyring when calling addNewAccount Apr 15, 2024
const oldAccounts = await this.getAccounts();
const oldAccounts = await primaryKeyring.getAccounts();
Copy link
Member

Choose a reason for hiding this comment

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

If we change this here, then we probably have to change what's being used by the extension as accountCount, as we currently count all accounts there: https://github.com/MetaMask/metamask-extension/blob/6e0483da7d5269cbb3afdba2ea579902e9d2987b/app/scripts/metamask-controller.js#L3602

Copy link
Member

Choose a reason for hiding this comment

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

for this reason we should mark this PR as breaking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, we should mark this as breaking and also make the change in the clients as well.

@montelaidev montelaidev changed the title fix: bug 4157, use getAccounts on HD Keyring when calling addNewAccount breaking: bug 4157, use getAccounts on HD Keyring when calling addNewAccount Apr 16, 2024
@montelaidev
Copy link
Contributor Author

@metamaskbot publish-previews

@montelaidev montelaidev changed the title breaking: bug 4157, use getAccounts on HD Keyring when calling addNewAccount fix!: bug 4157, use getAccounts on HD Keyring when calling addNewAccount Apr 16, 2024
@montelaidev montelaidev merged commit 3dafe52 into main Apr 16, 2024
139 checks passed
@montelaidev montelaidev deleted the fix/add-accounts-for-hd-keyring branch April 16, 2024 14:35
@montelaidev montelaidev mentioned this pull request Apr 17, 2024
3 tasks
montelaidev added a commit that referenced this pull request Apr 17, 2024
## Explanation

## References

## Changelog

## [13.0.0] Accounts Controller

### Changed

- Fix update setSelectedAccount to throw if the id is not found
([#4167](#4167))
- Fix normal account indexing naming with index gap
([#4089](#4089))
- **BREAKING** Bump peer dependency `@metamask/snaps-controllers` to
`^6.0.3` and dependencies `@metamask/snaps-sdk` to `^3.1.1`,
`@metamask/eth-snap-keyring` to
`^3.0.0`([#4090](#4090))

## [28.0.0] Assets Controller

### Added

- Add reservoir migration
([#4030](#4030))

### Changed

- Fix getting nft tokenURI
([#4136](#4136))
- **BREAKING** Bump peer dependency on `@metamask/keyring-controller`
([#4090](#4090))
- Fix token detection during account change
([#4133](#4133))
- Fix update nft metadata when toggles off
([#4096](#4096))
- Adds `tokenMethodIncreaseAllowance`
([#4069](#4069))
- Fix mantle token mispriced
([#4045](#4045))

## [15.0.0] Keyring Controller

### Changed

- **BREAKING** use getAccounts on HD Keyring when calling addNewAccount
([#4158](#4158))
- Pass CAIP-2 scope to execution context
([#4090](#4090))
- Allow gas limits to be changed during #addPaymasterData
([#3942](#3942))

## [10.0.0] Preferences Controller

### Changed

- **BREAKING** Bump peer dependency on `@metamask/keyring-controller` to
`^15.0.0` ([#4090](#4090))
- Restore previous behavior of toChecksumHexAddress
([#4046](#4046))

## [15.0.0] Signature Controller

### Changed

- **BREAKING** Bump peer dependency on `@metamask/keyring-controller` to
`^15.0.0` ([#4090](#4090))

## [8.0.0] User Operation Controller 

### Changed

- **BREAKING** Bump peer dependency on `@metamask/keyring-controller` to
`^15.0.0` and Pass CAIP-2 scope to execution context
([#4090](#4090))
- Allow gas limits to be changed during #addPaymasterData
([#3942](#3942))


## 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 highlighted breaking changes using the "BREAKING" category
above as appropriate
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.

KeyringController addAccounts retrieves all addresses instead of only hd addresses
3 participants