Author

Topic: Can I verify the integrety of a QT wallet.dat file without making a transaction? (Read 267 times)

?
Activity: -
Merit: -
Yes, the integrity of the wallet can be verified.

As a security feature, if you want to check the integrity of a QT wallet.dat file without initiating a transaction all steps can help you.
>>Do not sync the wallet and unlock it.
>>Check that the balances correspond to the explorer.
>>Run bitcoin-cli verifychain in order to examine the integrity of the blockchain.
>>Use bitcoin-cli getbalance to view available balance.

If these verifications are satisfactorily passed, probably the wallet.dat file is intact and the balances are ready to be utilized.

Note: Check whether the height of the blockchain of the given wallet is equal to that of the current height of the chain so that one can be sure the wallet is up-to-date.


Do you double-check what you write? bitcoin-cli getbalance might show outdated balance if you don't let Bitcoin Core sync the wallet (a.k.a. finding relevant transaction associated with the wallet). And FWIW, default parameter for verifychain (at least on Bitcoin Core 28.0) doesn't verify whole blockchain.

Thank you for the correction,you're absolutely right.

>>Bitcoin-cli getbalance may show outdated balance if the wallet isn't synced.
>>verifychain default parameter doesn't verify the entire blockchain (requires additional flags)

Thank you for helping me improve accuracy.

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Yes, the integrity of the wallet can be verified.

As a security feature, if you want to check the integrity of a QT wallet.dat file without initiating a transaction all steps can help you.
>>Do not sync the wallet and unlock it.
>>Check that the balances correspond to the explorer.
>>Run bitcoin-cli verifychain in order to examine the integrity of the blockchain.
>>Use bitcoin-cli getbalance to view available balance.

If these verifications are satisfactorily passed, probably the wallet.dat file is intact and the balances are ready to be utilized.

Note: Check whether the height of the blockchain of the given wallet is equal to that of the current height of the chain so that one can be sure the wallet is up-to-date.


Do you double-check what you write? bitcoin-cli getbalance might show outdated balance if you don't let Bitcoin Core sync the wallet (a.k.a. finding relevant transaction associated with the wallet). And FWIW, default parameter for verifychain (at least on Bitcoin Core 28.0) doesn't verify whole blockchain.
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
I am curious though. If you had unencrypted backups of the wallet before, but then before you send any transactions or receive coins to any new addresses, you destroy the wallet.dat file and import it again (or just import it to another computer with Bitcoin Core on it), restoration from the unencrypted backup would technically work, right? As there are no UTXOs associated with any new keys.
That specific scenario will work because as explained by achow101, wallet encryption doesn't get rid of the old used keys.

Not entirely related to the question but will affect the result nonetheless:
In a scenario when it's an old not-synced non-HD wallet.dat backup, it depends on the wallet's keypool and the number of used keys after the backup.
Not much of a problem with newer non-HD wallet.dat with 1000-key gap limit unless it's used a lot.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
I'm wondering if a new set of addresses is generated only when the wallet is first encrypted or if this process repeated everytime you change the passphrase?
It is only done when the wallet is first encrypted. Changing the passphrase will not generate new keys.

I am curious though. If you had unencrypted backups of the wallet before, but then before you send any transactions or receive coins to any new addresses, you destroy the wallet.dat file and import it again (or just import it to another computer with Bitcoin Core on it), restoration from the unencrypted backup would technically work, right? As there are no UTXOs associated with any new keys.
staff
Activity: 3458
Merit: 6793
Just writing some code
I'm wondering if a new set of addresses is generated only when the wallet is first encrypted or if this process repeated everytime you change the passphrase?
It is only done when the wallet is first encrypted. Changing the passphrase will not generate new keys.
?
Activity: -
Merit: -
then a message warned me, that a new back-up should be made after each outgoing transaction.
There is no such message. The message about backups, which you have already seen, is that you need to create a backup after encrypting. There is no need to make a backup after every transaction, nor really with any frequency.

