brave-browser: crypto wallet: auto-generated mnemonic is not standard compatible
Description
Brave does not correctly derive the Ethereum address for 24-word mnemonics. The crypto wallet automatically creates 24 seed words upon first start which are also not yielding the correct address. Entering those seed words in another tool such as MyEtherWallet or MyCrypto derives another address.
As a consequence all funds that are sent to a Brave address cannot be recovered and might be lost!
Steps to Reproduce
- Create a new profile on brave (to have a blank wallet setup)
- Open the crypto wallet and follow the setup instructions
- The setup instructions will lead to a 24-word mnemonic, copy that one (in my case it was
toward around purity endorse style assume seed discover beyond mosquito lend auto cattle shed smile pretty push slot grid hotel eagle govern defense element
- Note the address that is shown in the brave wallet - in my case it was
0xC5443F1948FF4273222E04E93A9365780990Bc1D
- Open e.g. MyEtherWallet (same result using MyCrypto desktop app) or any other standard Ethereum wallet and restore the address from the mnemonic.
- The resulting Ethereum address is a different one, in my case
0x815B52687Ff57Ae9a58B4894e66ad476f0ba224D
Actual result:
The Ethereum address generated in Brave does not match those generated with standard tools.
Expected result:
The Ethereum address generated in Brave should match those generated with standard tools.
Reproduces how often:
Easily reproduced
Brave version (brave://version info)
on Ubuntu 18.04
Brave | 1.8.96 Chromium: 81.0.4044.138 (Official Build) (64-bit)
-- | --
Revision | 8c6c7ba89cc9453625af54f11fd83179e23450fa-refs/branch-heads/4044@{#999}
OS | Linux
JavaScript | V8 8.1.307.32
Miscellaneous Information:
Generally, Brave seems to be unable to import 24-word mnemonics correctly. E.g. the test vector zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote
yields the address 0x63D1ec5Cb2D2D2d3168266E88DA0F08c7455e6D9
(should be 0x1959f5f4979c5Cd87D5CB75c678c770515cb5E0E
).
12-word mnemonics on the other hand do work fine. The test vector zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong
yields the correct address 0xfc2077CA7F403cBECA41B1B0F62D91B5EA631B5E
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 45 (24 by maintainers)
Commits related to this issue
- Give instructions on how to import wallet to a different application Fix https://github.com/brave/brave-browser/issues/9837 — committed to brave/ethereum-remote-client by diracdeltas 4 years ago
Can this be re-opened, as it still is an issue? It is still not fixed as I have a 24-word phrase that cannot be used in Brave because Brave doesn’t follow the standard HD Wallet algorithm for key derivation from it.
IIUC, #13245 only fixed 12-word phrases, but 24-word phrases are still non-standards compliant. While I understand that this is a huge pain to fix, the pain of Brave mnemonics being standards non-compliant is only going to get worse with additional crypto adoption over time and the longer we wait to start on the road to standards compliance in brave the more painful this will be.
My recommendation on long-term migration strategy:
Another option would be that when the user tries to recover a 24 word phrase, check to see which accounts have assets on the current network so we can helpfully hint to the user which one they probably have.
Okay, this can be the 3rd complaint. I expect most users of Brave Crypto Wallet would not realise the issue exists. If they had known of the issue they probably wouldn’t have choosen the Brave Crypto Wallet in the first place.
Is there a guide for deriving seed words that will restore the crypto wallet addresses to other wallets?
i did some digging; findings here
how brave does wallet derivation/restoration
bip39.entropyToMnemonic
to encode it as a mnemonichdkey.fromMasterSeed
directly on the 32-byte seed (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#master-key-generation)bip39.mnemonicToEntropy
on the mnemonic to convert it back into the seedhow metamask does wallet derivation/restoration
as far as i understand:
bip39.generateMnemonic()
to generate 16 bytes of entropy encoded as a mnemonic. this follows https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#generating-the-mnemonic.hdkey.fromMasterSeed
with the 64-byte seedbip39.mnemonicToSeed
unfortunately, i think this will make it difficult for us to encode the brave wallet codewords as other-wallet-compatible code words, because we would need to find the PBKDF2 preimage. if other wallets are willing to take the seed directly as input, that could work.
After a quick skim of the code (way over my head here), is this line correct? https://github.com/brave/brave-core/blob/cd5a08090094fc1a67033e2760c3a067b27e001d/components/brave_sync/crypto/crypto.cc#L148
bip39_mnemonic_to_bytes
only converts the mnemonic into a binary representation, but it does not actually derive the BIP39 seed. That is done bybip39_mnemonic_to_seed
, which doesn’t seem to be used anywhere in the code. Maybe someone mistook the result ofPassphraseToBytes32
as the actual seed to derive keys with?