wallet, sqlite: Enable secure_delete by default

bitcoin/bitcoin: PR #36796

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

2 suggestions

Earlier concerns neither republished nor resolved: 1 major finding. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · The compile-time default masks runtime secure_delete coverage

On depends builds, the new byte scans cannot distinguish the runtime secure_delete setting from SQLite's compile-time default, so they do not independently protect builds whose library defaults to OFF.

Location: src/wallet/sqlite.cpp:312 (head).

Details and suggested fix

depends/packages/sqlite.mk now defines SQLITE_SECURE_DELETE, so removing the SetPragma call would leave erasure enabled in those builds. Add a database unit test that sets PRAGMA secure_delete=OFF through m_db, calls Open() again on the file-backed database with no active transaction, and asserts that PRAGMA secure_delete returns 1. This exercises the runtime setting independently of the linked library's default while retaining the functional scans for end-to-end behavior. Whether a current CI job already uses an OFF-default library was not established.


Link

[suggestion] · Missing Python sqlite3 now skips all encryption coverage

The new skip_if_no_py_sqlite3() skips existing encryption, unlock, timeout and passphrase-change checks when Python's sqlite3 module is unavailable, although only the mkey inspection needs it.

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

Details and suggested fix

The helper raises SkipTest during setup, preventing every assertion in run_test() from running. The RPC checks and raw-file private-key scans do not require the module. Fetch mkey_data through the existing inspect_sqlite_db() helper and run the dependent byte-search assertion only when inspection returned a value. That helper warns and returns without inspection when the import fails, allowing the remaining coverage to run.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The post-encryption rewrite was introduced to remove recoverable plaintext private-key remnants from wallet files, not merely to remove the corresponding live database records.

The description of historical PR #635 explicitly says unencrypted private keys could remain in wallet.dat after encryption and prescribes completely rewriting that file. It also addresses temporary database files and cached plaintext being written back. Thus the motivating requirement was protection against recovery of residual plaintext after encryption, rather than successful encrypted-key storage alone.

Source 1