The reason to create a backup after encrypting is because encrypting will generate an entirely new set of keys that will be used going forwards. The old keys remain in the wallet, they just are not used for any new addresses since they were unencrypted and therefore potentially exposed. If you did not make a new backup, any previous backups of the unencrypted wallet would not contain the newly generated keys and therefore restoring such backups would result in missing funds.

I should have been more carefull in my post mentioning the warning message. Hopefully the inaccuracy is now properly corrected. I once checked the passphrase for a copy of the encrypted wallet.dat file by "changing" the passphrase with the same passphrase. I can't remember any warning messages after I did that. I'm wondering if a new set of addresses is generated only when the wallet is first encrypted or if this process repeated everytime you change the passphrase?
staff
Activity: 3458
Merit: 6793
Just writing some code
then a message warned me, that a new back-up should be made after each outgoing transaction.
There is no such message. The message about backups, which you have already seen, is that you need to create a backup after encrypting. There is no need to make a backup after every transaction, nor really with any frequency.

The reason to create a backup after encrypting is because encrypting will generate an entirely new set of keys that will be used going forwards. The old keys remain in the wallet, they just are not used for any new addresses since they were unencrypted and therefore potentially exposed. If you did not make a new backup, any previous backups of the unencrypted wallet would not contain the newly generated keys and therefore restoring such backups would result in missing funds.

As this was unknown to me, I am still wondering if there might be more pitfalls  that could render the wallet useless, even though everything seems fine, without putting it to the test by making a transaction?
Generally, no, as long as you read all of the instructions presented and any dialogs or warning messages. We're pretty thorough about considering what could go wrong and either protecting against those issues or letting the user know.
?
Activity: -
Merit: -
Also, if any transactions were made after the wallet backup, the wallet would still show the old balances. To verify recent transactions, you need to resync the wallet or check online explorers.


That makes sense, unless the wallet.dat file changes after each transaction. I might repeat the experiment later today to check what the warning message that worried me to see was actually about.



After encryption of the wallet, the following message popped-up:

IMPORTANT: Any previous backups you have made of your wallet file should be replaced with the newly generated, encrypted wallet file. For security reasons, previous backups of the unencrypted wallet file will become useless as soon as you start using the new, encrypted wallet.

As mentioned, I had made backups of the wallet (which included the .exe file) on several USB sticks. I remember, that Bitcoin core once would start right from the USB sticks. On second inspection, they do start Bitcoin Core, without any errors, but no transactions are shown, and no block source is available. These backups were not encrypted. If the warning message is correct, then the unencrypted wallet would not work, but I am not going to verify that. In this case, the security feature might have protected me, because I did use the wallet after encryption. But if I would not have had access to the encrypted wallet.dat file, then I would effectively have spoiled the balances.

Can I conclude, that the balances on the wallet.dat file that I encrypted, and never changed passwords, shoud be spendable?

As this was unknown to me, I am still wondering if there might be more pitfalls  that could render the wallet useless, even though everything seems fine, without putting it to the test by making a transaction?
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Or you can download pywallet from git hub and try running;
Code:
wallet=check-integrity


Which pywallet fork you use? I just re-checked https://github.com/jackjack-jj/pywallet, but the source code doesn't mention anything about command check-integrity.
?
Activity: -
Merit: -
I think you should be able to verify the integrity of a wallet.dat file without making a transaction. You could possibly try bitcoin-cl. try opening your Bitcoin Core wallet offline then try using bitcoin-cli  command-line tool to verify balance.
Code:
datadir= getbalance
Then replace with the directory containing your wallet.dat file.

Thanks for your suggestions. I tried the datadir= getbalance command, but "method was not found (code -32601)". Perhaps the getbalance feature was not yet implemented when version 16.3 was released. I'll still have to look into your second suggestion.

I noticed an error in my post: The wallet shows 0 balance, as expected, but does show the transactions. The wallet.dat file has been rescanned by a synchronized v 19.01 quite recently though, and then it showed the balance in correspondence with the transactions.



If you are able to unlock your wallet and all of the transactions and balances show as you expect, then you can be reasonably confident that you can spend that balance.

The wallet will perform its own integrity check when unlocking - it either computes the public key from the stored private key and compares it against the stored public key, or it does that for a single key and checks that the rest had a valid stored checksum. This should protect against random corruption, although the latter does not protect against malicious modification (not a problem if the wallet is actually yours).

The balance is computed on-the-fly by checking which outputs of the transactions stored in the wallet are spendable by the stored keys (or descriptors), so as long as the keys are correct, the balance should be spendable.

Thanks. I hope it's as simple as that. I noticed an error in my post: The wallet shows 0 balance, as expected (never synchronized), but it does show the transactions. The wallet.dat file has been rescanned by a synchronized v 19.01 quite recently though, and then it showed the balance in correspondence with the transactions.

What made me worry though, is that when I tested the encryption/unlocking procedure using the command line, with the empty wallet.dat file that came with the intallation, then a message warned me, that a new back-up should be made after each outgoing transaction. I made some back-ups in between several transactions. And these indeed do not seem to work at all. They try to run the client, then it shuts down. I might have used the back-up button that put the whole bitcoin wallet on the USB sticks back then. I don't remember. Perhaps I messed that up in another way. No wallet.dat files to be found there either. Luckily, I still had access to the original wallet.dat file, so I could just rescan. I'm worried, because I can't be completely sure if any of the transactions were made after I copied the encrypted wallet.dat file. But if you can mess the back-up as easiiy as that, then there are probably many more ways, that you can mess things up. So as of now, things look pretty fine, but I'm still worried what will happen if I want to transact from the wallet.

Mod note: consecutive posts merged
staff
Activity: 3458
Merit: 6793
Just writing some code
If you are able to unlock your wallet and all of the transactions and balances show as you expect, then you can be reasonably confident that you can spend that balance.

The wallet will perform its own integrity check when unlocking - it either computes the public key from the stored private key and compares it against the stored public key, or it does that for a single key and checks that the rest had a valid stored checksum. This should protect against random corruption, although the latter does not protect against malicious modification (not a problem if the wallet is actually yours).

The balance is computed on-the-fly by checking which outputs of the transactions stored in the wallet are spendable by the stored keys (or descriptors), so as long as the keys are correct, the balance should be spendable.
sr. member
Activity: 448
Merit: 560
Crypto Casino and Sportsbook
I think you should be able to verify the integrity of a wallet.dat file without making a transaction. You could possibly try bitcoin-cl. try opening your Bitcoin Core wallet offline then try using bitcoin-cli  command-line tool to verify balance.
Code:
datadir= getbalance
Then replace with the directory containing your wallet.dat file.

Or you can download pywallet from git hub and try running;
Code:
wallet=check-integrity

Like I said earlier also try replacing ` with the path to your wallet.dat file

Make sure to run everything offline to be on a safer side. Also, if any transactions were made after the wallet backup, the wallet would still show the old balances. To verify recent transactions, you need to resync the wallet or check online explorers.
?
Activity: -
Merit: -
I have restored a Bitcoin Core wallet from a wallet.dat file with some balances on it. I used an old off-line computer running on Windows Vista, so I used version 16.3 of Bitcoin Core. I need to urgently verify the integrety of the wallet.dat file, but I do not want to make a transaction for now. I can unlock and open the wallet without synchronization, and it shows the same balances as in the explorer. Can I be absolutesly sure, that these balances are spendable? As an example of a potential complication, let's assume, that same transactions were made, after the wallet was backed-up and encrypted, would it open and show balances, as described? Is there anything I can or need to do to verify that the balances are safe? Or should it just be fine, since it shows the same transactions and balances as the explorer after unlocking the wallet?
Jump to: