From 495a877af1132ef6966cc7faa03cf5e86631a810 Mon Sep 17 00:00:00 2001 From: lumat Date: Wed, 3 Jul 2019 15:05:47 +0200 Subject: [PATCH 1/2] Add support for new lyra2 variant --- src/common/crypto/Algorithm.cpp | 2 ++ src/common/net/Job.cpp | 2 +- src/common/net/Pool.cpp | 3 ++- src/common/xmrig.h | 3 ++- src/crypto/Lyra2.c | 17 ++++++++++------- src/crypto/Lyra2.h | 10 +++++++--- src/workers/CpuThread.cpp | 9 ++++++++- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index f9be1b9..4938989 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -55,6 +55,8 @@ struct AlgoData static AlgoData const algorithms[] = { { "lyra2-webchain", "lyra2-web", xmrig::LYRA2, xmrig::VARIANT_AUTO }, { "lyra2-webchain/1", "lyra2-web/1", xmrig::LYRA2, xmrig::VARIANT_0 }, + { "lyra2v2-webchain", "lyra2v2-web", xmrig::LYRA2v2, xmrig::VARIANT_AUTO }, + { "lyra2v2-webchain/1", "lyra2v2-web/1", xmrig::LYRA2v2, xmrig::VARIANT_0 }, }; diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 5127bca..a79da0b 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -166,7 +166,7 @@ bool Job::setTarget(const char *target) xmrig::Variant Job::variant() const { - if (m_algorithm.algo() == xmrig::LYRA2) { + if (m_algorithm.algo() == xmrig::LYRA2 || m_algorithm.algo() == xmrig::LYRA2v2) { return xmrig::VARIANT_0; } diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 60b247c..72ebd02 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -91,6 +91,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const { + return true; // TODO if (m_algorithms.empty()) { return true; } @@ -227,7 +228,7 @@ void Pool::adjust(xmrig::Algo algorithm) m_algorithm.setAlgo(algorithm); if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (algorithm == xmrig::LYRA2) { + if (algorithm == xmrig::LYRA2 || algorithm == xmrig::LYRA2v2) { m_algorithm.setVariant(xmrig::VARIANT_0); } } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index cbdd8d4..3917f7a 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -32,7 +32,8 @@ namespace xmrig enum Algo { INVALID_ALGO = -1, - LYRA2 /* LYRA2 (Webchain) */ + LYRA2, /* LYRA2 (Webchain) */ + LYRA2v2 /* LYRA2v2 (Webchain) */ }; diff --git a/src/crypto/Lyra2.c b/src/crypto/Lyra2.c index 8e3a776..d2b02ab 100644 --- a/src/crypto/Lyra2.c +++ b/src/crypto/Lyra2.c @@ -43,7 +43,7 @@ * * @return 0 if the key is generated correctly; -1 if there is an error (usually due to lack of memory for allocation) */ -int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen) +int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen, uint32_t tcost) { struct LYRA2_ctx *ctx = ctx2; //============================= Basic variables ============================// @@ -92,7 +92,7 @@ int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen) v64 = 0; // saltlen memcpy(ptrByte, &v64, sizeof(int64_t)); ptrByte += sizeof(uint64_t); - v64 = TCOST; + v64 = tcost; memcpy(ptrByte, &v64, sizeof(int64_t)); ptrByte += sizeof(uint64_t); v64 = NROWS; @@ -135,6 +135,9 @@ int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen) //updates the value of row* (deterministically picked during Setup)) rowa = (rowa + step) & (window - 1); + __builtin_prefetch((uint64_t*)(memMatrix(rowa))+0); + __builtin_prefetch((uint64_t*)(memMatrix(rowa))+4); + __builtin_prefetch((uint64_t*)(memMatrix(rowa))+8); //update prev: it now points to the last row ever computed prev = row; //updates row: goes to the next row to be computed @@ -142,17 +145,17 @@ int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen) //Checks if all rows in the window where visited. if (rowa == 0) { - step = window + gap; //changes the step: approximately doubles its value - window *= 2; //doubles the size of the re-visitation window - gap = -gap; //inverts the modifier to the step - } + step = window + gap; //changes the step: approximately doubles its value + window *= 2; //doubles the size of the re-visitation window + gap = -gap; //inverts the modifier to the step + } } while (row < NROWS); //==========================================================================/ //============================ Wandering Phase =============================// row = 0; //Resets the visitation to the first row of the memory matrix - for (tau = 1; tau <= TCOST; tau++) { + for (tau = 1; tau <= tcost; tau++) { //Step is approximately half the number of all rows of the memory matrix for an odd tau; otherwise, it is -1 step = (tau % 2 == 0) ? -1 : NROWS / 2 - 1; do { diff --git a/src/crypto/Lyra2.h b/src/crypto/Lyra2.h index cd5e255..278c3cb 100644 --- a/src/crypto/Lyra2.h +++ b/src/crypto/Lyra2.h @@ -43,7 +43,6 @@ struct LYRA2_ctx { #define NROWS 16384 #define NCOLS 4 -#define TCOST 4 #define LYRA2_MEMSIZE (BLOCK_LEN_INT64 * NCOLS * 8 * NROWS) #define memMatrix(x) (&ctx->wholeMatrix[x * BLOCK_LEN_INT64 * NCOLS]) @@ -51,14 +50,19 @@ struct LYRA2_ctx { #ifdef __cplusplus extern "C" { #endif - int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen); + int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen, uint32_t tcost); void *LYRA2_create(void); void LYRA2_destroy(void *c); static inline void lyra2_hash(const uint8_t *input, size_t size, uint8_t *output, void *ctx) { - LYRA2(ctx, output, 32, input, size); + LYRA2(ctx, output, 32, input, size, 4); + } + + static inline void lyra2v2_hash(const uint8_t *input, size_t size, uint8_t *output, void *ctx) + { + LYRA2(ctx, output, 32, input, size, 1); } #ifdef __cplusplus } diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 59b8d2b..cf68ff6 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -55,7 +55,14 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - return lyra2_hash; + switch (algorithm) { + case xmrig::LYRA2: + return lyra2_hash; + case xmrig::LYRA2v2: + return lyra2v2_hash; + default: + return lyra2_hash; + } } From 1363b7189988d9058f0c6bdebd9797270aa0e498 Mon Sep 17 00:00:00 2001 From: lumat Date: Fri, 5 Jul 2019 11:15:54 +0200 Subject: [PATCH 2/2] Change version to 2.8.0 --- src/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.h b/src/version.h index 93b0eae..a481329 100644 --- a/src/version.h +++ b/src/version.h @@ -28,15 +28,15 @@ #define APP_ID "webchain-miner" #define APP_NAME "webchain-miner" #define APP_DESC "webchain-miner CPU miner" -#define APP_VERSION "2.7.1" +#define APP_VERSION "2.8.0" #define APP_DOMAIN "webchain.network" #define APP_SITE "webchain.network" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com; Copyright (C) 2018-2019 Webchain project" #define APP_KIND "cpu" #define APP_VER_MAJOR 2 -#define APP_VER_MINOR 7 -#define APP_VER_PATCH 1 +#define APP_VER_MINOR 8 +#define APP_VER_PATCH 0 #define APP_VER_REVISION 0 #ifdef _MSC_VER