Title: Correct / incorrect WIF Post by: math09183 on June 29, 2020, 07:54:50 AM Hello
We know that WIF has checksum. I use bitcoin-core library for reading WIF and then retrieving address etc. Usually, when I provide wrong (synthetically incorrect) WIF, parser complains. But recently I have found a few WIFs which are accepted, pubKey is retrieved etc, even if checksum is wrong. What I am missing? KztWMvdFrpEScTmRBVwfmtzqYzb1rcu5PKGGKf6FUij16N2NYS88 retrieved: priv: 6d786c3b9976d286362f4969d3fdf7ccd6abe2314e7435bd7c270837ab19a28e pub: (d4b8c48cd5633ea6bdd2f282f70901b1d9b120631c155263737fdb1f4ef06ace,ffca79e0ca3d894d1f6e26690c0feac80dc9039b084de3b646e15b39d3c02be5,c737176f36ac61ce342338898eba8f65539ee6727b74445b31f9597407c0caf6) address: 18NYbvmXvQ2nducAyGJ8wrsUnyJ5rZc5RD but checking for example on: https://learnmeabitcoin.com/guide/wif checksum is incorrect, it should be: KztWMvdFrpEScTmRBVwfmtzqYzb1rcu5PKGGKf6FUij164yixbkN Title: Re: Correct / incorrect WIF Post by: nc50lc on June 29, 2020, 09:37:09 AM The private key KztWMvdFrpEScTmRBVwfmtzqYzb1rcu5PKGGKf6FUij16N2NYS88 has the correct checksum but the "Compressed flag" is '0x99' instead of '0x01'.
In HEX: 806d786c3b9976d286362f4969d3fdf7ccd6abe2314e7435bd7c270837ab19a28e99029474a9 Green = Private key | Purple = Checksum | The Byte after the private key should be the 'compressed public key' flag. The correct WIF should be: KztWMvdFrpEScTmRBVwfmtzqYzb1rcu5PKGGKf6FUij164yixbkN if you set "01" as the flag instead of "99". Surprisingly, '99' flag resulted in 'K' or 'L' in every random private key that I've tried :-\ But it wont work with well-written clients. Title: Re: Correct / incorrect WIF Post by: Coding Enthusiast on June 29, 2020, 12:53:01 PM Surprisingly, '99' flag resulted in 'K' or 'L' in every random private key that I've tried There are a bunch of different variations that could give similar looking key strings. Here are 3 examples from Bitcoin.Net test vectors (https://github.com/Autarkysoft/Denovo/blob/d77e531bf192834fbfe79e1c0ecd3435fe07128c/Src/Tests/Bitcoin/Cryptography/Asymmetric/KeyPairs/PrivateKeyTests.cs#L221-L229): Code: 5GPHYxaeAAqL2egjmyU8Kaaqh831aw12XJ92y2rgRWi1zc Title: Re: Correct / incorrect WIF Post by: math09183 on June 30, 2020, 07:57:41 AM Surprisingly, '99' flag resulted in 'K' or 'L' in every random private key that I've tried :-\ But it wont work with well-written clients. Apparently there is no check for this in bitcoinj library, it accepts WIFs not only with 99 (as long as checksum is OK): L4V2zpTnbnoTqzfXiyBXsZiaJkPj926jYtxNK65wmGePWWHtzM3W (bf) |