-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Accounts sometimes generated differently from TestRPC #640
Comments
Here's an independent BIP32 tool: https://bip32jp.github.io/english/ Entering the following mnemonic together with the path (from testrpc: That is turned into an Ethereum address as follows:
This seems to match Metamask's. Pluggin the same in to
Gives: Which equals to @jprichardson any idea? |
Awesome, thanks for showing the steps! |
According to [axic's work here](#640 (comment)), MetaMask is generating the correct address, so I've corrected that assertion accordingly.
Actually I think it should be validated by a non-JS implementation, such as Trezor. I don't have mine here, but if anyone enters the above mnemonic + path they can retrieve the xprv. |
@FlySwatter it is strange... I've actually recreated it with |
Whoah, this is an increasingly large schism. Could this come from slightly different dictionaries? (Sad to say I don't know much about this niche of crypto) |
Very mysterious, I haven't been able to replicate the derived keys from the |
From the mnemonic both Trezor and the bip39jp give the following I would think the difference is handling the edge cases within the private key derivation method. When a step generates an invalid private key (i.e. not matching the curve requirements) a new one must be generated. I think there wasn't a proper specific way to do this (it was only suggested lately to BIP32) and these tools might implement a different handling. |
This is my Trezor code: https://gist.github.com/axic/72294f8b93cdd6e871de83c570d42444 @jhoenicke can you double check this please? |
@jhoenicke that's funny though, it was actually you suggesting this clarification and perhaps now here's an actual example? See: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2016-April/012611.html |
Best thing about MetaMask's dev beta: Lots of real users on this software, finding those edge cases! |
Hmm, seems pretty unlikely that we've accidentally stumbled upon something like this. I also tried a bunch of different derivations from the same master key |
@christianlundkvist it could be that the very first derivation fails |
Yes good point.
|
Using another random master key Ha, would be so fun if this really was a case of the hash being larger than the prime of the curve. I'm not sure how to dig into it and really test it so hopefully @jhoenicke can shed some light. BTW I bet the website uses bitcore's HD key library (same as lightwallet/metamask uses). |
The website actually uses an its own ancient implementation based on CryptoJS. So another clue might be a wrong edge-case of HMAC. |
@christianlundkvist can you post here |
@axic I'm walking home from Starbucks right now, will post when I get home. We can basically narrow it down to a single derivation step |
@axic So for
If we choose this one as the master now and derive
from the web tool and
from
from the web tool and
from
|
@christianlundkvist I meant the internal loop (and not the resulting keys) of the derivation for that given path |
@axic What do you mean by "internal loop"? I don't know how to compute the internal key derivation steps for a given path, is that possible with |
I guess this is implemented somewhere, but don't really have time to reimplement or dig around in the code right now. |
This doesn't seem to do the internal checks: https://github.com/bitpay/bitcore-lib/blob/master/lib/hdprivatekey.js#L163 (You're using bitcore-lib, correct?) |
@axic Interesting! And
Yes, I use the |
I'm actually testing all this with Trezor (an extended version of the code I've posted above) which matches |
@axic Doesn't look like it's failing at
|
trezor:
bitcore:
The data for private derivation is |
@axic Ah! I've seen that kind of behavior before from bitcore (i.e. dropping leading zeros in private keys). Like here: bitpay/bitcore-lib#47 |
Well, it's sorted now. Someone just needs to fix it :) @FlySwatter I think you need to update that test 😉 |
I think I'm going to add it in a later PR, so I'm not waiting for the fixes. :) Thanks a lot guys, was fun to watch :D Just to clarify: Bitcore is used by eth-lightwallet, so that was the wrong one here? The correct key was |
That seems to be the case, yes. |
@FlySwatter This should happen fairly frequently (like one time in 256) so if bit core changes behavior you might get people who all of a sudden can't get to their Ether because some of the derived addresses changed. The Ether won't be lost, but there probably needs to be some way to use the old algorithm to retrieve the other keys. |
@christianlundkvist actually, that chance is present for every derivation step and there are at least 5 steps (plus more if the step produced an invalid key) for the path used above. |
So should we aim to expose the option to restore the bug at every layer of the stack, or simply offer an outdated build as a step in a recovery process? I'm leaning towards the latter for simplicity.
|
The latter sounds like a reasonable idea to me.
|
sounds like |
I've made a write up here: https://medium.com/@alexberegszaszi/6f3254cc5846 Let me know if something's incorrect! |
Blocked by fixes to bitcore & eth-lightwallet. |
You can test with: bitpay/bitcore-lib#97 |
@axic can you verify the probability of hitting this bug? We're preparing to launch our fix, and we want to prepare appropriately. |
This has been resolved within MetaMask. |
In some but not all cases, the mnemonic used to create & restore a vault in MetaMask is differing from the accounts generated in TestRPC.
MetaMask relies on eth-lightwallet, while testrpc has migrated to ethereumjs-wallet.
The currently reliable test case is:
radar blur cabbage chef fix engine embark joy scheme fiction master release
0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9
0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9
.0xe15D894BeCB0354c501AE69429B05143679F39e0
.Curious if @christianlundkvist or @axic might be able to help determine how this could be?
The text was updated successfully, but these errors were encountered: