Check if possible 11-bit walking possible for ElectrumV2 mnemonic
harningt opened this issue · comments
Microbenchmarks through Caliper has shown that the 11-bit integer method is supremely optimal to that of BigInteger modular arithmetic/bit shifting. However as unopened it currently requires that the encoded data is an even multiple of 11 bits and that the word list is 2^11 (2048 words).
Electrum V2 does not guarantee 2048 words (Portuguese uses a shorter dictionary) and does not guarantee an even multiple of 11 encoded.
The first is easy as it would just require splitting things into a happy path and an unhappy one.
The second would generally be fixable by performing a set number of reads and at the end, read the remaining bits ignoring the fact that it could be 7 bits.
Another issue to account for is that during generation, the data structure has a "custom entropy" as input that could complicate the byte-math. Worst case we specialize it for the common happy path of it being "1".
This may or may not make it into a release as it is merely an optimization of a case that is probably uncommon and has to be balanced with the fact that cryptographic digests are being calculated alongside the generation process due to a brute-force attempt to get a desired prefix.
Implemented in 6f57614 via a related mechanism accounting for padding due to the data typically not being an even multiple of 11 bits.