Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow encryption of watchonly wallets #631

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

achow101
Copy link
Member

Watchonly wallets do not have any private keys to encrypt. It does not make sense to encrypt such wallets, so disable the option to encrypt them.

This avoids an assertion that can be hit when encrypting watchonly descriptor wallets.

As our current behavior allows for encrypting watchonly wallets (no crash with legacy, crash, but still encrypted with descriptors), the new NoKeys status is only returned for unencrypted watchonly wallets. This allows any watchonly wallets that were previously encrypted to show the correct encryption status (they have encryption keys, and so should be indicated as being encrypted).

Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.
Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 4c49541

I couldn't reproduce the crash mentioned on IRC. On my machine (Ubuntu 21.10 VM) nothing happened after encrypting a wallet with private keys disabled.
But this option should be disabled for these wallets anyway.

However, this change does not prevent the user from creating a blank wallet (without disabling the private keys) and encrypting an empty wallet.

@achow101
Copy link
Member Author

I couldn't reproduce the crash mentioned on IRC. On my machine (Ubuntu 21.10 VM) nothing happened after encrypting a wallet with private keys disabled.

The crash is for descriptor wallet specifically. Legacy wallets will "encrypt" successfully.

However, this change does not prevent the user from creating a blank wallet (without disabling the private keys) and encrypting an empty wallet.

Yes, blank wallets are not watchonly because they can have private keys imported.

@katesalazar
Copy link
Contributor

katesalazar commented Jul 16, 2022 via email

@kristapsk
Copy link
Contributor

Concept ACK

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK, 1 nit

@@ -71,6 +71,7 @@ class WalletModel : public QObject

