Skip to content

Review finding: descriptor ECDSA key encryption ignores write and erase failures #296

Closed

Description

@kiwidream

Summary

When descriptor ECDSA keys are encrypted, a failed write or a failed erase of the plaintext record is ignored. If either fails, the wallet reports itself encrypted while a plaintext private-key record stays in the file.

Observed

At 1.x.x b27130a7b9, found by reading the code during review of the #283 fix. Not reproduced.

  • WalletBatch::WriteCryptedDescriptorKey (src/wallet/walletdb.cpp:235-242) ignores the result of erasing the plaintext walletdescriptorkey record and returns true.
  • DescriptorScriptPubKeyMan::Encrypt ignores the result of WriteCryptedDescriptorKey itself (src/wallet/scriptpubkeyman.cpp:1089).
  • The fix for wallet: plaintext PQC keys already in encrypted v1.0.0 wallets are kept, rewritten on signing, and not reported #283 corrects the PQC equivalent: WriteCryptedDescriptorPQCKey returns its erase result, and Encrypt checks it, so a failure goes through EncryptWallet's abort path. The ECDSA path still needs the same change. Bitcoin Core v30.2 has the same code.

Impact

Low. It needs a statement-level SQLite failure that does not abort the transaction. Failures that roll back the whole transaction, such as a full disk or an I/O error, make the commit fail instead.

Suggested fix

Have WriteCryptedDescriptorKey return the erase result, and check it in Encrypt, the same way the #283 fix does for PQC keys.

Activity

  1. kiwidream commented on Nov 12, 2026

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #418 (e9f4499aba), which ships in v1.0.1: WalletBatch::WriteCryptedDescriptorKey now returns the result of erasing the plaintext record, and DescriptorScriptPubKeyMan::Encrypt fails when that call fails, so the failure goes through EncryptWallet's abort path, as it already did for PQC keys. Test: wallet_encryption_tests/FailedKeyRecordWriteOrEraseFailsEncryption.

    Closing by hand, because a merge into 1.x.x does not close issues automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions