Bitcoin Forum
May 25, 2024, 11:12:09 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: wif decodes longer than expected  (Read 699 times)
sdp (OP)
Sr. Member
****
Offline Offline

Activity: 469
Merit: 281



View Profile WWW
December 24, 2013, 03:13:54 PM
 #1

It looks as if my Satoshi client has a 33 byte secret.  Decoding the wif, which is a string I got from dumpprivkey.  Now, when decoded from base58 this much longer string should turn into something 37 bytes long.  Instead of that it is 38 bytes long.  Is there a longer magic number now?


Coinsbank: Left money in their costodial wallet for my signature.  Then they kept the money.
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
December 24, 2013, 09:50:19 PM
 #2

compression flag?

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
sdp (OP)
Sr. Member
****
Offline Offline

Activity: 469
Merit: 281



View Profile WWW
December 26, 2013, 02:40:44 PM
 #3

Code:
function chomp( sequence o )
    if length(o) and o[length(o)]='\n' then
return o[1..length(o)-1]
    end if
    return o
end function

constant pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
function decode_base_58(sequence s)
atom answer = 0
atom power_multicand = 1
for i = length(s) to 1 by -1 do
answer += power_multicand * (find(s[i],pszBase58)-1)
power_multicand *= 58
end for
return answer
end function

sequence line = chomp(gets(0))

? log(decode_base_58(line))/log(256)

You'll need EUPHORIA for this.   (see openeuphoria.org)  Here this decodes a wif sent to standard input and prints the log base 256 of the value.  Now, if the smallest integer greater than or equal to this value is 38, then you need 38 bytes to represent it.

The fact that the numbers are not arbitrary length numbers means nothing for we only care about the magnitude.  I ran this on a wif I got from my bitcoin client and got:

37.87505791

You need 38 bytes for this value.  Arguably we should be able to import the wif I got from one client to another.  I will try this.  The most significant byte is 128 which is the magic number.


Coinsbank: Left money in their costodial wallet for my signature.  Then they kept the money.
sdp (OP)
Sr. Member
****
Offline Offline

Activity: 469
Merit: 281



View Profile WWW
December 26, 2013, 10:53:54 PM
 #4

I see now you have two possible sizes for the secret.  It might be 32 bytes or 33 bytes.  I have found a bug in libbitcoin.

Coinsbank: Left money in their costodial wallet for my signature.  Then they kept the money.
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
December 27, 2013, 02:32:37 AM
 #5

compression flag?

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
sdp (OP)
Sr. Member
****
Offline Offline

Activity: 469
Merit: 281



View Profile WWW
December 28, 2013, 04:51:21 AM
 #6


Yes, you were right.  I only used dumpprivkey and got a long string.  If the flag is true there is an extra byte before the checksum.  This library I am using handles only wifs with 37 byte secrets.

sdp

Coinsbank: Left money in their costodial wallet for my signature.  Then they kept the money.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!