Review report

bitcoin/bitcoin: PR #36796

1 major finding · 1 minor finding · 1 suggestion

Findings

Link

[major] · Encryption no longer scrubs pre-upgrade plaintext key residue

Removing the encryption-time VACUUM can leave pre-upgrade plaintext private-key residue readable in an encrypted wallet.dat and its later backups.

Location: src/wallet/wallet.cpp:900 (base).

Details and suggested fix

Consider an unencrypted legacy wallet migrated before this PR using SQLite with secure_delete disabled, as in depends builds. Migration copies the legacy records into SQLite, then deletes the legacy key records while retaining their keys in descriptors. Those deletions can leave plaintext in free space. Enabling secure_delete on the next open protects subsequent deletions, but does not scrub that existing residue. EncryptWallet now encrypts live descriptor keys without the previous whole-file VACUUM, so anyone obtaining wallet.dat or a later page-based backup may recover surviving plaintext without the passphrase. No real migrated wallet was examined; survival depends on subsequent page reuse and defragmentation. This is separate from the migration's plaintext .legacy.bak file, which the user may already have deleted. Wallets created or migrated with this build receive secure_delete before those deletions. Retain the one-time VACUUM at the end of initial encryption in addition to the pragma. Add a regression fixture that creates deleted private-key residue with secure_delete off, verifies that the bytes remain before encryption, and checks their removal afterward; the fresh-wallet checks do not exercise this state.


Link

[minor] · Misspelled secure-delete define leaves the depends default unchanged

The missing leading S in QLITE_SECURE_DELETE makes the depends build change ineffective, although the runtime pragma still protects wallet connections.

Location: depends/packages/sqlite.mk:16 (head).

Details and suggested fix

SQLite recognizes SQLITE_SECURE_DELETE, not QLITE_SECURE_DELETE. The depends machinery passes this definition unchanged through CPPFLAGS, so the added flag does not enable the intended compile-time default. SQLiteDatabase::Open separately sets PRAGMA secure_delete = ON, including after connection recovery, which limits the practical impact. Change the flag to -DSQLITE_SECURE_DELETE to establish the intended package default.


Optional improvements

Link

[suggestion] · The sqlite3 dependency skips unrelated wallet encryption coverage

Without Python's sqlite3 module, wallet_encryption.py now skips all checks even though only the mkey lookup needs that module.

Location: test/functional/wallet_encryption.py:34 (head).

Details and suggested fix

The new top-level skip removes existing timeout, wrong-passphrase, walletlock, and passphrase-change coverage in environments without Python sqlite3. It also skips the new plaintext-key scans, which only read wallet.dat as bytes. Use inspect_sqlite_db for the mkey lookup, retaining its row assertion inside the callback, and condition only the later rotated-mkey scan on receiving a value. The helper already logs a warning and returns None when the module is unavailable, so the remaining checks can continue running.


Coverage details