Post
Topic
Board Development & Technical Discussion
Merits 11 from 6 users
Re: BIP39 Calculate checksum
by
NotATether
on 16/12/2020, 23:44:22 UTC
⭐ Merited by LoyceV (4) ,ETFbitcoin (2) ,o_e_l_e_o (2) ,Heisenberg_Hunter (1) ,vapourminer (1) ,pbies (1)
Don't think your hash function is right.

It isn't, OP must have generated the last 4 bits with the dice instead of deriving the checksum.



BIP39 12-word seed phrases have a 128 bit-entropy and a 4 bit checksum for a total of 132 bytes, and the 12th word includes. the last 128/32 = 4 bits of the checksum. Each word in the seed groups log2(2048) 11 bits together because there are 2048 possible words in the wordlist.

You already have 11 words: possible wage deliver gossip first party hair antique salute fuel survey miracle, the 12th word is a combination of 1000110 and a 4 bit checksum. So the last word 10001101011 "miracle" is actually invalid.

Your first 128 bits are 10101000100  11110110001   00111010000  01100100111  01010111011  10100000100  01101000010  00001001111  10111110110  01011101111  11011010101  1000110 as the 128-bit entropy. This is 0xa89ec4e8327577411a104fbecbbf6ac6 in hex.

Your checksum is first_4_bits(SHA256(entropy)), or for your example:

SHA256(0xa89ec4e8327577411a104fbecbbf6ac6) = 0xfdd211682c17f1af399453a541827c07

We take the first 4 bits of this hex, which is 7 ==> 0111. Then we append this to the entropy to get:

 10101000100  11110110001   00111010000  01100100111  01010111011  10100000100  01101000010  00001001111  10111110110  01011101111  11011010101  10001100111


Convert it to a buffer or something, calculate the length (16), multiply by 8, we get 128.


Can you detail this step please? Thank you for your time.

Your bits have to be converted into a byte array in order to pass it to SHA256. In Python you can convert from binary string representation ==> integer ==> hex ==> bytearray to do this.

Code:
# the [2:] just shaves off the '0x' at the beginning
bytearray.fromhex(hex(int('10101000100111101100010011101000001100100111010101110111010000010001101000010000010011111011111011001011101111110110101011000110', 2))[2:])

Other languages have a similar way to convert to a bytes array.