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

Why is a valid brain seed word count always divisible by 3? #46

Closed
jcalfee opened this issue May 11, 2017 · 7 comments
Closed

Why is a valid brain seed word count always divisible by 3? #46

jcalfee opened this issue May 11, 2017 · 7 comments

Comments

@jcalfee
Copy link

jcalfee commented May 11, 2017

I'm looking at bip-0039 and I'm not sure why you have this check to make sure the brain seed word count is divisible by 3:

https://github.com/bitcoinjs/bip39/blob/v2.3.0/index.js#L34

Maybe I missed something but I don't see this checking either:
https://github.com/bitpay/bitcore-mnemonic/blob/v1.2.5/lib/mnemonic.js#L110

@dcousens
Copy link
Contributor

dcousens commented May 12, 2017

Its an intrinsic property of the encoding algorithm.

11 (1) acquire | ERR: Cannot read property 'map' of null
1111 (2) baby acquire | ERR: Cannot read property 'map' of null
111111 (3) baby mass ability | ERR: Invalid mnemonic checksum
11111111 (4) baby mass dutch
1111111111 (5) baby mass dust afford | ERR: Invalid mnemonic checksum
111111111111 (6) baby mass dust captain able | ERR: Invalid mnemonic checksum
11111111111111 (7) baby mass dust captain baby able | ERR: Invalid mnemonic checksum
1111111111111111 (8) baby mass dust captain baby material
111111111111111111 (9) baby mass dust captain baby mass ancient | ERR: Invalid mnemonic checksum
11111111111111111111 (10) baby mass dust captain baby mass dust absent | ERR: Invalid mnemonic checksum
1111111111111111111111 (11) baby mass dust captain baby mass dust captain ability | ERR: Invalid mnemonic checksum
111111111111111111111111 (12) baby mass dust captain baby mass dust captain badge
11111111111111111111111111 (13) baby mass dust captain baby mass dust captain baby ball | ERR: Invalid mnemonic checksum
1111111111111111111111111111 (14) baby mass dust captain baby mass dust captain baby mass acid | ERR: Invalid mnemonic checksum
111111111111111111111111111111 (15) baby mass dust captain baby mass dust captain baby mass dutch about | ERR: Invalid mnemonic checksum
11111111111111111111111111111111 (16) baby mass dust captain baby mass dust captain baby mass dust casino
1111111111111111111111111111111111 (17) baby mass dust captain baby mass dust captain baby mass dust captain acoustic | ERR: Invalid mnemonic checksum
111111111111111111111111111111111111 (18) baby mass dust captain baby mass dust captain baby mass dust captain baby add | ERR: Invalid mnemonic checksum
11111111111111111111111111111111111111 (19) baby mass dust captain baby mass dust captain baby mass dust captain baby mass about | ERR: Invalid mnemonic checksum
1111111111111111111111111111111111111111 (20) baby mass dust captain baby mass dust captain baby mass dust captain baby mass echo

I'm not sure how @weilu stumbled across it, but it is a good first pass approximation.
Another valid check would be to ensure that the entropy has a length multiple of 4.

@dcousens
Copy link
Contributor

dcousens commented May 12, 2017

The mnemonic must encode entropy in a multiple of 32 bits.

Ref https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#From_mnemonic_to_seed

@dcousens
Copy link
Contributor

dcousens commented May 12, 2017

I'll add a comment and the multiple of 4 check too.

@dcousens
Copy link
Contributor

entropyToMnemonic should probably error out rather than producing an invalid mnemonic though...

@dcousens
Copy link
Contributor

See #47

@dcousens
Copy link
Contributor

It'd be nice to derive an exact proof why this is the case ... otherwise I'd be tempted to remove it in favour of the actual constraint enforcement.

@dcousens dcousens reopened this May 12, 2017
@dcousens
Copy link
Contributor

#49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants