From 6a7c29be51d55e8568ceba27f43e0a331a2faeec Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 26 Nov 2024 21:51:23 +0400 Subject: [PATCH] Fix #482 suggested by @jeffro256 --- src/currency_core/basic_pow_helpers.cpp | 2 +- src/currency_core/basic_pow_helpers.h | 10 ++++++---- src/stratum/stratum_server.cpp | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/currency_core/basic_pow_helpers.cpp b/src/currency_core/basic_pow_helpers.cpp index b7ee80ca..d029ee19 100644 --- a/src/currency_core/basic_pow_helpers.cpp +++ b/src/currency_core/basic_pow_helpers.cpp @@ -81,7 +81,7 @@ namespace currency { blobdata bd = get_block_hashing_blob(b); - access_nonce_in_block_blob(bd) = 0; + set_nonce_to_blockblob(bd, 0); return crypto::cn_fast_hash(bd.data(), bd.size()); } //--------------------------------------------------------------- diff --git a/src/currency_core/basic_pow_helpers.h b/src/currency_core/basic_pow_helpers.h index 32ded457..e9cc6ca5 100644 --- a/src/currency_core/basic_pow_helpers.h +++ b/src/currency_core/basic_pow_helpers.h @@ -34,13 +34,15 @@ namespace currency void get_block_longhash(const block& b, crypto::hash& res); crypto::hash get_block_longhash(const block& b); - inline uint64_t& access_nonce_in_block_blob(blobdata& bd) + inline uint64_t get_nonce_from_blockblob(const blobdata& bd) { - return *reinterpret_cast(&bd[CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET]); + uint64_t nonce = 0; + std::memcpy(&nonce, &bd[CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET], sizeof(nonce)); + return nonce; } - inline const uint64_t& access_nonce_in_block_blob(const blobdata& bd) + inline void set_nonce_to_blockblob(blobdata& bd, const uint64_t nonce) { - return *reinterpret_cast(&bd[CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET]); + std::memcpy(&bd[CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET], &nonce, sizeof(nonce)); } } \ No newline at end of file diff --git a/src/stratum/stratum_server.cpp b/src/stratum/stratum_server.cpp index 4cfa686a..95729637 100644 --- a/src/stratum/stratum_server.cpp +++ b/src/stratum/stratum_server.cpp @@ -402,11 +402,11 @@ namespace #endif m_blockchain_last_block_id = top_block_id; - m_block_template_hash_blob = get_block_hashing_blob(m_block_template); - if (access_nonce_in_block_blob(m_block_template_hash_blob) != 0) + m_block_template_hash_blob = get_block_hashing_blob(m_block_template); + if (get_nonce_from_blockblob(m_block_template_hash_blob) != 0) { LOG_PRINT_RED("non-zero nonce in generated block template", LOG_LEVEL_0); - access_nonce_in_block_blob(m_block_template_hash_blob) = 0; + set_nonce_to_blockblob(m_block_template_hash_blob, 0); } m_prev_block_template_ethash = m_block_template_ethash; m_block_template_ethash = crypto::cn_fast_hash(m_block_template_hash_blob.data(), m_block_template_hash_blob.size());