diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index f3f4c2f4f..fbfd02311 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -57,6 +57,7 @@ static AlgoData const algorithms[] = { { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, + { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -68,6 +69,8 @@ static AlgoData const algorithms[] = { # ifndef XMRIG_NO_SUMO { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, # endif }; @@ -89,7 +92,9 @@ static const char *variants[] = { "0", "1", "ipbc", - "xtl" + "xtl", + "msr", + "xhv" }; @@ -145,11 +150,6 @@ void xmrig::Algorithm::parseAlgorithm(const char *algo) void xmrig::Algorithm::parseVariant(const char *variant) { - if (m_algo == CRYPTONIGHT_HEAVY) { - m_variant = VARIANT_0; - return; - } - m_variant = VARIANT_AUTO; for (size_t i = 0; i < ARRAY_SIZE(variants); i++) { @@ -163,7 +163,7 @@ void xmrig::Algorithm::parseVariant(const char *variant) void xmrig::Algorithm::parseVariant(int variant) { - if (variant >= VARIANT_AUTO && variant <= VARIANT_XTL) { + if (variant >= VARIANT_AUTO && variant < VARIANT_MAX) { m_variant = static_cast(variant); } else { @@ -175,10 +175,6 @@ void xmrig::Algorithm::parseVariant(int variant) void xmrig::Algorithm::setAlgo(Algo algo) { m_algo = algo; - - if (m_algo == CRYPTONIGHT_HEAVY) { - m_variant = VARIANT_0; - } } diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 81c3b8f8d..9a7ede8e9 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -173,12 +173,12 @@ xmrig::Variant Job::variant() const return xmrig::VARIANT_1; } - if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (m_algorithm.algo() == xmrig::CRYPTONIGHT) { - return xmrig::VARIANT_1; - } + if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] < 7) { + return xmrig::VARIANT_1; + } - return (m_blob[0] > 6 ? xmrig::VARIANT_1 : xmrig::VARIANT_0); + if (m_algorithm.variant() == xmrig::VARIANT_AUTO && m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { + return xmrig::VARIANT_1; } return m_algorithm.variant(); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index d59435453..006d76a13 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -321,12 +321,12 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_IPBC); - addVariant(xmrig::VARIANT_AUTO); - } + addVariant(xmrig::VARIANT_1); + addVariant(xmrig::VARIANT_0); + addVariant(xmrig::VARIANT_XTL); + addVariant(xmrig::VARIANT_IPBC); + addVariant(xmrig::VARIANT_MSR); + addVariant(xmrig::VARIANT_XHV); + addVariant(xmrig::VARIANT_AUTO); # endif } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 43a2a2525..170f4832c 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -61,8 +61,11 @@ enum Variant { VARIANT_AUTO = -1, // Autodetect VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 - VARIANT_IPBC = 2, // CryptoNight Lite variant 1 with XOR (IPBC only) - VARIANT_XTL = 3 // CryptoNight variant 1 (Stellite only) + VARIANT_IPBC = 2, // Modified CryptoNight Lite variant 1 with XOR (IPBC/TUBE only) + VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) + VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) + VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) + VARIANT_MAX }; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 7e6627fd6..73f3e9581 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -38,6 +38,7 @@ namespace xmrig constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; +constexpr const uint32_t CRYPTONIGHT_MSR_ITER = 0x40000; constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0; @@ -102,18 +103,24 @@ inline uint32_t cn_select_mask(Algo algorithm) } -template inline constexpr uint32_t cn_select_iter() { return 0; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template inline constexpr uint32_t cn_select_iter() { return 0; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_MSR_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } -inline uint32_t cn_select_iter(Algo algorithm) +inline uint32_t cn_select_iter(Algo algorithm, Variant variant) { switch(algorithm) { case CRYPTONIGHT: - return CRYPTONIGHT_ITER; + return variant == VARIANT_MSR ? CRYPTONIGHT_MSR_ITER : CRYPTONIGHT_ITER; case CRYPTONIGHT_LITE: return CRYPTONIGHT_LITE_ITER; diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index bf6013e8c..8d8fe4551 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -99,6 +99,21 @@ const static uint8_t test_output_xtl[160] = { }; +// Masari (MSR) +const static uint8_t test_output_msr[160] = { + 0x3C, 0x7A, 0x61, 0x08, 0x4C, 0x5E, 0xB8, 0x65, 0xB4, 0x98, 0xAB, 0x2F, 0x5A, 0x1A, 0xC5, 0x2C, + 0x49, 0xC1, 0x77, 0xC2, 0xD0, 0x13, 0x34, 0x42, 0xD6, 0x5E, 0xD5, 0x14, 0x33, 0x5C, 0x82, 0xC5, + 0x69, 0xDF, 0x38, 0x51, 0x1B, 0xB3, 0xEB, 0x7D, 0xE7, 0x6B, 0x08, 0x8E, 0xB6, 0x7E, 0xB7, 0x1C, + 0x5F, 0x3C, 0x81, 0xC9, 0xF7, 0xCE, 0xAE, 0x28, 0xC0, 0xFE, 0xEB, 0xBA, 0x0B, 0x40, 0x38, 0x1D, + 0x44, 0xD0, 0xD5, 0xD3, 0x98, 0x1F, 0xA3, 0x0E, 0xE9, 0x89, 0x1A, 0xD7, 0x88, 0xCC, 0x25, 0x76, + 0x9C, 0xFF, 0x4D, 0x7F, 0x9C, 0xCF, 0x48, 0x07, 0x91, 0xF9, 0x82, 0xF5, 0x4C, 0xE9, 0xBD, 0x82, + 0x36, 0x36, 0x64, 0x14, 0xED, 0xB8, 0x54, 0xEE, 0x22, 0xA1, 0x66, 0xA3, 0x87, 0x10, 0x76, 0x1F, + 0x5A, 0xCD, 0x4C, 0x31, 0x4C, 0xBA, 0x41, 0xD2, 0xDB, 0x6C, 0x31, 0x2E, 0x7A, 0x64, 0x15, 0xFF, + 0xA6, 0xD9, 0xB9, 0x7D, 0x1C, 0x3C, 0x98, 0xDD, 0x16, 0xE6, 0xD3, 0xAA, 0xEF, 0xB6, 0xB3, 0x53, + 0x74, 0xD1, 0xAC, 0x5C, 0x04, 0x26, 0x7D, 0x71, 0xDE, 0xAB, 0x66, 0x28, 0x91, 0x3A, 0x6F, 0x4F +}; + + #ifndef XMRIG_NO_AEON const static uint8_t test_output_v0_lite[160] = { 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 66bcf8b54..3aa2a927b 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -403,11 +403,11 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) } -template +template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -493,11 +493,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -700,11 +700,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -790,11 +790,11 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -896,11 +896,11 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size } -template +template inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index e42139c08..926a9ba3b 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -62,9 +62,15 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - assert(variant == VARIANT_0 || variant == VARIANT_1 || variant == VARIANT_IPBC || variant == VARIANT_XTL); + assert(variant == VARIANT_0 || + variant == VARIANT_1 || + variant == VARIANT_IPBC || + variant == VARIANT_XTL || + variant == VARIANT_MSR || + variant == VARIANT_XHV + ); - static const cn_hash_fun func_table[90] = { + static const cn_hash_fun func_table[180] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -87,7 +93,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC cryptonight_single_hash, cryptonight_double_hash, @@ -100,6 +106,19 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -134,12 +153,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif # ifndef XMRIG_NO_SUMO @@ -153,18 +176,33 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_triple_hash, cryptonight_quad_hash, cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif }; -# ifndef XMRIG_NO_SUMO - if (algorithm == CRYPTONIGHT_HEAVY) { - variant = VARIANT_0; - } -# endif - - const size_t index = 40 * algorithm + 10 * variant + av - 1; + const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1; # ifndef NDEBUG cn_hash_fun func = func_table[index]; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index c0f884466..f3acf7f8a 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -50,36 +50,23 @@ MultiWorker::~MultiWorker() template bool MultiWorker::selfTest() { - if (m_thread->fn(xmrig::VARIANT_0) == nullptr) { - return false; - } - - m_thread->fn(xmrig::VARIANT_0)(test_input, 76, m_hash, m_ctx); - - if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, sizeof m_hash) == 0) { - m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); - if (memcmp(m_hash, test_output_v1, sizeof m_hash) != 0) { - return false; - } - - m_thread->fn(xmrig::VARIANT_XTL)(test_input, 76, m_hash, m_ctx); - return memcmp(m_hash, test_output_xtl, sizeof m_hash) == 0; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT) { + return verify(xmrig::VARIANT_0, test_output_v0) && + verify(xmrig::VARIANT_1, test_output_v1) && + verify(xmrig::VARIANT_XTL, test_output_xtl) && + verify(xmrig::VARIANT_MSR, test_output_msr); } # ifndef XMRIG_NO_AEON - if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_hash, test_output_v0_lite, sizeof m_hash) == 0) { - m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); - if (memcmp(m_hash, test_output_v1_lite, sizeof m_hash) != 0) { - return false; - } - - m_thread->fn(xmrig::VARIANT_IPBC)(test_input, 76, m_hash, m_ctx); - return memcmp(m_hash, test_output_ipbc_lite, sizeof m_hash) == 0; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE) { + return verify(xmrig::VARIANT_0, test_output_v0_lite) && + verify(xmrig::VARIANT_1, test_output_v1_lite) && + verify(xmrig::VARIANT_IPBC, test_output_ipbc_lite); } # endif # ifndef XMRIG_NO_SUMO - return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, sizeof m_hash) == 0; + return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && verify(xmrig::VARIANT_0, test_output_heavy); # else return false; # endif @@ -140,6 +127,20 @@ bool MultiWorker::resume(const Job &job) } +template +bool MultiWorker::verify(xmrig::Variant variant, const uint8_t *referenceValue) +{ + + xmrig::CpuThread::cn_hash_fun func = m_thread->fn(variant); + if (!func) { + return false; + } + + func(test_input, 76, m_hash, m_ctx); + return memcmp(m_hash, referenceValue, sizeof m_hash) == 0; +} + + template void MultiWorker::consumeJob() { diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index d89bbb335..d4a6910e7 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -48,6 +48,7 @@ protected: private: bool resume(const Job &job); + bool verify(xmrig::Variant variant, const uint8_t *referenceValue); void consumeJob(); void save(const Job &job);