What changed, and why it matters
This commit adds automatic memory clearing when Bitcoin private key objects are destroyed. It is a defensive hardening change, not a fix for an active vulnerability. The change reduces the chance that secret key material lingers in memory after use, but the commit itself does not claim to fix any known exploit.
No immediate action required. Treat as routine hardening. If relying on this for key security, ensure broader practices such as mlock, guarded heap allocations, and secure enclaves are also used, since Drop-based clearing is not sufficient alone.
Security signals we found
secret-key memory clearing on drop
removal of Copy prerequisite for Drop
defensive hardening against memory-resident key leakage
Evidence from the diff
The patch implements Drop for Keypair and PrivateKey in rust-bitcoin. On drop, it calls non_secure_erase() on the underlying secp256k1 secret data. This follows the earlier removal of Copy from these types, making it safe to implement Drop. It is a memory-hygiene improvement; non_secure_erase is best-effort and does not guarantee protection against all memory-exposure attacks (e.g., compiler optimizations, swapping, core dumps, hibernation).
Changed components
bitcoin/src/crypto/key.rsKeypairPrivateKeyInspect captured patch +8 / −0
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index f157ddcd..1e465474 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -124,6 +124,10 @@ mod encapsulate {
pub fn compressed(&self) -> bool { self.compressed }
}
+ impl Drop for Keypair {
+ fn drop(&mut self) { self.0.non_secure_erase(); }
+ }
+
/// An always-compressed Bitcoin ECDSA public key.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CompressedPublicKey(secp256k1::PublicKey);
@@ -168,6 +172,10 @@ mod encapsulate {
pub fn compressed(&self) -> bool { self.compressed }
}
+ impl Drop for PrivateKey {
+ fn drop(&mut self) { self.inner.non_secure_erase(); }
+ }
+
/// Tweaked BIP-0340 X-coord-only public key.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.