enum EncryptionStatus
{
NoKeys, // wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unsupported seems like it would fit better here

@luke-jr
Copy link
Member

luke-jr commented Jul 16, 2022

Note: This could be rebased as far back as the v0.5.0 tag (or at the latest for 0.21 compatibility, 831675c) to cleanly merge to older branches.

@hebasto
Copy link
Member

hebasto commented Jul 18, 2022

The issue reported on IRC:

12:01 <stevenroose> bitcoin-qt: wallet/scriptpubkeyman.cpp:1850: bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch&, const CKey&, const CPubKey&): Assertion `!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)' failed
12:01 <stevenroose> qt crashes when trying to encrypt a watchonly wallet
12:02 <stevenroose> it prompts for the passphrase and then hangs about 5 seconds and crashes

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look sane. But I cannot reproduce the initially reported issue to make sure it has been fixed.

FWIW, here is the getwalletinfo RPC output for my test watchonly descriptor wallet which I can encrypt with no crash:

{
  "walletname": "220718d-v22-DisablePK.1",
  "walletversion": 169900,
  "format": "sqlite",
  "balance": 0.00100000,
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 1,
  "keypoolsize": 1000,
  "keypoolsize_hd_internal": 0,
  "paytxfee": 0.00000000,
  "private_keys_enabled": false,
  "avoid_reuse": false,
  "scanning": false,
  "descriptors": true,
  "external_signer": false
}

@achow101

The crash is for descriptor wallet specifically.

Could you provide steps to reproduce the issue reliably?

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

  • I agree with the concept of this PR.
    • Since encrypting a wallet ⇒ encrypting its private keys. And since a watch-only wallet has none, encrypting it doesn’t make sense.
  • I was able to verify the code and confirm that encrypting a watch-only wallet in the GUI is disabled by this PR.

Screenshot:
Screenshot from 2022-07-18 19-05-59

  • However, I was also unable to reproduce the error on the master branch.

@achow101
Copy link
Member Author

Could you provide steps to reproduce the issue reliably?

Create a new descriptor wallet with only private keys diasbled. It must not be marked as a blank wallet. This requires using the RPC to create the wallet as the GUI will always set the blank wallet flag. Then encrypt that wallet using the GUI and it will crash.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4c49541, tested on Ubuntu 22.04.

@hebasto hebasto merged commit 6d8707b into bitcoin-core:master Jul 19, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 19, 2022
4c49541 Disallow encryption of watchonly wallets (Andrew Chow)

Pull request description:

  Watchonly wallets do not have any private keys to encrypt. It does not make sense to encrypt such wallets, so disable the option to encrypt them.

  This avoids an assertion that can be hit when encrypting watchonly descriptor wallets.

  As our current behavior allows for encrypting watchonly wallets (no crash with legacy, crash, but still encrypted with descriptors), the new `NoKeys` status is only returned for unencrypted watchonly wallets. This allows any watchonly wallets that were previously encrypted to show the correct encryption status (they have encryption keys, and so should be indicated as being encrypted).

ACKs for top commit:
  w0xlt:
    tACK bitcoin-core/gui@4c49541
  hebasto:
    ACK 4c49541, tested on Ubuntu 22.04.

Tree-SHA512: 054dba0a8c1343a0df17689508cd628a974555828955a3c8820bf020868b95a3df98c47253b0ffe2252765b020160bb76ea21647d76d59ba748b3b41c481f2ae
hebasto pushed a commit to hebasto/bitcoin that referenced this pull request Aug 12, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
@hebasto
Copy link
Member

hebasto commented Aug 12, 2022

Backported to the 23.x branch in bitcoin/bitcoin#25828.

fanquake added a commit to bitcoin/bitcoin that referenced this pull request Oct 2, 2022
31ca698 Disallow encryption of watchonly wallets (Andrew Chow)
da9578d build, qt: bump Qt5 version to 5.15.3 (Pavol Rusnak)

Pull request description:

  Backports:
  - ef20add from #24668 to address #24939 and bitcoin-core/gui#638
  - bitcoin-core/gui#631

  Guix builds on `x86_64`:
  ```
  773f3555a1c6179d35a7a0b3971ced8eaf5a5e4bef5c08313216509506fe618d  guix-build-31ca698f2017/output/aarch64-linux-gnu/SHA256SUMS.part
  ef3977b92daabffc2d153e15963a5703839bc04250d2784bc00dc1104112e79e  guix-build-31ca698f2017/output/aarch64-linux-gnu/bitcoin-31ca698f2017-aarch64-linux-gnu-debug.tar.gz
  65b2351c61d226a8b10fda36cc963fda1f5fb89ea6b463d7351fdcd67bd57c3e  guix-build-31ca698f2017/output/aarch64-linux-gnu/bitcoin-31ca698f2017-aarch64-linux-gnu.tar.gz
  41c3489300f81f714033aa45ca3a807c5005be0625ebf58234fd89f3cdc65a1d  guix-build-31ca698f2017/output/arm-linux-gnueabihf/SHA256SUMS.part
  45e6e4c9e2e35430c41bca6df36d5ed2f9a857934da46bfd920a499e03bddb61  guix-build-31ca698f2017/output/arm-linux-gnueabihf/bitcoin-31ca698f2017-arm-linux-gnueabihf-debug.tar.gz
  cf08e2a62c5a9bfdeaeee6ce69263dde8b56033aab650bb9ffafe8e9b9241519  guix-build-31ca698f2017/output/arm-linux-gnueabihf/bitcoin-31ca698f2017-arm-linux-gnueabihf.tar.gz
  7d1f3e185fbb6843a1b5c47f7ff2a4452aa4a1f533bd7171f7fc8a13e65fde53  guix-build-31ca698f2017/output/arm64-apple-darwin/SHA256SUMS.part
  6395ee2e17fd5a8891fc70d97e7d75810d677293b6ad8581334b2e289024210d  guix-build-31ca698f2017/output/arm64-apple-darwin/bitcoin-31ca698f2017-arm64-apple-darwin-unsigned.dmg
  1658de08323b366f0f39e9ed02d68072ee3bef2db2252235e71d8fd206b4e609  guix-build-31ca698f2017/output/arm64-apple-darwin/bitcoin-31ca698f2017-arm64-apple-darwin-unsigned.tar.gz
  c4fdf8d5563bdfc0390dec7adce2a0608f8e5b8d0d82b648ef38aed8ab72d996  guix-build-31ca698f2017/output/arm64-apple-darwin/bitcoin-31ca698f2017-arm64-apple-darwin.tar.gz
  709470d5d1a4a44022cd3e7b162c8cf6c492c6bb9996eb31f12a121351ad081f  guix-build-31ca698f2017/output/dist-archive/bitcoin-31ca698f2017.tar.gz
  6f809a8bdd10fc62143b5d265ea9c2eae37a1b18cf573d4a3743b2b026c0d038  guix-build-31ca698f2017/output/powerpc64-linux-gnu/SHA256SUMS.part
  ff2f87a29f7581d9ce1fccb8749f4473d03532de2194373de0fcdcd3bf0d380a  guix-build-31ca698f2017/output/powerpc64-linux-gnu/bitcoin-31ca698f2017-powerpc64-linux-gnu-debug.tar.gz
  ab5ec4203ff59c0d4885f5df1c91191a03a3c104ed8ca0e98e19f531914cd2ad  guix-build-31ca698f2017/output/powerpc64-linux-gnu/bitcoin-31ca698f2017-powerpc64-linux-gnu.tar.gz
  beb0ed7d9940718351301cb27dda1ae7891092c85664e2f9473e81c02479c951  guix-build-31ca698f2017/output/powerpc64le-linux-gnu/SHA256SUMS.part
  286121e5698b726abbfc24d972c00d9f16f6d841fab245980a376a51e8dd85bc  guix-build-31ca698f2017/output/powerpc64le-linux-gnu/bitcoin-31ca698f2017-powerpc64le-linux-gnu-debug.tar.gz
  04a12dfe6a036477d212877f301ee425dcf063abf0fd892b8fbc0497ee5612fc  guix-build-31ca698f2017/output/powerpc64le-linux-gnu/bitcoin-31ca698f2017-powerpc64le-linux-gnu.tar.gz
  d229041d43c40a49bbebcb5b0700c540456e058e0cb7be0d3ac414a80018e4f9  guix-build-31ca698f2017/output/riscv64-linux-gnu/SHA256SUMS.part
  981268b93caaf1c450f1f3cec4d70efd2b4779e17917a4ab424447743628519e  guix-build-31ca698f2017/output/riscv64-linux-gnu/bitcoin-31ca698f2017-riscv64-linux-gnu-debug.tar.gz
  acfef50476d9141ec29855216e60974d6307307a02784e7217942ee281d69c76  guix-build-31ca698f2017/output/riscv64-linux-gnu/bitcoin-31ca698f2017-riscv64-linux-gnu.tar.gz
  5482b0c34069be1e40a96a173f984c67eb983860a4f5f4d9d927638caf72eed5  guix-build-31ca698f2017/output/x86_64-apple-darwin/SHA256SUMS.part
  fe4847edbc3ad1c747663a67f0daf2ed8b38818d1d1960617d85c851b0dded2f  guix-build-31ca698f2017/output/x86_64-apple-darwin/bitcoin-31ca698f2017-x86_64-apple-darwin-unsigned.dmg
  2b1899804035508f90eef57e1f068120509e7680877c8ae6cb5cb5beed84607c  guix-build-31ca698f2017/output/x86_64-apple-darwin/bitcoin-31ca698f2017-x86_64-apple-darwin-unsigned.tar.gz
  7a82ab62d1db4141b13ac566bc985eca5fa1da982be29427dd74f7098059932c  guix-build-31ca698f2017/output/x86_64-apple-darwin/bitcoin-31ca698f2017-x86_64-apple-darwin.tar.gz
  3e943a6e11930ac1dcd7339bcdfbcf310b09f03d1e2544fce314e656b3552b7a  guix-build-31ca698f2017/output/x86_64-linux-gnu/SHA256SUMS.part
  0e0155ce76ffe8af19a74ecb74b813ce7ca4817bf3535a2b5813ae9e229804dc  guix-build-31ca698f2017/output/x86_64-linux-gnu/bitcoin-31ca698f2017-x86_64-linux-gnu-debug.tar.gz
  b66f9a25e963db98b3b8eed79e6d280d0ae7902d1f7e2cdee8481bacfc94ed96  guix-build-31ca698f2017/output/x86_64-linux-gnu/bitcoin-31ca698f2017-x86_64-linux-gnu.tar.gz
  bdc9cdd0ba739c3aba3d355f6e9ea88af99b09dd666cf40c7986212b355d2a09  guix-build-31ca698f2017/output/x86_64-w64-mingw32/SHA256SUMS.part
  815d4b70b257932a3e32e14d8bb53960efd5e71500e7349ac53d13303f4b5335  guix-build-31ca698f2017/output/x86_64-w64-mingw32/bitcoin-31ca698f2017-win64-debug.zip
  4b248df85b0b5de00631756839bc53e9e64c764b4da900afad34f871e2afe995  guix-build-31ca698f2017/output/x86_64-w64-mingw32/bitcoin-31ca698f2017-win64-setup-unsigned.exe
  b26008ed9fa0db1d32220087c2f0828788f0f9f784c981622f5e76c63c98fb9a  guix-build-31ca698f2017/output/x86_64-w64-mingw32/bitcoin-31ca698f2017-win64-unsigned.tar.gz
  4dd03a68ac2d742681d6b8c42b15e6f9d4ce46084ff18ebb0f1313109a867205  guix-build-31ca698f2017/output/x86_64-w64-mingw32/bitcoin-31ca698f2017-win64.zip
  ```

ACKs for top commit:
  jarolrod:
    ACK 31ca698

Tree-SHA512: 596c2979e070d3574c744ac89961ba157e9e01c2e1a3ce7d33cc369ad2cf1c2e16aa23209b382667dbd100545b5c17530771855b380eeb7345deebfa695a3be6
hebasto pushed a commit to hebasto/bitcoin that referenced this pull request Nov 21, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
@hebasto
Copy link
Member

hebasto commented Nov 21, 2022

Backported to the 22.x branch in bitcoin/bitcoin#26521.

fanquake added a commit to bitcoin/bitcoin that referenced this pull request Nov 22, 2022
272fa25 Fixes #26490 by preventing notifications (John Moffett)
7b7bbc1 Disallow encryption of watchonly wallets (Andrew Chow)

Pull request description:

  Backports:
  - bitcoin-core/gui#631
  - bitcoin-core/gui#680

ACKs for top commit:
  jarolrod:
    ACK 272fa25

Tree-SHA512: 4c285327464240ace3884d9653cc46d8e7b60b888f3b096ceb4fd5000d084ea8d97f1ef86ca1dea8dc7d3be8cdd2da19eece2b8c5b7351c5961b50b78fcd4c4d
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Nov 23, 2022
d9bd628 doc: add release notes for 22.1rc2 (fanquake)
6523107 doc: Update manual pages for 22.1rc2 (fanquake)
6af7af6 build: Bump version to 22.1rc2 (fanquake)

Pull request description:

  Bump the version to 22.1rc2.
  Regenerate the man pages.
  Add WIP 22.1 release notes.

  Changes since rc1:
  - bitcoin-core/gui#631
  - bitcoin-core/gui#680

ACKs for top commit:
  stickies-v:
    ACK [d9bd628](d9bd628)
  jarolrod:
    ACK d9bd628

Tree-SHA512: 70b1723fd5f77a93763ffc153b18c5d6c11c8294828406bd5e93daf9e8aac5e62306280ef6601508b4d22e1cce5136687afc826be6d159816071549849c40f91
psgreco pushed a commit to psgreco/elements that referenced this pull request Dec 7, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
(cherry picked from commit 7b7bbc1)
psgreco pushed a commit to psgreco/elements that referenced this pull request Dec 7, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
(cherry picked from commit 7b7bbc1)
psgreco pushed a commit to psgreco/elements that referenced this pull request Dec 7, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
(cherry picked from commit 7b7bbc1)
psgreco pushed a commit to psgreco/elements that referenced this pull request Dec 7, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
(cherry picked from commit 7b7bbc1)
vertiond pushed a commit to vertiond/vertcoin-core that referenced this pull request Dec 10, 2022
Watchonly wallets do not have any private keys to encrypt. It does not
make sense to encrypt such wallets, so disable the option to encrypt
them.

This avoids an assertion that can be hit when encrypting watchonly descriptor
wallets.

Github-Pull: bitcoin-core/gui#631
Rebased-From: 4c49541
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants