iancoleman / bip39

A web tool for converting BIP39 mnemonic codes
https://iancoleman.io/bip39/
MIT License
3.41k stars 1.42k forks source link

Is Dice6 entropy calculated wrong? #636

Closed ZenDragonX closed 11 months ago

ZenDragonX commented 11 months ago

Hello, when calculating dice rolls for 100 rolls of the dice it is saying that 100 rolls is only 169 bits of entropy. However log2(6^100) = 258. Not 169.

iancoleman commented 11 months ago

See entropy.js L26-29 and this comment in #435 to understand why a single dice roll is less than log2(6) bits of entropy (whole conversation in 435 is worth reading, the topic definitely evaded my own intuition and is pretty fascinating).

brianddk commented 3 months ago

I'm siding with @ZenDragonX on this one.

Using the DICE entropy string "123456123456" notice the filtered entropy goes to "123450123450". So ONLY 6 wraps? If the symbols are {1,2,3,4,5,6} then 6 should be valid. Perhaps filtered base6 should read "012345012345" but wrapping ONLY 6, while leaving the rest unchanged seems weird to me.

You can spot-check this against : https://github.com/Coldcard/firmware/blob/master/docs/rolls.py to show the "wrapping 6 bug". If you try "1234512345" on both you get:

^(tool aim drum remain amazing present strike tattoo fox guilt vessel protect salute forward galaxy hidden long chunk humor lumber upset news build behave)

Subtle... but I really do think this is bugged whenever 6 shows up in the entropy string.

wigy-opensource-developer commented 3 months ago

Good thing is you still have 6 symbols however you label them, so the Shannon entropy has to be the same.