Skip to content

Commit

Permalink
Merge pull request #14 from webchain-network/lyra2v2
Browse files Browse the repository at this point in the history
Add support for new lyra2 variant
  • Loading branch information
lukaszmatczak authored Jul 5, 2019
2 parents bb74f51 + 1363b71 commit 8483bbd
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/common/crypto/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};


Expand Down
2 changes: 1 addition & 1 deletion src/common/net/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/common/net/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/xmrig.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace xmrig

enum Algo {
INVALID_ALGO = -1,
LYRA2 /* LYRA2 (Webchain) */
LYRA2, /* LYRA2 (Webchain) */
LYRA2v2 /* LYRA2v2 (Webchain) */
};


Expand Down
17 changes: 10 additions & 7 deletions src/crypto/Lyra2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ============================//
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -135,24 +135,27 @@ 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
row++;

//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 {
Expand Down
10 changes: 7 additions & 3 deletions src/crypto/Lyra2.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,26 @@ 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])

#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
}
Expand Down
6 changes: 3 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/workers/CpuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down

0 comments on commit 8483bbd

Please sign in to comment.