unit_tests: remove addressof overload for crypto::secret_key
What changed, and why it matters
This is a small cleanup in Monero's test code. It removes a custom helper called addressof that was used only in unit tests and replaces it with the standard C++ std::addressof. The change also adds a compile-time check that the tested types have a single, unambiguous memory layout. There is no direct evidence this fixes an active security bug in production code, but it removes a potentially risky custom overload near secret key handling and makes the test stricter.
Treat as a low-risk test-hardening change. Reviewers may want to confirm the removed overload was not used elsewhere and that unwrap(unwrap(k)) did not hide any undefined behavior that could affect other tests. No urgent action is required.
Security signals we found
Custom addressof overload for secret_key removed
Standard std::addressof used instead
static_assert for unique object representations added
Change limited to unit test file
No production code or consensus logic modified
Evidence from the diff
The commit modifies tests/unit_tests/crypto.cpp. It deletes a namespace-scope overload of addressof(T&) and a specialization for crypto::secret_key that forwarded through unwrap(unwrap(k)). It then uses std::addressof from
Changed components
tests/unit_tests/crypto.cppInspect captured patch +4 / −6
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index 1c4841b..42500dd 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2024, The Monero Project
+// Copyright (c) 2017-2026, The Monero Project
//
// All rights reserved.
//
@@ -31,13 +31,13 @@
#include <memory>
#include <sstream>
#include <string>
+#include <type_traits>
extern "C"
{
#include "crypto/crypto-ops.h"
}
#include "crypto/generators.h"
-#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "cryptonote_basic/merge_mining.h"
#include "ringct/rctOps.h"
#include "ringct/rctTypes.h"
@@ -55,9 +55,6 @@ namespace
"8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94"
"6c7251d54154cfa92c173a0dd39c1f948b655970153799af2aeadc9ff1add0ea";
- template<typename T> void *addressof(T &t) { return &t; }
- template<> void *addressof(crypto::secret_key &k) { return addressof(unwrap(unwrap(k))); }
-
template<typename T>
bool is_formatted()
{
@@ -66,7 +63,8 @@ namespace
static_assert(alignof(T) == 1, "T must have 1 byte alignment");
static_assert(sizeof(T) <= sizeof(source), "T is too large for source");
static_assert(sizeof(T) * 2 <= sizeof(expected), "T is too large for destination");
- std::memcpy(addressof(value), source, sizeof(T));
+ static_assert(std::has_unique_object_representations_v<T>);
+ std::memcpy(std::addressof(value), source, sizeof(T));
std::stringstream out;
out << "BEGIN" << value << "END";
Why this scored 17/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.