Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: morbius55 on May 22, 2021, 06:29:28 PM



Title: wkeys
Post by: morbius55 on May 22, 2021, 06:29:28 PM
Does anyone know what version of Bitcoin Core was the last to use wkeys and how did the wallet.dat differ from later versions. Thanks.


Title: Re: wkeys
Post by: BitMaxz on May 22, 2021, 07:39:59 PM
I tried to search about this there is no much information that I can find but it might these posts below about wkeys.

- https://bitcointalk.org/index.php?topic=5253789.0
- https://bitcointalk.org/index.php?topic=2962.0

The version you might be looking at is the oldest Bitcoin-qt wallet that was created in the year 2009 or 2010.


Title: Re: wkeys
Post by: morbius55 on May 22, 2021, 08:22:55 PM
During my hex editor hard drive search I have stumbled on a wallet file that has wkeys and other keys that are named differently to more modern wallet files. I don't know if wkeys are private keys or not, or whether I need to look at other things in the file. It may come to nothing but I still need to check it out, but I need to understand what I'm looking at. Thanks.


Title: Re: wkeys
Post by: HCP on May 22, 2021, 11:23:32 PM
Found a reference to these wkey's here: https://renenyffenegger.ch/notes/development/Crypto-Currencies/Bitcoin/wallet

It seems they are no longer used:
wkey: Public key (class CPubKey) followed by a wallet key (class CWalletKey). Apparently no longer used.


Indeed, the most recent versions seem to have removed support completely:
        } else if (strType == DBKeys::OLD_KEY) {
            strErr = "Found unsupported 'wkey' record, try loading with version 0.18";
            return false;

Support was dropped in this commit: https://github.com/bitcoin/bitcoin/commit/0b1f4b3c6685d0a6307926d43d166add538061b7#diff-49a07da77d79017222ba989b99048c0a629d3230988ce7b6b74df0d14f727626


Anyway... it looks like this "wkey" may indeed contain a Private key:
Code: (https://github.com/bitcoin/bitcoin/blob/914923d125f5d17b39b4dc05f666d130e80a68b2/src/wallet/walletdb.cpp#L267-L279)
...
            CKey key;
            CPrivKey pkey;
            uint256 hash;

            if (strType == DBKeys::KEY) {
                wss.nKeys++;
                ssValue >> pkey;
            } else {
                OldKey wkey;
                ssValue >> wkey;
                pkey = wkey.vchPrivKey;
            }
...

You can see the privkey being read out of the wkey object.


The definition of the "OldKey" struct is here: https://github.com/bitcoin/bitcoin/blob/914923d125f5d17b39b4dc05f666d130e80a68b2/src/wallet/wallet.h#L679

Not quite sure how that relates to the raw hex in the wallet file tho... Seems you might just be better off attempting to load the wallet file with an old version of Bitcoin Core (ie. <= 0.18) which should be able to handle the wkey records properly.


Title: Re: wkeys
Post by: achow101 on May 23, 2021, 01:05:36 AM
After doing some code archaeology, I am pretty sure that wkey records were never actually used. I am unable to find any point in time where wkey were even able to be written to disk. So it's really odd that you have a wallet file that contains wkeys.

In any case, wkey is supposed to be a private key with some extra metadata. There should be a 4 byte version number, followed by the private key, followed by an 8 byte creation time, followed by an 8 byte expiration time.


Title: Re: wkeys
Post by: morbius55 on May 23, 2021, 10:10:38 AM
After doing some code archaeology, I am pretty sure that wkey records were never actually used. I am unable to find any point in time where wkey were even able to be written to disk. So it's really odd that you have a wallet file that contains wkeys.

In any case, wkey is supposed to be a private key with some extra metadata. There should be a 4 byte version number, followed by the private key, followed by an 8 byte creation time, followed by an 8 byte expiration time.
It's probably not an old Qt wallet file then. Maybe it's an old exchange wallet? This is a screenshot of part of the wallet file. Thanks for the info.
https://imgur.com/a/gOm4fh8


Title: Re: wkeys
Post by: HCP on May 23, 2021, 10:38:47 AM
It's probably not an old Qt wallet file then. Maybe it's an old exchange wallet? This is a screenshot of part of the wallet file. Thanks for the info.
https://talkimg.com/images/2023/11/14/zNGvl.png

Errrrr... that's not a wallet file... that's the actual Bitcoin Core source code. Another red herring I am afraid :-\


You can see the code in walletdb.cpp here that is matching your screenshot:
...
static bool IsKeyType(string strType)
{
    return (strType== "key" || strType == "wkey" ||
            strType == "mkey" || strType == "ckey");
}

DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
{
    pwallet->vchDefaultKey = CPubKey();
...


Title: Re: wkeys
Post by: morbius55 on May 23, 2021, 10:58:04 AM
Thanks @HCP, another thing to cross off. Cheers.