refactor: disable default std::hash for CTransactionRef
What changed, and why it matters
This is a defensive coding change in Bitcoin Core. It removes the default way to use CTransactionRef (a shared pointer to a transaction) as a key in hash tables, because the default behavior would compare memory addresses instead of transaction content. The change forces developers to explicitly choose a proper hash function, reducing the risk of subtle bugs in the future. It does not by itself fix a known active vulnerability.
No immediate action required. This is a safe refactor. Downstream maintainers should ensure any code that previously relied on std::hash<CTransactionRef> now explicitly uses CTransactionRefHash or another custom hasher, or it will fail to compile.
Security signals we found
Defensive compile-time enforcement of correct hashing semantics
Prevents accidental use of pointer-identity hash for transaction references
No runtime logic or consensus code changed
No CVE, bug report, or exploit referenced in commit
Evidence from the diff
The commit specializes std::hash
Changed components
src/primitives/transaction.hCTransactionRef type definitionAny future or existing code using std::hash<CTransactionRef>Inspect captured patch +12 / −0
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
index 34bb9571..3a7735e1 100644
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -403,4 +403,16 @@ struct CMutableTransaction
typedef std::shared_ptr<const CTransaction> CTransactionRef;
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
+namespace std {
+/** Disable default std::hash for CTransactionRef to prevent accidentally
+ * comparing by pointer. Use CTransactionRefHash or provide a custom
+ * hasher. */
+template <>
+struct hash<CTransactionRef> {
+ hash() = delete;
+ // Belt-and-suspenders, already implied by the above.
+ size_t operator()(const CTransactionRef&) const = delete;
+};
+} // namespace std
+
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H
Why this scored 29/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.