aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/merge_mining.cpp
diff options
context:
space:
mode:
authorCrypto City <cryptocity@example.com>2023-11-12 11:33:20 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2023-11-30 17:01:52 +0000
commit53e632b435582193d4a708e2b7cf0bfc01ae821b (patch)
tree7a4b79bf488284a743124a0d25dd025e55d2dc61 /src/cryptonote_basic/merge_mining.cpp
parentMerge pull request #9050 (diff)
downloadmonero-53e632b435582193d4a708e2b7cf0bfc01ae821b.tar.xz
fix merge mining with more than one merge mined chain
reported by sech1
Diffstat (limited to 'src/cryptonote_basic/merge_mining.cpp')
-rw-r--r--src/cryptonote_basic/merge_mining.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/cryptonote_basic/merge_mining.cpp b/src/cryptonote_basic/merge_mining.cpp
index 0e649e095..3e26c00e3 100644
--- a/src/cryptonote_basic/merge_mining.cpp
+++ b/src/cryptonote_basic/merge_mining.cpp
@@ -71,21 +71,21 @@ uint32_t get_path_from_aux_slot(uint32_t slot, uint32_t n_aux_chains)
return path;
}
//---------------------------------------------------------------
-uint32_t encode_mm_depth(uint32_t n_aux_chains, uint32_t nonce)
+uint64_t encode_mm_depth(uint32_t n_aux_chains, uint32_t nonce)
{
CHECK_AND_ASSERT_THROW_MES(n_aux_chains > 0, "n_aux_chains is 0");
+ CHECK_AND_ASSERT_THROW_MES(n_aux_chains <= 256, "n_aux_chains is too large");
// how many bits to we need to representing n_aux_chains - 1
uint32_t n_bits = 1;
- while ((1u << n_bits) < n_aux_chains && n_bits < 16)
+ while ((1u << n_bits) < n_aux_chains)
++n_bits;
- CHECK_AND_ASSERT_THROW_MES(n_bits <= 16, "Way too many bits required");
- const uint32_t depth = (n_bits - 1) | ((n_aux_chains - 1) << 3) | (nonce << (3 + n_bits));
+ const uint64_t depth = (n_bits - 1) | ((n_aux_chains - 1) << 3) | (((uint64_t)nonce) << (3 + n_bits));
return depth;
}
//---------------------------------------------------------------
-bool decode_mm_depth(uint32_t depth, uint32_t &n_aux_chains, uint32_t &nonce)
+bool decode_mm_depth(uint64_t depth, uint32_t &n_aux_chains, uint32_t &nonce)
{
const uint32_t n_bits = 1 + (depth & 7);
n_aux_chains = 1 + (depth >> 3 & ((1 << n_bits) - 1));