-
Notifications
You must be signed in to change notification settings - Fork 863
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
mnemonic bisect_left will fail (ungracefully) on other bip39 wordlists #132
Comments
Yes, this line is wrong wordlist_english=list(open(os.path.join(os.path.dirname(os.path.realpath(file)),'english.txt'),'r')) |
english.txt is the standard bip39 english wordlist, and ALL the wordlists being lexographically sorted is a part of the bip39 spec
However, you aren't wrong about the bisection algorithm being incorrect, but for several other completely different reasons. I'm going to submit a patch soon. Furthermore, english.txt is only provided for convenience. If you want to use another wordlist, you can pass it as a sorted list to the 'wordlist' parameter in most of the mnemonic functions |
Perhaps it might be best for convenience reasons to include an assert loop On Wed, Jan 20, 2016 at 4:58 PM, Steven Braeger [email protected]
|
Actually, I've been doing some research with this and what should really This is because in order for the wallet to match the spec, the search index The correct behavior will be one of the following options:
On Thu, Jan 21, 2016 at 6:44 AM, WizardOfOzzie [email protected]
|
If you're computing the sorted list anyway, would it not be simpler to just On Thu, Jan 21, 2016 at 1:47 PM, Steven Braeger [email protected]
|
No, because then the result would be incorrect. The whole point is that They are supposed to be sorted in the file, but the bug appears because the You could compute |
I fixed this with a pull request #141 It uses a hash table for the index lookup and word check operations which is O(1) and doesn't require locale-dependant string comparisons to do either operation. All functions which expect a wordlist can use this type as the wordlist for improved performance, but they all degrade gracefully to O(n) cases if the user provides a list as the wordlist instead of an instance of the type. It also adds support for ALL the languages in bip39, which are now selectable. English remains the default, but you can use any of the others without needing to load them yourself (e.g. |
@Steve132 I've just taken a cursory glance, but it looks fantastic so far, great work! |
This patch fixed the locale-based search issues because it uses only the original index of the standard wordlist, NOT the index calculated from a sorted wordlist or a binary search with string comparisons. It remains fast by using a hash table. I think someone should patch the BIP39 specification where it says the lists must be sorted so as to enable binary search, as we've seen binary-search is not possible to do in a locale-independant way. Instead perhaps the specification should have a recommendation that a hash function be used, perhaps even including C code and look up tables for a minimum-perfect-hash implementation for all languages. |
@wizardofozzie hi! i'm trying to use your fork, but i found the tests are failing. can you add issues to your proyect, so users can report this kind of errors? thanks! |
@reiven Absolutely, mate. I've been dabbling in iOS Pythonista 2.0, Pythonista 1.6 and another branch, so I'll be consolidating and testing the code ASAP (~1-2 days maximum) |
Bisect
only works for sorted wordlists; not an issue if onlyenglish.txt
is used, however, forks using standard bip39 wordlists will fail most ungracefully.eg (Japanese wordlist, forum post)
The text was updated successfully, but these errors were encountered: