Skip to content

Commit 64d5655

Browse files
committed
build: fix build with Boost 1.85 and remove instances of viewkey logging
1. Use `std::is_standard_layout` and `std::is_trivially_copyable` instead of `std::is_pod` for KV byte-wise serialization, which fixes compile issue for Boost UUIDs 2. Change requirements for epee byte spans 3. Removed reimplementation of `std::hash` for `boost::uuids::uuid 4. Removed `<<` operator overload for `crypto::secret_key` 5. Removed instances in code where private view key was dumped to the log in plaintext
1 parent a1dc85c commit 64d5655

File tree

18 files changed

+39
-54
lines changed

18 files changed

+39
-54
lines changed

contrib/epee/include/serialization/keyvalue_serialization.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,18 @@ public: \
9898
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
9999
epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
100100

101-
#define KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, val_name) \
102-
static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
103-
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name)
101+
#define KV_SERIALIZE_VAL_POD_AS_BLOB_N(variable, val_name) \
102+
static_assert(std::is_trivially_copyable_v<decltype(this_ref.variable)>, "t_type must be a trivially copyable type."); \
103+
static_assert(std::is_standard_layout_v<decltype(this_ref.variable)>, "t_type must be a standard layout type."); \
104+
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name)
104105

105-
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, val_name, default_value) \
106+
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(variable, val_name, default_value) \
106107
do { \
107-
static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
108-
bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
108+
static_assert(std::is_trivially_copyable_v<decltype(this_ref.variable)>, "t_type must be a trivially copyable type."); \
109+
static_assert(std::is_standard_layout_v<decltype(this_ref.variable)>, "t_type must be a standard layout type."); \
110+
bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name) \
109111
if (!ret) \
110-
epee::serialize_default(this_ref.varialble, default_value); \
112+
epee::serialize_default(this_ref.variable, default_value); \
111113
} while(0);
112114

113115
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, val_name) \
@@ -118,7 +120,7 @@ public: \
118120
#define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
119121
#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
120122
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(varialble, def) KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, #varialble, def)
121-
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_pod compile time check
123+
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_trivially_copyable and is_standard_layout compile time check
122124
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
123125
#define KV_SERIALIZE_OPT(variable,default_value) KV_SERIALIZE_OPT_N(variable, #variable, default_value)
124126

contrib/epee/include/span.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,11 @@ namespace epee
133133
return {src.data(), src.size()};
134134
}
135135

136-
template<typename T>
137-
constexpr bool has_padding() noexcept
138-
{
139-
return !std::is_standard_layout<T>() || alignof(T) != 1;
140-
}
141-
142136
//! \return Cast data from `src` as `span<const std::uint8_t>`.
143137
template<typename T>
144138
span<const std::uint8_t> to_byte_span(const span<const T> src) noexcept
145139
{
146-
static_assert(!has_padding<T>(), "source type may have padding");
140+
static_assert(!std::is_empty<T>(), "empty value types will not work -> sizeof == 1");
147141
return {reinterpret_cast<const std::uint8_t*>(src.data()), src.size_bytes()};
148142
}
149143

@@ -153,7 +147,7 @@ namespace epee
153147
{
154148
using value_type = typename T::value_type;
155149
static_assert(!std::is_empty<value_type>(), "empty value types will not work -> sizeof == 1");
156-
static_assert(!has_padding<value_type>(), "source value type may have padding");
150+
static_assert(std::is_trivially_copyable_v<value_type>, "source type may not be trivially copyable");
157151
return {reinterpret_cast<std::uint8_t*>(src.data()), src.size() * sizeof(value_type)};
158152
}
159153

@@ -162,7 +156,6 @@ namespace epee
162156
span<const std::uint8_t> as_byte_span(const T& src) noexcept
163157
{
164158
static_assert(!std::is_empty<T>(), "empty types will not work -> sizeof == 1");
165-
static_assert(!has_padding<T>(), "source type may have padding");
166159
return {reinterpret_cast<const std::uint8_t*>(std::addressof(src)), sizeof(T)};
167160
}
168161

@@ -171,7 +164,7 @@ namespace epee
171164
span<std::uint8_t> as_mut_byte_span(T& src) noexcept
172165
{
173166
static_assert(!std::is_empty<T>(), "empty types will not work -> sizeof == 1");
174-
static_assert(!has_padding<T>(), "source type may have padding");
167+
static_assert(std::is_trivially_copyable_v<T>, "source type may not be trivially copyable");
175168
return {reinterpret_cast<std::uint8_t*>(std::addressof(src)), sizeof(T)};
176169
}
177170

contrib/epee/include/string_tools.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ namespace string_tools
8989
std::string pod_to_hex(const t_pod_type& s)
9090
{
9191
static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
92+
static_assert(std::has_unique_object_representations_v<t_pod_type>, "type may have padding");
9293
return to_hex::string(as_byte_span(s));
9394
}
9495
//----------------------------------------------------------------------------
9596
template<class t_pod_type>
9697
bool hex_to_pod(const boost::string_ref hex_str, t_pod_type& s)
9798
{
9899
static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
100+
static_assert(std::has_unique_object_representations_v<t_pod_type>, "type may have padding");
99101
return from_hex::to_buffer(as_mut_byte_span(s), hex_str);
100102
}
101103
//----------------------------------------------------------------------------

src/crypto/crypto.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,6 @@ namespace crypto {
314314
inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) {
315315
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
316316
}
317-
inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) {
318-
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
319-
}
320317
inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) {
321318
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
322319
}

src/cryptonote_basic/cryptonote_format_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ namespace cryptonote
292292
bool r = hwdev.generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation);
293293
if (!r)
294294
{
295-
MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")");
295+
MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", <viewkey>)");
296296
memcpy(&recv_derivation, rct::identity().bytes, sizeof(recv_derivation));
297297
}
298298

@@ -303,7 +303,7 @@ namespace cryptonote
303303
r = hwdev.generate_key_derivation(additional_tx_public_keys[i], ack.m_view_secret_key, additional_recv_derivation);
304304
if (!r)
305305
{
306-
MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", " << ack.m_view_secret_key << ")");
306+
MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", <viewkey>)");
307307
}
308308
else
309309
{

src/cryptonote_core/cryptonote_tx_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace cryptonote
144144
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
145145
crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key);
146146
bool r = crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation);
147-
CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << txkey.sec << ")");
147+
CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << rct::sk2rct(txkey.sec) << ")");
148148

149149
r = crypto::derive_public_key(derivation, no, miner_address.m_spend_public_key, out_eph_public_key);
150150
CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << no << ", "<< miner_address.m_spend_public_key << ")");
@@ -484,7 +484,7 @@ namespace cryptonote
484484
crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data());
485485
ss_ring_s << "signatures:" << ENDL;
486486
std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;});
487-
ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output << ENDL;
487+
ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << rct::sk2rct(in_contexts[i].in_ephemeral.sec) << ENDL << "real_output: " << src_entr.real_output << ENDL;
488488
i++;
489489
}
490490

src/cryptonote_protocol/block_queue.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@
4040
#undef MONERO_DEFAULT_LOG_CATEGORY
4141
#define MONERO_DEFAULT_LOG_CATEGORY "cn.block_queue"
4242

43-
namespace std {
44-
static_assert(sizeof(size_t) <= sizeof(boost::uuids::uuid), "boost::uuids::uuid too small");
45-
template<> struct hash<boost::uuids::uuid> {
46-
std::size_t operator()(const boost::uuids::uuid &_v) const {
47-
return reinterpret_cast<const std::size_t &>(_v);
48-
}
49-
};
50-
}
51-
5243
namespace cryptonote
5344
{
5445

@@ -472,7 +463,7 @@ bool block_queue::has_spans(const boost::uuids::uuid &connection_id) const
472463
float block_queue::get_speed(const boost::uuids::uuid &connection_id) const
473464
{
474465
boost::unique_lock<boost::recursive_mutex> lock(mutex);
475-
std::unordered_map<boost::uuids::uuid, float> speeds;
466+
std::unordered_map<boost::uuids::uuid, float, boost::hash<boost::uuids::uuid>> speeds;
476467
for (const auto &span: blocks)
477468
{
478469
if (span.blocks.empty())

src/device/device_default.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ namespace hw {
317317
{
318318
// sending change to yourself; derivation = a*R
319319
r = generate_key_derivation(txkey_pub, sender_account_keys.m_view_secret_key, derivation);
320-
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", " << sender_account_keys.m_view_secret_key << ")");
320+
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", <viewkey>)");
321321
}
322322
else
323323
{
324324
// sending to the recipient; derivation = r*A (or s*C in the subaddress scheme)
325325
r = generate_key_derivation(dst_entr.addr.m_view_public_key, dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key, derivation);
326-
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << (dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key) << ")");
326+
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << rct::sk2rct(dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key) << ")");
327327
}
328328

329329
if (need_additional_txkeys)

src/lmdb/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ namespace lmdb
127127
/*!
128128
A LMDB comparison function that uses `std::memcmp`.
129129
130-
\toaram T is `!epee::has_padding`
130+
\toaram T has standard layout and an alignment of 1
131131
\tparam offset to `T` within the value.
132132
133133
\return The result of `std::memcmp` over the value.
134134
*/
135135
template<typename T, std::size_t offset = 0>
136136
inline int compare(MDB_val const* left, MDB_val const* right) noexcept
137137
{
138-
static_assert(!epee::has_padding<T>(), "memcmp will not work");
138+
static_assert(std::is_standard_layout_v<T> && alignof(T) == 1, "memcmp will not work");
139139
if (!left || !right || left->mv_size < sizeof(T) + offset || right->mv_size < sizeof(T) + offset)
140140
{
141141
assert("invalid use of custom comparison" == 0);

src/simplewallet/simplewallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7872,9 +7872,9 @@ bool simple_wallet::submit_transfer(const std::vector<std::string> &args_)
78727872
std::string get_tx_key_stream(crypto::secret_key tx_key, std::vector<crypto::secret_key> additional_tx_keys)
78737873
{
78747874
ostringstream oss;
7875-
oss << epee::string_tools::pod_to_hex(tx_key);
7875+
oss << epee::string_tools::pod_to_hex(rct::sk2rct(tx_key));
78767876
for (size_t i = 0; i < additional_tx_keys.size(); ++i)
7877-
oss << epee::string_tools::pod_to_hex(additional_tx_keys[i]);
7877+
oss << epee::string_tools::pod_to_hex(rct::sk2rct(additional_tx_keys[i]));
78787878
return oss.str();
78797879
}
78807880

0 commit comments

Comments
 (0)