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

fix issue with 11 bit padding messing up checksum check. #33

Merged
merged 1 commit into from Oct 5, 2016

Conversation

rubensayshi
Copy link
Contributor

when experimenting with using BIP39 mnemonics for encoding non-standard entropy sizes we ran into some odd bug where lpad(index, '0', 11) was making the checksum check fail.
this doesn't occur with the recommended BIP39 entropy sizes, but unless the library is made to limit it's scope completely to the recommended sizes (at which this bug doesn't occur) I think it should be fixed.

in entropyToMnemonic, the chunks for the words we (entropy + checksum).chunk(11), this means the checksum can be split between chunks and the final chunk can be between 1 and 11 bits.

in mnemonicToEntropy, the bits from the words are padded to 11 bytes each and then we slice off the checksum which can contain a padding byte.
by redoing the same step as in entropyToMnemonic and concatenating entropy with newChecksum we always get a comparable result.

@dcousens dcousens merged commit 5a175c1 into bitcoinjs:master Oct 5, 2016
@rubensayshi
Copy link
Contributor Author

@dcousens the tests failed on 0.10 .. ?!

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

I literally just saw that I as I pushed merge... I'm investigating it now

@afk11
Copy link

afk11 commented Oct 5, 2016

thought there weren't any more v0.10 tests? or was that pbkdf2?

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

@afk11 that was PBKDF2 ... which is probably why.

@rubensayshi
Copy link
Contributor Author

yea PBKDF2 latest no longer works on 0.10, but I think you added the engines to the package.json too late maybe?

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

Completely unrelated to the (binary) issues in PBKDF2, or 0.10... or more importantly, this PR.

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

Oh wait, right.
No it is related.
Its using SHA1... sigh, we should just hard throw rather than silently "work".

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

browserify/pbkdf2#36 (comment)

I guess I'm ~OK with that, but, it just sounds like it could hurt someone.

Of course, our repos.
I suppose we drop 0.10 support too?

@rubensayshi
Copy link
Contributor Author

@dcousens yes drop 0.10, it's happening all across the board in bitcoinjs related libs atm so might as well do it here too

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

@rubensayshi done

@rubensayshi
Copy link
Contributor Author

also, this PR actually might have been too hasty, we just realized that the vector I added is 1028 bytes, while > 1024 bytes of entropy the CS = ENT / 32 actually is larger than the max size of the checksum (256 bits)... and all bets are off because nothing is specced in BIP39 about that!

imo there are 2 options:

  1. throw an error when entropy > 1024 bytes
  2. Math.min(CS, 256)

I think 2 is sensible, but ...

@rubensayshi
Copy link
Contributor Author

for now reversing the PR might be a good idea

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

@rubensayshi I wasn't planning to release it for small while yet. I'm working through some examples locally.

@dcousens
Copy link
Contributor

dcousens commented Oct 5, 2016

I think master being unstable has always been the policy, and certainly we should progress forward in resolving this. Do we really need to revert?

@dcousens dcousens mentioned this pull request Oct 5, 2016
@rubensayshi
Copy link
Contributor Author

I'll try to figure out what the right solution is and let you know

@jprichardson
Copy link
Member

I suppose we drop 0.10 support too?

Yes 👍 It's unsupported now as of Oct 1st anyways.

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

Successfully merging this pull request may close these issues.

None yet

4 participants