diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e2e65228..b00b1f1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v2.5.0 +- [#434](https://github.com/xmrig/xmrig/issues/434) **Added support for Monero v7 PoW, scheduled on March 28.** +- Added full IPv6 support. +- Added protocol extension, when use the miner with xmrig-proxy 2.5+ no more need manually specify `nicehash` option. +- [#123](https://github.com/xmrig/xmrig-proxy/issues/123) Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy was parsed incorrectly. +- [#428](https://github.com/xmrig/xmrig/issues/428) Fixed regression (version 2.4.5 affected) with CPU cache size detection. + # v2.4.5 - [#324](https://github.com/xmrig/xmrig/pull/324) Fixed build without libmicrohttpd (CMake cache issue). - [#341](https://github.com/xmrig/xmrig/issues/341) Fixed wrong exit code and added command line option `--dry-run`. diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e1673eac..47a4d7419 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,8 +29,8 @@ set(HEADERS src/log/Log.h src/Mem.h src/net/Client.h + src/net/Id.h src/net/Job.h - src/net/JobId.h src/net/JobResult.h src/net/Network.h src/net/strategies/DonateStrategy.h @@ -48,6 +48,7 @@ set(HEADERS src/workers/SingleWorker.h src/workers/Worker.h src/workers/Workers.h + src/xmrig.h ) set(HEADERS_CRYPTO @@ -57,6 +58,7 @@ set(HEADERS_CRYPTO src/crypto/c_keccak.h src/crypto/c_skein.h src/crypto/CryptoNight.h + src/crypto/CryptoNight_monero.h src/crypto/CryptoNight_test.h src/crypto/groestl_tables.h src/crypto/hash.h diff --git a/cmake/FindMHD.cmake b/cmake/FindMHD.cmake index 8505b337a..a20ecfec2 100644 --- a/cmake/FindMHD.cmake +++ b/cmake/FindMHD.cmake @@ -8,12 +8,16 @@ find_path( MHD_INCLUDE_DIR NAMES microhttpd.h + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "include" DOC "microhttpd include dir" ) find_library( MHD_LIBRARY - NAMES microhttpd microhttpd-10 libmicrohttpd libmicrohttpd-dll + NAMES microhttpd libmicrohttpd + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "lib" DOC "microhttpd library" ) @@ -34,6 +38,6 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(mhd DEFAULT_MSG MHD_INCLUDE_DIR MHD_LIBRARY) +find_package_handle_standard_args(MHD DEFAULT_MSG MHD_LIBRARY MHD_INCLUDE_DIR) mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY) diff --git a/cmake/FindUV.cmake b/cmake/FindUV.cmake index e3c22d28d..7906633f1 100644 --- a/cmake/FindUV.cmake +++ b/cmake/FindUV.cmake @@ -1,5 +1,16 @@ -find_path(UV_INCLUDE_DIR NAMES uv.h) -find_library(UV_LIBRARY NAMES uv libuv) +find_path( + UV_INCLUDE_DIR + NAMES uv.h + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "include" +) + +find_library( + UV_LIBRARY + NAMES libuv.a uv libuv + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "lib" +) set(UV_LIBRARIES ${UV_LIBRARY}) set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR}) diff --git a/src/Cpu_stub.cpp b/src/Cpu_stub.cpp index 0b9196eea..87d9de755 100644 --- a/src/Cpu_stub.cpp +++ b/src/Cpu_stub.cpp @@ -24,13 +24,18 @@ #ifdef _MSC_VER # include - -# define bit_AES (1 << 25) -# define bit_BMI2 (1 << 8) #else # include #endif +#ifndef bit_AES +# define bit_AES (1 << 25) +#endif + +#ifndef bit_BMI2 +# define bit_BMI2 (1 << 8) +#endif + #include @@ -87,7 +92,7 @@ static inline bool has_aes_ni() int cpu_info[4] = { 0 }; cpuid(PROCESSOR_INFO, cpu_info); - return cpu_info[ECX_Reg] & bit_AES; + return (cpu_info[ECX_Reg] & bit_AES) != 0; } @@ -95,7 +100,7 @@ static inline bool has_bmi2() { int cpu_info[4] = { 0 }; cpuid(EXTENDED_FEATURES, cpu_info); - return cpu_info[EBX_Reg] & bit_BMI2; + return (cpu_info[EBX_Reg] & bit_BMI2) != 0; } diff --git a/src/Mem.cpp b/src/Mem.cpp index 4437c6739..9c608f73c 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,7 @@ #include "crypto/CryptoNight.h" #include "Mem.h" #include "Options.h" +#include "xmrig.h" bool Mem::m_doubleHash = false; @@ -35,21 +37,22 @@ int Mem::m_algo = 0; int Mem::m_flags = 0; int Mem::m_threads = 0; size_t Mem::m_offset = 0; +size_t Mem::m_size = 0; uint8_t *Mem::m_memory = nullptr; cryptonight_ctx *Mem::create(int threadId) { # ifndef XMRIG_NO_AEON - if (m_algo == Options::ALGO_CRYPTONIGHT_LITE) { + if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) { return createLite(threadId); } # endif - cryptonight_ctx *ctx = reinterpret_cast(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); + cryptonight_ctx *ctx = reinterpret_cast(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); const int ratio = m_doubleHash ? 2 : 1; - ctx->memory = &m_memory[MEMORY * (threadId * ratio + 1)]; + ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)]; return ctx; } @@ -72,15 +75,15 @@ cryptonight_ctx *Mem::createLite(int threadId) { cryptonight_ctx *ctx; if (!m_doubleHash) { - const size_t offset = MEMORY * (threadId + 1); + const size_t offset = MONERO_MEMORY * (threadId + 1); - ctx = reinterpret_cast(&m_memory[offset + MEMORY_LITE]); + ctx = reinterpret_cast(&m_memory[offset + AEON_MEMORY]); ctx->memory = &m_memory[offset]; return ctx; } - ctx = reinterpret_cast(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); - ctx->memory = &m_memory[MEMORY * (threadId + 1)]; + ctx = reinterpret_cast(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); + ctx->memory = &m_memory[MONERO_MEMORY * (threadId + 1)]; return ctx; } diff --git a/src/Mem.h b/src/Mem.h index 58dba8485..eaa4f49a8 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,6 +62,7 @@ private: static int m_flags; static int m_threads; static size_t m_offset; + static size_t m_size; VAR_ALIGN(16, static uint8_t *m_memory); # ifndef XMRIG_NO_AEON diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 43ffa6644..3e6995444 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +38,7 @@ #include "log/Log.h" #include "Mem.h" #include "Options.h" +#include "xmrig.h" bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) @@ -45,35 +47,35 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) m_threads = threads; m_doubleHash = doubleHash; - const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; - const size_t size = MEMORY * (threads * ratio + 1); + const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; + m_size = MONERO_MEMORY * (threads * ratio + 1); if (!enabled) { - m_memory = static_cast(_mm_malloc(size, 16)); + m_memory = static_cast(_mm_malloc(m_size, 16)); return true; } m_flags |= HugepagesAvailable; # if defined(__APPLE__) - m_memory = static_cast(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0)); + m_memory = static_cast(mmap(0, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0)); # elif defined(__FreeBSD__) - m_memory = static_cast(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0)); + m_memory = static_cast(mmap(0, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0)); # else - m_memory = static_cast(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0)); + m_memory = static_cast(mmap(0, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0)); # endif if (m_memory == MAP_FAILED) { - m_memory = static_cast(_mm_malloc(size, 16)); + m_memory = static_cast(_mm_malloc(m_size, 16)); return true; } m_flags |= HugepagesEnabled; - if (madvise(m_memory, size, MADV_RANDOM | MADV_WILLNEED) != 0) { + if (madvise(m_memory, m_size, MADV_RANDOM | MADV_WILLNEED) != 0) { LOG_ERR("madvise failed"); } - if (mlock(m_memory, size) == 0) { + if (mlock(m_memory, m_size) == 0) { m_flags |= Lock; } @@ -83,14 +85,12 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) void Mem::release() { - const int size = MEMORY * (m_threads + 1); - if (m_flags & HugepagesEnabled) { if (m_flags & Lock) { - munlock(m_memory, size); + munlock(m_memory, m_size); } - munmap(m_memory, size); + munmap(m_memory, m_size); } else { _mm_free(m_memory); diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index a4f92cfe3..239bda7d8 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +38,7 @@ #include "crypto/CryptoNight.h" #include "Mem.h" #include "Options.h" +#include "xmrig.h" /***************************************************************** @@ -150,11 +152,11 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) m_threads = threads; m_doubleHash = doubleHash; - const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; - const size_t size = MEMORY * (threads * ratio + 1); + const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; + m_size = MONERO_MEMORY * (threads * ratio + 1); if (!enabled) { - m_memory = static_cast(_mm_malloc(size, 16)); + m_memory = static_cast(_mm_malloc(m_size, 16)); return true; } @@ -162,9 +164,9 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) m_flags |= HugepagesAvailable; } - m_memory = static_cast(VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); + m_memory = static_cast(VirtualAlloc(NULL, m_size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); if (!m_memory) { - m_memory = static_cast(_mm_malloc(size, 16)); + m_memory = static_cast(_mm_malloc(m_size, 16)); } else { m_flags |= HugepagesEnabled; diff --git a/src/Options.cpp b/src/Options.cpp index 4e7c75cac..939075f8a 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,6 +47,7 @@ #include "rapidjson/error/en.h" #include "rapidjson/filereadstream.h" #include "version.h" +#include "xmrig.h" #ifndef ARRAY_SIZE @@ -74,6 +75,7 @@ Options:\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --no-huge-pages disable huge pages support\n\ --no-color disable colored output\n\ + --variant algorithm PoW variant\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ --user-agent set custom user-agent string for pool\n\ -B, --background run the miner in the background\n\ @@ -118,6 +120,7 @@ static struct option const options[] = { { "nicehash", 0, nullptr, 1006 }, { "no-color", 0, nullptr, 1002 }, { "no-huge-pages", 0, nullptr, 1009 }, + { "variant", 1, nullptr, 1010 }, { "pass", 1, nullptr, 'p' }, { "print-time", 1, nullptr, 1007 }, { "retries", 1, nullptr, 'r' }, @@ -163,6 +166,7 @@ static struct option const pool_options[] = { { "user", 1, nullptr, 'u' }, { "userpass", 1, nullptr, 'O' }, { "keepalive", 0, nullptr ,'k' }, + { "variant", 1, nullptr, 1010 }, { "nicehash", 0, nullptr, 1006 }, { 0, 0, 0, 0 } }; @@ -272,9 +276,7 @@ Options::Options(int argc, char **argv) : } } - for (Url *url : m_pools) { - url->applyExceptions(); - } + adjust(); m_ready = true; } @@ -380,6 +382,7 @@ bool Options::parseArg(int key, const char *arg) case 1007: /* --print-time */ case 1021: /* --cpu-priority */ case 4000: /* --api-port */ + case 1010: /* --variant */ return parseArg(key, strtol(arg, nullptr, 10)); case 'B': /* --background */ @@ -498,6 +501,10 @@ bool Options::parseArg(int key, uint64_t arg) m_printTime = (int) arg; break; + case 1010: /* --variant */ + m_pools.back()->setVariant((int) arg); + break; + case 1020: /* --cpu-affinity */ if (arg) { m_affinity = arg; @@ -585,6 +592,14 @@ Url *Options::parseUrl(const char *arg) const } +void Options::adjust() +{ + for (Url *url : m_pools) { + url->adjust(m_algo); + } +} + + void Options::parseConfig(const char *fileName) { rapidjson::Document doc; @@ -629,7 +644,7 @@ void Options::parseJSON(const struct option *option, const rapidjson::Value &obj if (option->has_arg && value.IsString()) { parseArg(option->val, value.GetString()); } - else if (option->has_arg && value.IsUint64()) { + else if (option->has_arg && value.IsInt64()) { parseArg(option->val, value.GetUint64()); } else if (!option->has_arg && value.IsBool()) { @@ -695,7 +710,7 @@ bool Options::setAlgo(const char *algo) # ifndef XMRIG_NO_AEON if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) { - m_algo = ALGO_CRYPTONIGHT_LITE; + m_algo = xmrig::ALGO_CRYPTONIGHT_LITE; break; } # endif @@ -713,7 +728,7 @@ bool Options::setAlgo(const char *algo) int Options::getAlgoVariant() const { # ifndef XMRIG_NO_AEON - if (m_algo == ALGO_CRYPTONIGHT_LITE) { + if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) { return getAlgoVariantLite(); } # endif diff --git a/src/Options.h b/src/Options.h index 6f0749179..e29059ecc 100644 --- a/src/Options.h +++ b/src/Options.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,11 +39,6 @@ struct option; class Options { public: - enum Algo { - ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */ - ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ - }; - enum AlgoVariant { AV0_AUTO, AV1_AESNI, @@ -96,6 +91,7 @@ private: bool parseArg(int key, uint64_t arg); bool parseBoolean(int key, bool enable); Url *parseUrl(const char *arg) const; + void adjust(); void parseConfig(const char *fileName); void parseJSON(const struct option *option, const rapidjson::Value &object); void showUsage(int status) const; diff --git a/src/api/Httpd.cpp b/src/api/Httpd.cpp index 996bc0079..a604b5de3 100644 --- a/src/api/Httpd.cpp +++ b/src/api/Httpd.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,7 +45,19 @@ bool Httpd::start() return false; } - m_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END); + unsigned int flags = 0; + if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) { + flags = MHD_USE_EPOLL_LINUX_ONLY | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY; + } + else { + flags = MHD_USE_SELECT_INTERNALLY; + } + + if (MHD_is_feature_supported(MHD_FEATURE_IPv6)) { + flags |= MHD_USE_DUAL_STACK; + } + + m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END); if (!m_daemon) { LOG_ERR("HTTP Daemon failed to start."); return false; diff --git a/src/api/Httpd.h b/src/api/Httpd.h index 7a4dd9321..30618e2a8 100644 --- a/src/api/Httpd.h +++ b/src/api/Httpd.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp index 3ac9e94bb..996622c47 100644 --- a/src/crypto/CryptoNight.cpp +++ b/src/crypto/CryptoNight.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,7 @@ #include "crypto/CryptoNight.h" + #if defined(XMRIG_ARM) # include "crypto/CryptoNight_arm.h" #else @@ -34,60 +36,74 @@ #include "net/Job.h" #include "net/JobResult.h" #include "Options.h" +#include "xmrig.h" -void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr; +void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = nullptr; -static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx) { +#define CRYPTONIGHT_HASH(NAME, ITERATIONS, MEM, MASK, SOFT_AES) \ + switch (variant) { \ + case xmrig::VARIANT_V1: \ + return cryptonight_##NAME##_hash(input, size, output, ctx); \ + \ + case xmrig::VARIANT_NONE: \ + return cryptonight_##NAME##_hash(input, size, output, ctx); \ + \ + default: \ + break; \ + } + + +static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx, int variant) { # if !defined(XMRIG_ARMv7) - cryptonight_hash<0x80000, MEMORY, 0x1FFFF0, false>(input, size, output, ctx); + CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false) # endif } -static void cryptonight_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { +static void cryptonight_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { # if !defined(XMRIG_ARMv7) - cryptonight_double_hash<0x80000, MEMORY, 0x1FFFF0, false>(input, size, output, ctx); + CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false) # endif } -static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { - cryptonight_hash<0x80000, MEMORY, 0x1FFFF0, true>(input, size, output, ctx); +static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { + CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true) } -static void cryptonight_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { - cryptonight_double_hash<0x80000, MEMORY, 0x1FFFF0, true>(input, size, output, ctx); +static void cryptonight_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { + CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true) } #ifndef XMRIG_NO_AEON -static void cryptonight_lite_av1_aesni(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { - # if !defined(XMRIG_ARMv7) - cryptonight_hash<0x40000, MEMORY_LITE, 0xFFFF0, false>(input, size, output, ctx); -#endif -} - - -static void cryptonight_lite_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { +static void cryptonight_lite_av1_aesni(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { # if !defined(XMRIG_ARMv7) - cryptonight_double_hash<0x40000, MEMORY_LITE, 0xFFFF0, false>(input, size, output, ctx); + CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false) # endif } -static void cryptonight_lite_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { - cryptonight_hash<0x40000, MEMORY_LITE, 0xFFFF0, true>(input, size, output, ctx); +static void cryptonight_lite_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +# if !defined(XMRIG_ARMv7) + CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, false) +# endif } -static void cryptonight_lite_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { - cryptonight_double_hash<0x40000, MEMORY_LITE, 0xFFFF0, true>(input, size, output, ctx); +static void cryptonight_lite_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { + CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, true) } -void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = { + +static void cryptonight_lite_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { + CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, true) +} + +void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = { cryptonight_av1_aesni, cryptonight_av2_aesni_double, cryptonight_av3_softaes, @@ -98,7 +114,7 @@ void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_lite_av4_softaes_double }; #else -void (*cryptonight_variations[4])(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = { +void (*cryptonight_variations[4])(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = { cryptonight_av1_aesni, cryptonight_av2_aesni_double, cryptonight_av3_softaes, @@ -109,7 +125,7 @@ void (*cryptonight_variations[4])(const void *input, size_t size, void *output, bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx) { - cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx); + cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx, job.variant()); return *reinterpret_cast(result.result + 24) < job.target(); } @@ -122,7 +138,7 @@ bool CryptoNight::init(int algo, int variant) } # ifndef XMRIG_NO_AEON - const int index = algo == Options::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1); + const int index = algo == xmrig::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1); # else const int index = variant - 1; # endif @@ -133,9 +149,9 @@ bool CryptoNight::init(int algo, int variant) } -void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx) +void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) { - cryptonight_hash_ctx(input, size, output, ctx); + cryptonight_hash_ctx(input, size, output, ctx, variant); } @@ -146,17 +162,31 @@ bool CryptoNight::selfTest(int algo) { char output[64]; - struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16); - ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 2, 16); + struct cryptonight_ctx *ctx = static_cast(_mm_malloc(sizeof(cryptonight_ctx), 16)); + ctx->memory = static_cast(_mm_malloc(MONERO_MEMORY * 2, 16)); - cryptonight_hash_ctx(test_input, 76, output, ctx); + cryptonight_hash_ctx(test_input, 76, output, ctx, 0); + + const bool doubleHash = Options::i()->doubleHash(); + +# ifndef XMRIG_NO_AEON + bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, (doubleHash ? 64 : 32)) == 0; +# else + bool rc = memcmp(output, test_output_v0, (doubleHash ? 64 : 32)) == 0; +# endif + + if (rc) { + cryptonight_hash_ctx(test_input, 76, output, ctx, 1); + +# ifndef XMRIG_NO_AEON + rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v1_lite : test_output_v1, (doubleHash ? 64 : 32)) == 0; +# else + rc = memcmp(output, test_output_v1, (doubleHash ? 64 : 32)) == 0; +# endif + } _mm_free(ctx->memory); _mm_free(ctx); -# ifndef XMRIG_NO_AEON - return memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0; -# else - return memcmp(output, test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0; -# endif + return rc; } diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index 64fc0fd1a..9526309dd 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,9 +32,13 @@ #include "align.h" +#define AEON_MEMORY 1048576 +#define AEON_MASK 0xFFFF0 +#define AEON_ITER 0x40000 -#define MEMORY 2097152 /* 2 MiB */ -#define MEMORY_LITE 1048576 /* 1 MiB */ +#define MONERO_MEMORY 2097152 +#define MONERO_MASK 0x1FFFF0 +#define MONERO_ITER 0x80000 struct cryptonight_ctx { @@ -52,7 +57,7 @@ class CryptoNight public: static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx); static bool init(int algo, int variant); - static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx); + static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant); private: static bool selfTest(int algo); diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 4ac14f34d..6b214d66e 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -5,8 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2016 Imran Yusuff - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +35,7 @@ #include "crypto/CryptoNight.h" +#include "crypto/CryptoNight_monero.h" #include "crypto/soft_aes.h" @@ -136,20 +138,6 @@ static inline __m128i sl_xor(__m128i tmp1) } -template -static inline void aes_genkey_sub(__m128i* xout0, __m128i* xout2) -{ -// __m128i xout1 = _mm_aeskeygenassist_si128(*xout2, rcon); -// xout1 = _mm_shuffle_epi32(xout1, 0xFF); // see PSHUFD, set all elems to 4th elem -// *xout0 = sl_xor(*xout0); -// *xout0 = _mm_xor_si128(*xout0, xout1); -// xout1 = _mm_aeskeygenassist_si128(*xout0, 0x00); -// xout1 = _mm_shuffle_epi32(xout1, 0xAA); // see PSHUFD, set all elems to 3rd elem -// *xout2 = sl_xor(*xout2); -// *xout2 = _mm_xor_si128(*xout2, xout1); -} - - template static inline void soft_aes_genkey_sub(__m128i* xout0, __m128i* xout2) { @@ -344,11 +332,13 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) } -template -inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) +template +inline void cryptonight_single_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) { keccak(static_cast(input), (int) size, ctx->state0, 200); + VARIANT1_INIT(0); + cn_explode_scratchpad((__m128i*) ctx->state0, (__m128i*) ctx->memory); const uint8_t* l0 = ctx->memory; @@ -374,6 +364,7 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * } _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); + VARIANT1_1(&l0[idx0 & MASK]); idx0 = EXTRACT64(cx); bx0 = cx; @@ -385,8 +376,10 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * al0 += hi; ah0 += lo; + VARIANT1_2(ah0, 0); ((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; + VARIANT1_2(ah0, 0); ah0 ^= ch; al0 ^= cl; @@ -400,12 +393,15 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * } -template +template inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) { keccak((const uint8_t *) input, (int) size, ctx->state0, 200); keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200); + VARIANT1_INIT(0); + VARIANT1_INIT(1); + const uint8_t* l0 = ctx->memory; const uint8_t* l1 = ctx->memory + MEM; uint64_t* h0 = reinterpret_cast(ctx->state0); @@ -443,6 +439,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + VARIANT1_1(&l0[idx0 & MASK]); + VARIANT1_1(&l1[idx1 & MASK]); idx0 = EXTRACT64(cx0); idx1 = EXTRACT64(cx1); @@ -458,8 +456,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, al0 += hi; ah0 += lo; + VARIANT1_2(ah0, 0); ((uint64_t*) &l0[idx0 & MASK])[0] = al0; ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + VARIANT1_2(ah0, 0); ah0 ^= ch; al0 ^= cl; @@ -472,8 +472,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, al1 += hi; ah1 += lo; + VARIANT1_2(ah1, 1); ((uint64_t*) &l1[idx1 & MASK])[0] = al1; ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + VARIANT1_2(ah1, 1); ah1 ^= ch; al1 ^= cl; diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h new file mode 100644 index 000000000..3c6146aca --- /dev/null +++ b/src/crypto/CryptoNight_monero.h @@ -0,0 +1,51 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __CRYPTONIGHT_MONERO_H__ +#define __CRYPTONIGHT_MONERO_H__ + + +// VARIANT ALTERATIONS +#define VARIANT1_INIT(part) \ + uint64_t tweak1_2_##part = 0; \ + if (VARIANT > 0) { \ + tweak1_2_##part = (*reinterpret_cast(reinterpret_cast(input) + 35 + part * size) ^ \ + *(reinterpret_cast(ctx->state##part) + 24)); \ + } + +#define VARIANT1_1(p) \ + if (VARIANT > 0) { \ + const uint8_t tmp = reinterpret_cast(p)[11]; \ + static const uint32_t table = 0x75310; \ + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ + ((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \ + } + +#define VARIANT1_2(p, part) \ + if (VARIANT > 0) { \ + (p) ^= tweak1_2_##part; \ + } + + +#endif /* __CRYPTONIGHT_MONERO_H__ */ diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index b2985379b..0f7feda11 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +40,7 @@ const static uint8_t test_input[152] = { }; -const static uint8_t test_output0[64] = { +const static uint8_t test_output_v0[64] = { 0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66, 0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F, 0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7, @@ -47,12 +48,30 @@ const static uint8_t test_output0[64] = { }; +// Monero v7 +const static uint8_t test_output_v1[64] = { + 0xC9, 0xFA, 0xE8, 0x42, 0x5D, 0x86, 0x88, 0xDC, 0x23, 0x6B, 0xCD, 0xBC, 0x42, 0xFD, 0xB4, 0x2D, + 0x37, 0x6C, 0x6E, 0xC1, 0x90, 0x50, 0x1A, 0xA8, 0x4B, 0x04, 0xA4, 0xB4, 0xCF, 0x1E, 0xE1, 0x22, + 0xF2, 0x2D, 0x3D, 0x62, 0x03, 0xD2, 0xA0, 0x8B, 0x41, 0xD9, 0x02, 0x72, 0x78, 0xD8, 0xBC, 0xC9, + 0x83, 0xAC, 0xAD, 0xA9, 0xB6, 0x8E, 0x52, 0xE3, 0xC6, 0x89, 0x69, 0x2A, 0x50, 0xE9, 0x21, 0xD9 +}; + + #ifndef XMRIG_NO_AEON -const static uint8_t test_output1[64] = { +const static uint8_t test_output_v0_lite[64] = { 0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE, 0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD, 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, - 0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88, + 0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88 +}; + + +// AEON v2 +const static uint8_t test_output_v1_lite[64] = { + 0x87, 0xC4, 0xE5, 0x70, 0x65, 0x3E, 0xB4, 0xC2, 0xB4, 0x2B, 0x7A, 0x0D, 0x54, 0x65, 0x59, 0x45, + 0x2D, 0xFA, 0xB5, 0x73, 0xB8, 0x2E, 0xC5, 0x2F, 0x15, 0x2B, 0x7F, 0xF9, 0x8E, 0x79, 0x44, 0x6F, + 0x6D, 0x8C, 0xDC, 0x44, 0x4E, 0x9B, 0xBB, 0xFD, 0x68, 0xFC, 0x43, 0xFC, 0xD4, 0x85, 0x5B, 0x22, + 0x8C, 0x8A, 0x1B, 0xD9, 0x1D, 0x9D, 0x00, 0x28, 0x5B, 0xEC, 0x02, 0xB7, 0xCA, 0x2D, 0x67, 0x41 }; #endif diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 927aab723..1e5190d8f 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +35,7 @@ #include "crypto/CryptoNight.h" +#include "crypto/CryptoNight_monero.h" #include "crypto/soft_aes.h" @@ -307,11 +309,13 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) } -template -inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) +template +inline void cryptonight_single_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) { keccak(static_cast(input), (int) size, ctx->state0, 200); + VARIANT1_INIT(0); + cn_explode_scratchpad((__m128i*) ctx->state0, (__m128i*) ctx->memory); const uint8_t* l0 = ctx->memory; @@ -334,6 +338,7 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); + VARIANT1_1(&l0[idx0 & MASK]); idx0 = EXTRACT64(cx); bx0 = cx; @@ -345,8 +350,10 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * al0 += hi; ah0 += lo; + VARIANT1_2(ah0, 0); ((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; + VARIANT1_2(ah0, 0); ah0 ^= ch; al0 ^= cl; @@ -360,12 +367,15 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * } -template +template inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) { keccak((const uint8_t *) input, (int) size, ctx->state0, 200); keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200); + VARIANT1_INIT(0); + VARIANT1_INIT(1); + const uint8_t* l0 = ctx->memory; const uint8_t* l1 = ctx->memory + MEM; uint64_t* h0 = reinterpret_cast(ctx->state0); @@ -401,6 +411,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + VARIANT1_1(&l0[idx0 & MASK]); + VARIANT1_1(&l1[idx1 & MASK]); idx0 = EXTRACT64(cx0); idx1 = EXTRACT64(cx1); @@ -416,8 +428,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, al0 += hi; ah0 += lo; + VARIANT1_2(ah0, 0); ((uint64_t*) &l0[idx0 & MASK])[0] = al0; ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + VARIANT1_2(ah0, 0); ah0 ^= ch; al0 ^= cl; @@ -430,8 +444,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, al1 += hi; ah1 += lo; + VARIANT1_2(ah1, 1); ((uint64_t*) &l1[idx1 & MASK])[0] = al1; ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + VARIANT1_2(ah1, 1); ah1 ^= ch; al1 ^= cl; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index eb07bf21a..f6543b4e7 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -54,6 +54,8 @@ int64_t Client::m_sequence = 1; Client::Client(int id, const char *agent, IClientListener *listener) : + m_ipv6(false), + m_nicehash(false), m_quiet(false), m_agent(agent), m_listener(listener), @@ -71,7 +73,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) : m_resolver.data = this; - m_hints.ai_family = PF_INET; + m_hints.ai_family = AF_UNSPEC; m_hints.ai_socktype = SOCK_STREAM; m_hints.ai_protocol = IPPROTO_TCP; @@ -109,19 +111,6 @@ void Client::connect(const Url *url) } -void Client::disconnect() -{ -# ifndef XMRIG_PROXY_PROJECT - uv_timer_stop(&m_keepAliveTimer); -# endif - - m_expire = 0; - m_failures = -1; - - close(); -} - - void Client::setUrl(const Url *url) { if (!url || !url->isValid()) { @@ -150,6 +139,19 @@ void Client::tick(uint64_t now) } +bool Client::disconnect() +{ +# ifndef XMRIG_PROXY_PROJECT + uv_timer_stop(&m_keepAliveTimer); +# endif + + m_expire = 0; + m_failures = -1; + + return close(); +} + + int64_t Client::submit(const JobResult &result) { # ifdef XMRIG_PROXY_PROJECT @@ -167,13 +169,29 @@ int64_t Client::submit(const JobResult &result) # endif const size_t size = snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRIu64 ",\"jsonrpc\":\"2.0\",\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"}}\n", - m_sequence, m_rpcId, result.jobId.data(), nonce, data); + m_sequence, m_rpcId.data(), result.jobId.data(), nonce, data); m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff()); return send(size); } +bool Client::close() +{ + if (m_state == UnconnectedState || m_state == ClosingState || !m_socket) { + return false; + } + + setState(ClosingState); + + if (uv_is_closing(reinterpret_cast(m_socket)) == 0) { + uv_close(reinterpret_cast(m_socket), Client::onClose); + } + + return true; +} + + bool Client::isCriticalError(const char *message) { if (!message) { @@ -203,7 +221,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } - Job job(m_id, m_url.isNicehash()); + Job job(m_id, m_nicehash, m_url.algo(), m_url.variant()); if (!job.setId(params["job_id"].GetString())) { *code = 3; return false; @@ -219,6 +237,14 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } + if (params.HasMember("coin")) { + job.setCoin(params["coin"].GetString()); + } + + if (params.HasMember("variant")) { + job.setVariant(params["variant"].GetInt()); + } + if (m_job == job) { if (!m_quiet) { LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); @@ -235,14 +261,16 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) bool Client::parseLogin(const rapidjson::Value &result, int *code) { - const char *id = result["id"].GetString(); - if (!id || strlen(id) >= sizeof(m_rpcId)) { + if (!m_rpcId.setId(result["id"].GetString())) { *code = 1; return false; } - memset(m_rpcId, 0, sizeof(m_rpcId)); - memcpy(m_rpcId, id, strlen(id)); + m_nicehash = m_url.isNicehash(); + + if (result.HasMember("extensions")) { + parseExtensions(result["extensions"]); + } return parseJob(result["job"], code); } @@ -291,21 +319,25 @@ int64_t Client::send(size_t size) } -void Client::close() +void Client::connect(const std::vector &ipv4, const std::vector &ipv6) { - if (m_state == UnconnectedState || m_state == ClosingState || !m_socket) { - return; + addrinfo *addr = nullptr; + m_ipv6 = ipv4.empty() && !ipv6.empty(); + + if (m_ipv6) { + addr = ipv6[ipv6.size() == 1 ? 0 : rand() % ipv6.size()]; + uv_ip6_name(reinterpret_cast(addr->ai_addr), m_ip, 45); + } + else { + addr = ipv4[ipv4.size() == 1 ? 0 : rand() % ipv4.size()]; + uv_ip4_name(reinterpret_cast(addr->ai_addr), m_ip, 16); } - setState(ClosingState); - - if (uv_is_closing(reinterpret_cast(m_socket)) == 0) { - uv_close(reinterpret_cast(m_socket), Client::onClose); - } + connect(addr->ai_addr); } -void Client::connect(struct sockaddr *addr) +void Client::connect(sockaddr *addr) { setState(ConnectingState); @@ -374,6 +406,11 @@ void Client::parse(char *line, size_t len) LOG_DEBUG("[%s:%u] received (%d bytes): \"%s\"", m_url.host(), m_url.port(), len, line); + if (len < 32 || line[0] != '{') { + LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port()); + return; + } + rapidjson::Document doc; if (doc.ParseInsitu(line).HasParseError()) { if (!m_quiet) { @@ -397,6 +434,24 @@ void Client::parse(char *line, size_t len) } +void Client::parseExtensions(const rapidjson::Value &value) +{ + if (!value.IsArray()) { + return; + } + + for (const rapidjson::Value &ext : value.GetArray()) { + if (!ext.IsString()) { + continue; + } + + if (strcmp(ext.GetString(), "nicehash") == 0) { + m_nicehash = true; + } + } +} + + void Client::parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error) { if (error.IsObject()) { @@ -456,7 +511,8 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code); } - return close(); + close(); + return; } m_failures = 0; @@ -476,7 +532,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap void Client::ping() { - send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId)); + send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); } @@ -532,7 +588,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t auto client = getClient(handle->data); buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; - buf->len = client->m_recvBuf.len - (unsigned long)client->m_recvBufPos; + buf->len = client->m_recvBuf.len - client->m_recvBufPos; } @@ -582,11 +638,13 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); } - return client->close(); + client->close(); + return; } if ((size_t) nread > (sizeof(m_buf) - 8 - client->m_recvBufPos)) { - return client->close(); + client->close(); + return; } client->m_recvBufPos += nread; @@ -628,24 +686,27 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) addrinfo *ptr = res; std::vector ipv4; + std::vector ipv6; while (ptr != nullptr) { if (ptr->ai_family == AF_INET) { ipv4.push_back(ptr); } + if (ptr->ai_family == AF_INET6) { + ipv6.push_back(ptr); + } + ptr = ptr->ai_next; } - if (ipv4.empty()) { - LOG_ERR("[%s:%u] DNS error: \"No IPv4 records found\"", client->m_url.host(), client->m_url.port()); + if (ipv4.empty() && ipv6.empty()) { + LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port()); + + uv_freeaddrinfo(res); return client->reconnect(); } - ptr = ipv4[rand() % ipv4.size()]; - - uv_ip4_name(reinterpret_cast(ptr->ai_addr), client->m_ip, 16); - - client->connect(ptr->ai_addr); + client->connect(ipv4, ipv6); uv_freeaddrinfo(res); } diff --git a/src/net/Client.h b/src/net/Client.h index 2cc169153..a927bd19d 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -27,8 +27,10 @@ #include #include +#include +#include "net/Id.h" #include "net/Job.h" #include "net/SubmitResult.h" #include "net/Url.h" @@ -56,10 +58,10 @@ public: Client(int id, const char *agent, IClientListener *listener); ~Client(); + bool disconnect(); int64_t submit(const JobResult &result); void connect(); void connect(const Url *url); - void disconnect(); void setUrl(const Url *url); void tick(uint64_t now); @@ -74,15 +76,17 @@ public: inline void setRetryPause(int ms) { m_retryPause = ms; } private: + bool close(); bool isCriticalError(const char *message); bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); int resolve(const char *host); int64_t send(size_t size); - void close(); - void connect(struct sockaddr *addr); + void connect(const std::vector &ipv4, const std::vector &ipv6); + void connect(sockaddr *addr); void login(); void parse(char *line, size_t len); + void parseExtensions(const rapidjson::Value &value); void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error); void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); void ping(); @@ -99,10 +103,11 @@ private: static inline Client *getClient(void *data) { return static_cast(data); } addrinfo m_hints; + bool m_ipv6; + bool m_nicehash; bool m_quiet; char m_buf[2048]; - char m_ip[17]; - char m_rpcId[64]; + char m_ip[46]; char m_sendBuf[768]; const char *m_agent; IClientListener *m_listener; @@ -120,6 +125,7 @@ private: uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; + xmrig::Id m_rpcId; # ifndef XMRIG_PROXY_PROJECT uv_timer_t m_keepAliveTimer; diff --git a/src/net/JobId.h b/src/net/Id.h similarity index 75% rename from src/net/JobId.h rename to src/net/Id.h index 061897792..5c77d1d43 100644 --- a/src/net/JobId.h +++ b/src/net/Id.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,40 +21,51 @@ * along with this program. If not, see . */ -#ifndef __JOBID_H__ -#define __JOBID_H__ +#ifndef __ID_H__ +#define __ID_H__ #include -class JobId +namespace xmrig { + + +class Id { public: - inline JobId() + inline Id() { memset(m_data, 0, sizeof(m_data)); } - inline JobId(const char *id, size_t sizeFix = 0) + inline Id(const char *id, size_t sizeFix = 0) { setId(id, sizeFix); } - inline bool operator==(const JobId &other) const + inline bool operator==(const Id &other) const { return memcmp(m_data, other.m_data, sizeof(m_data)) == 0; } - inline bool operator!=(const JobId &other) const + inline bool operator!=(const Id &other) const { return memcmp(m_data, other.m_data, sizeof(m_data)) != 0; } + Id &operator=(const Id &other) + { + memcpy(m_data, other.m_data, sizeof(m_data)); + + return *this; + } + + inline bool setId(const char *id, size_t sizeFix = 0) { memset(m_data, 0, sizeof(m_data)); @@ -80,4 +91,8 @@ private: char m_data[64]; }; -#endif /* __JOBID_H__ */ + +} /* namespace xmrig */ + + +#endif /* __ID_H__ */ diff --git a/src/net/Job.cpp b/src/net/Job.cpp index c3d33739a..8b1966aa3 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,14 +56,31 @@ static inline char hf_bin2hex(unsigned char c) } -Job::Job(int poolId, bool nicehash) : - m_nicehash(nicehash), - m_poolId(poolId), +Job::Job() : + m_nicehash(false), + m_algo(xmrig::ALGO_CRYPTONIGHT), + m_poolId(-2), m_threadId(-1), + m_variant(xmrig::VARIANT_AUTO), m_size(0), m_diff(0), m_target(0) { + memset(m_coin, 0, sizeof(m_coin)); +} + + +Job::Job(int poolId, bool nicehash, int algo, int variant) : + m_nicehash(nicehash), + m_algo(algo), + m_poolId(poolId), + m_threadId(-1), + m_variant(variant), + m_size(0), + m_diff(0), + m_target(0) +{ + memset(m_coin, 0, sizeof(m_coin)); } @@ -146,6 +164,33 @@ bool Job::setTarget(const char *target) } +void Job::setCoin(const char *coin) +{ + if (!coin || strlen(coin) > 4) { + memset(m_coin, 0, sizeof(m_coin)); + return; + } + + strncpy(m_coin, coin, sizeof(m_coin)); + m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::ALGO_CRYPTONIGHT_LITE : xmrig::ALGO_CRYPTONIGHT; +} + + +void Job::setVariant(int variant) +{ + switch (variant) { + case xmrig::VARIANT_AUTO: + case xmrig::VARIANT_NONE: + case xmrig::VARIANT_V1: + m_variant = variant; + break; + + default: + break; + } +} + + bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) { bool error = false; diff --git a/src/net/Job.h b/src/net/Job.h index bf8f88356..545eaa888 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,26 +31,32 @@ #include "align.h" -#include "net/JobId.h" +#include "net/Id.h" +#include "xmrig.h" class Job { public: - Job(int poolId = -2, bool nicehash = false); + Job(); + Job(int poolId, bool nicehash, int algo, int variant); ~Job(); bool setBlob(const char *blob); bool setTarget(const char *target); + void setCoin(const char *coin); + void setVariant(int variant); inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline bool setId(const char *id) { return m_id.setId(id); } - inline const JobId &id() const { return m_id; } + inline const char *coin() const { return m_coin; } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } + inline const xmrig::Id &id() const { return m_id; } inline int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } + inline int variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? 1 : 0) : m_variant); } inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } inline uint32_t diff() const { return (uint32_t) m_diff; } @@ -73,12 +80,15 @@ private: VAR_ALIGN(16, uint8_t m_blob[84]); // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. bool m_nicehash; + char m_coin[5]; + int m_algo; int m_poolId; int m_threadId; - JobId m_id; + int m_variant; size_t m_size; uint64_t m_diff; uint64_t m_target; + xmrig::Id m_id; # ifdef XMRIG_PROXY_PROJECT VAR_ALIGN(16, char m_rawBlob[169]); diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 520022a76..e32825847 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,11 +36,11 @@ class JobResult { public: inline JobResult() : poolId(0), diff(0), nonce(0) {} - inline JobResult(int poolId, const JobId &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff) : + inline JobResult(int poolId, const xmrig::Id &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff) : poolId(poolId), - jobId(jobId), diff(diff), - nonce(nonce) + nonce(nonce), + jobId(jobId) { memcpy(this->result, result, sizeof(this->result)); } @@ -71,10 +71,10 @@ public: int poolId; - JobId jobId; uint32_t diff; uint32_t nonce; uint8_t result[32]; + xmrig::Id jobId; }; #endif /* __JOBRESULT_H__ */ diff --git a/src/net/Url.cpp b/src/net/Url.cpp index dcbe82af5..c17ef690a 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #include "net/Url.h" +#include "xmrig.h" #ifdef _MSC_VER @@ -41,6 +42,9 @@ Url::Url() : m_host(nullptr), m_password(nullptr), m_user(nullptr), + m_algo(xmrig::ALGO_CRYPTONIGHT), + m_variant(xmrig::VARIANT_AUTO), + m_url(nullptr), m_port(kDefaultPort) { } @@ -63,17 +67,23 @@ Url::Url(const char *url) : m_host(nullptr), m_password(nullptr), m_user(nullptr), + m_algo(xmrig::ALGO_CRYPTONIGHT), + m_variant(xmrig::VARIANT_AUTO), + m_url(nullptr), m_port(kDefaultPort) { parse(url); } -Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash) : +Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash, int variant) : m_keepAlive(keepAlive), m_nicehash(nicehash), m_password(password ? strdup(password) : nullptr), m_user(user ? strdup(user) : nullptr), + m_algo(xmrig::ALGO_CRYPTONIGHT), + m_variant(variant), + m_url(nullptr), m_port(port) { m_host = strdup(host); @@ -85,6 +95,10 @@ Url::~Url() free(m_host); free(m_password); free(m_user); + + if (m_url) { + delete [] m_url; + } } @@ -105,6 +119,10 @@ bool Url::parse(const char *url) return false; } + if (base[0] == '[') { + return parseIPv6(base); + } + const char *port = strchr(base, ':'); if (!port) { m_host = strdup(base); @@ -112,9 +130,8 @@ bool Url::parse(const char *url) } const size_t size = port++ - base + 1; - m_host = static_cast(malloc(size)); + m_host = new char[size](); memcpy(m_host, base, size - 1); - m_host[size - 1] = '\0'; m_port = (uint16_t) strtol(port, nullptr, 10); return true; @@ -139,12 +156,27 @@ bool Url::setUserpass(const char *userpass) } -void Url::applyExceptions() +const char *Url::url() const +{ + if (!m_url) { + const size_t size = strlen(m_host) + 8; + m_url = new char[size]; + + snprintf(m_url, size - 1, "%s:%d", m_host, m_port); + } + + return m_url; +} + + +void Url::adjust(int algo) { if (!isValid()) { return; } + m_algo = algo; + if (strstr(m_host, ".nicehash.com")) { m_keepAlive = false; m_nicehash = true; @@ -178,9 +210,40 @@ void Url::setUser(const char *user) } +void Url::setVariant(int variant) +{ + switch (variant) { + case xmrig::VARIANT_AUTO: + case xmrig::VARIANT_NONE: + case xmrig::VARIANT_V1: + m_variant = variant; + break; + + default: + break; + } +} + + +bool Url::operator==(const Url &other) const +{ + if (m_port != other.m_port || m_keepAlive != other.m_keepAlive || m_nicehash != other.m_nicehash) { + return false; + } + + if (strcmp(host(), other.host()) != 0 || strcmp(user(), other.user()) != 0 || strcmp(password(), other.password()) != 0) { + return false; + } + + return true; +} + + Url &Url::operator=(const Url *other) { m_keepAlive = other->m_keepAlive; + m_algo = other->m_algo; + m_variant = other->m_variant; m_nicehash = other->m_nicehash; m_port = other->m_port; @@ -190,5 +253,32 @@ Url &Url::operator=(const Url *other) setPassword(other->m_password); setUser(other->m_user); + if (m_url) { + delete [] m_url; + m_url = nullptr; + } + return *this; } + + +bool Url::parseIPv6(const char *addr) +{ + const char *end = strchr(addr, ']'); + if (!end) { + return false; + } + + const char *port = strchr(end, ':'); + if (!port) { + return false; + } + + const size_t size = end - addr; + m_host = new char[size](); + memcpy(m_host, addr + 1, size - 1); + + m_port = (uint16_t) strtol(port + 1, nullptr, 10); + + return true; +} diff --git a/src/net/Url.h b/src/net/Url.h index a1982300c..f861fec54 100644 --- a/src/net/Url.h +++ b/src/net/Url.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ public: Url(); Url(const char *url); - Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false ); + Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, int variant = -1); ~Url(); inline bool isKeepAlive() const { return m_keepAlive; } @@ -46,24 +46,35 @@ public: inline const char *host() const { return m_host; } inline const char *password() const { return m_password ? m_password : kDefaultPassword; } inline const char *user() const { return m_user ? m_user : kDefaultUser; } + inline int algo() const { return m_algo; } + inline int variant() const { return m_variant; } inline uint16_t port() const { return m_port; } inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setVariant(bool monero) { m_variant = monero; } bool parse(const char *url); bool setUserpass(const char *userpass); - void applyExceptions(); + const char *url() const; + void adjust(int algo); void setPassword(const char *password); void setUser(const char *user); + void setVariant(int variant); + bool operator==(const Url &other) const; Url &operator=(const Url *other); private: + bool parseIPv6(const char *addr); + bool m_keepAlive; bool m_nicehash; char *m_host; char *m_password; char *m_user; + int m_algo; + int m_variant; + mutable char *m_url; uint16_t m_port; }; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index d7c721c66..84d1e4da5 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ #include "net/Job.h" #include "net/strategies/DonateStrategy.h" #include "Options.h" +#include "xmrig.h" extern "C" @@ -48,7 +49,7 @@ DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : keccak(reinterpret_cast(user), static_cast(strlen(user)), hash, sizeof(hash)); Job::toHex(hash, 32, userId); - Url *url = new Url("fee.xmrig.com", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443, userId, nullptr, false, true); + Url *url = new Url("thanks.xmrig.com", Options::i()->algo() == xmrig::ALGO_CRYPTONIGHT_LITE ? 5555 : 80, userId, nullptr, false, true); m_client = new Client(-1, agent, this); m_client->setUrl(url); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 302de292c..070110533 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/version.h b/src/version.h index d34b45a59..e0d4511ae 100644 --- a/src/version.h +++ b/src/version.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2018 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,15 +27,15 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.4.5" +#define APP_VERSION "2.5.0-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" #define APP_KIND "cpu" #define APP_VER_MAJOR 2 -#define APP_VER_MINOR 4 -#define APP_VER_BUILD 5 +#define APP_VER_MINOR 5 +#define APP_VER_BUILD 0 #define APP_VER_REV 0 #ifdef _MSC_VER diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index 46d6f3663..46c8ed2ea 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -85,7 +86,7 @@ void DoubleWorker::start() *Job::nonce(m_state->blob) = ++m_state->nonce1; *Job::nonce(m_state->blob + m_state->job.size()) = ++m_state->nonce2; - CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx); + CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx, m_state->job.variant()); if (*reinterpret_cast(m_hash + 24) < m_state->job.target()) { Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff())); diff --git a/src/workers/DoubleWorker.h b/src/workers/DoubleWorker.h index 711f4bd1c..9f29fa5b2 100644 --- a/src/workers/DoubleWorker.h +++ b/src/workers/DoubleWorker.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index ecb566f89..9f4a7484c 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/workers/SingleWorker.h b/src/workers/SingleWorker.h index 08ab1857e..f7d9cff88 100644 --- a/src/workers/SingleWorker.h +++ b/src/workers/SingleWorker.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/xmrig.h b/src/xmrig.h new file mode 100644 index 000000000..103e8a68e --- /dev/null +++ b/src/xmrig.h @@ -0,0 +1,47 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __XMRIG_H__ +#define __XMRIG_H__ + + +namespace xmrig +{ + + +enum Algo { + ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */ + ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ +}; + + +enum Variant { + VARIANT_AUTO = -1, + VARIANT_NONE = 0, + VARIANT_V1 = 1 +}; + +} /* xmrig */ + + +#endif /* __XMRIG_H__ */