From 52aec4d9572ca98033613a18e5b4a6a63149d9bf Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 2 Feb 2023 12:26:46 +0700 Subject: [PATCH 1/4] v6.19.1-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index f3b98a28..07c4c493 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define APP_ID "xmrig-proxy" #define APP_NAME "xmrig-proxy" #define APP_DESC "XMRig Stratum proxy" -#define APP_VERSION "6.19.0" +#define APP_VERSION "6.19.1-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2023 xmrig.com" @@ -30,7 +30,7 @@ #define APP_VER_MAJOR 6 #define APP_VER_MINOR 19 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 1 #ifdef _MSC_VER # if (_MSC_VER >= 1930) From 207072653f36a3134c353e89f54e1a081f57af84 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 16 Mar 2023 23:45:49 +0700 Subject: [PATCH 2/4] Sync changes with XMRig. --- src/base/kernel/Platform.cpp | 10 +++++---- src/base/net/dns/DnsRecord.cpp | 8 +++---- src/base/net/dns/DnsUvBackend.cpp | 29 +++++++++++++++---------- src/base/net/tls/TlsContext.cpp | 36 +++++++++++++++++++++++++++++-- src/base/net/tls/TlsContext.h | 12 +++++------ src/base/net/tls/TlsGen.cpp | 8 +++++-- src/base/net/tls/TlsGen.h | 8 +++---- src/base/net/tools/Storage.h | 9 +++++--- src/base/tools/Object.h | 13 ++++++----- 9 files changed, 91 insertions(+), 42 deletions(-) diff --git a/src/base/kernel/Platform.cpp b/src/base/kernel/Platform.cpp index ef2b67eb..9baf77c2 100644 --- a/src/base/kernel/Platform.cpp +++ b/src/base/kernel/Platform.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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 @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - #include "base/kernel/Platform.h" @@ -42,9 +41,12 @@ void xmrig::Platform::init(const char *userAgent) # ifdef XMRIG_FEATURE_TLS SSL_library_init(); SSL_load_error_strings(); + +# if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) ERR_load_BIO_strings(); ERR_load_crypto_strings(); - SSL_load_error_strings(); +# endif + OpenSSL_add_all_digests(); # endif diff --git a/src/base/net/dns/DnsRecord.cpp b/src/base/net/dns/DnsRecord.cpp index bfa84613..3bf8f097 100644 --- a/src/base/net/dns/DnsRecord.cpp +++ b/src/base/net/dns/DnsRecord.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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 @@ -46,11 +46,11 @@ xmrig::String xmrig::DnsRecord::ip() const if (m_type == AAAA) { buf = new char[45](); - uv_ip6_name(reinterpret_cast(m_data), buf, 45); + uv_ip6_name(reinterpret_cast(m_data), buf, 45); } else { buf = new char[16](); - uv_ip4_name(reinterpret_cast(m_data), buf, 16); + uv_ip4_name(reinterpret_cast(m_data), buf, 16); } return buf; diff --git a/src/base/net/dns/DnsUvBackend.cpp b/src/base/net/dns/DnsUvBackend.cpp index 8de95df5..33f27f95 100644 --- a/src/base/net/dns/DnsUvBackend.cpp +++ b/src/base/net/dns/DnsUvBackend.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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,18 +28,19 @@ namespace xmrig { -static Storage* storage = nullptr; -Storage& DnsUvBackend::getStorage() +static Storage *storage = nullptr; + + +Storage &DnsUvBackend::getStorage() { - if (storage == nullptr) storage = new Storage(); + if (storage == nullptr) { + storage = new Storage(); + } + return *storage; } -void DnsUvBackend::releaseStorage() -{ - delete storage; -} static addrinfo hints{}; @@ -61,8 +62,14 @@ xmrig::DnsUvBackend::DnsUvBackend() xmrig::DnsUvBackend::~DnsUvBackend() { - getStorage().release(m_key); - releaseStorage(); + assert(storage); + + storage->release(m_key); + + if (storage->isEmpty()) { + delete storage; + storage = nullptr; + } } diff --git a/src/base/net/tls/TlsContext.cpp b/src/base/net/tls/TlsContext.cpp index e3621797..54b904ea 100644 --- a/src/base/net/tls/TlsContext.cpp +++ b/src/base/net/tls/TlsContext.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018 Lee Clagett - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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,6 +45,7 @@ namespace xmrig { // https://wiki.openssl.org/index.php/Diffie-Hellman_parameters +#if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) static DH *get_dh2048() { static unsigned char dhp_2048[] = { @@ -96,6 +97,8 @@ static DH *get_dh2048() return dh; } +#endif + } // namespace xmrig @@ -191,6 +194,7 @@ bool xmrig::TlsContext::setCipherSuites(const char *ciphersuites) bool xmrig::TlsContext::setDH(const char *dhparam) { +# if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) DH *dh = nullptr; if (dhparam != nullptr) { @@ -225,6 +229,34 @@ bool xmrig::TlsContext::setDH(const char *dhparam) return false; } +# else + if (dhparam != nullptr) { + EVP_PKEY *dh = nullptr; + BIO *bio = BIO_new_file(Env::expand(dhparam), "r"); + + if (bio) { + dh = PEM_read_bio_Parameters(bio, nullptr); + BIO_free(bio); + } + + if (!dh) { + LOG_ERR("PEM_read_bio_Parameters(\"%s\") failed.", dhparam); + + return false; + } + + if (SSL_CTX_set0_tmp_dh_pkey(m_ctx, dh) != 1) { + EVP_PKEY_free(dh); + + LOG_ERR("SSL_CTX_set0_tmp_dh_pkey(\"%s\") failed.", dhparam); + + return false; + } + } + else { + SSL_CTX_set_dh_auto(m_ctx, 1); + } +# endif return true; } diff --git a/src/base/net/tls/TlsContext.h b/src/base/net/tls/TlsContext.h index 9a9b3cb1..0bb7eec3 100644 --- a/src/base/net/tls/TlsContext.h +++ b/src/base/net/tls/TlsContext.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018 Lee Clagett - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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,9 +24,6 @@ #include "base/tools/Object.h" -#include - - using SSL_CTX = struct ssl_ctx_st; @@ -60,6 +57,7 @@ class TlsContext }; -} /* namespace xmrig */ +} // namespace xmrig + -#endif /* XMRIG_TLSCONTEXT_H */ +#endif // XMRIG_TLSCONTEXT_H diff --git a/src/base/net/tls/TlsGen.cpp b/src/base/net/tls/TlsGen.cpp index 42892053..ad2e648b 100644 --- a/src/base/net/tls/TlsGen.cpp +++ b/src/base/net/tls/TlsGen.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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 @@ -33,6 +33,7 @@ static const char *kLocalhost = "localhost"; static EVP_PKEY *generate_pkey() { +# if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) auto pkey = EVP_PKEY_new(); if (!pkey) { return nullptr; @@ -53,6 +54,9 @@ static EVP_PKEY *generate_pkey() BN_free(exponent); return pkey; +# else + return EVP_RSA_gen(2048); +# endif } diff --git a/src/base/net/tls/TlsGen.h b/src/base/net/tls/TlsGen.h index c471c8ca..193dd2d5 100644 --- a/src/base/net/tls/TlsGen.h +++ b/src/base/net/tls/TlsGen.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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,7 +55,7 @@ class TlsGen }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_TLSGEN_H */ +#endif // XMRIG_TLSGEN_H diff --git a/src/base/net/tools/Storage.h b/src/base/net/tools/Storage.h index e23e8666..390101c3 100644 --- a/src/base/net/tools/Storage.h +++ b/src/base/net/tools/Storage.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright 2018-2023 SChernykh + * Copyright 2016-2023 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 @@ -42,7 +42,7 @@ class Storage } - inline void *ptr(uintptr_t id) { return reinterpret_cast(id); } + inline TYPE *ptr(uintptr_t id) { return reinterpret_cast(id); } inline TYPE *get(const void *id) const { return get(reinterpret_cast(id)); } @@ -56,6 +56,9 @@ class Storage return m_data.at(id); } + inline bool isEmpty() const { return m_data.empty(); } + inline size_t size() const { return m_data.size(); } + inline void remove(const void *id) { delete release(reinterpret_cast(id)); } inline void remove(uintptr_t id) { delete release(id); } diff --git a/src/base/tools/Object.h b/src/base/tools/Object.h index 00bd9315..f67464ab 100644 --- a/src/base/tools/Object.h +++ b/src/base/tools/Object.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 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 @@ -20,7 +20,9 @@ #define XMRIG_OBJECT_H -#include +#include +#include +#include namespace xmrig { @@ -41,6 +43,7 @@ namespace xmrig { X &operator=(X &&other) = delete; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_OBJECT_H */ + +#endif // XMRIG_OBJECT_H From c5e94e1ea472c023371bc436e2d6c93465f23590 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 3 Apr 2023 14:44:49 +0200 Subject: [PATCH 3/4] Added view tag calculation --- src/base/net/stratum/DaemonClient.cpp | 21 +++++++++++++++++---- src/base/net/stratum/DaemonClient.h | 2 +- src/base/net/stratum/Job.cpp | 17 +++++++++++++---- src/base/net/stratum/Job.h | 8 ++++++-- src/base/tools/cryptonote/Signatures.cpp | 18 +++++++++++++++++- src/base/tools/cryptonote/Signatures.h | 2 +- src/net/JobResult.cpp | 3 ++- src/net/JobResult.h | 3 ++- src/proxy/Miner.cpp | 8 ++++++-- src/proxy/Miner.h | 1 + src/proxy/events/SubmitEvent.h | 8 ++++---- 11 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 10c04116..9b1cdc42 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -148,6 +148,11 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result) memcpy(data + sig_offset * 2, result.sig, 64 * 2); memcpy(data + m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) * 2, result.sig_data, 32 * 2); memcpy(data + m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) * 2, result.sig_data + 32 * 2, 32 * 2); + + // Handle view tag for txout_to_tagged_key outputs + if (m_blocktemplate.outputType() == 3) { + Cvt::toHex(data + m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) * 2 + 32 * 2, 2, &result.view_tag, 1); + } } if (result.extra_nonce >= 0) { @@ -178,7 +183,10 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result) m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend); # endif - return rpcSend(doc); + std::map headers; + headers.insert({"X-Hash-Difficulty", std::to_string(result.actualDiff())}); + + return rpcSend(doc, headers); } @@ -401,7 +409,8 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) - k, m_blocktemplate.offset(BlockTemplate::TX_EXTRA_NONCE_OFFSET) - k, m_blocktemplate.txExtraNonce().size(), - m_blocktemplate.minerTxMerkleTreeBranch() + m_blocktemplate.minerTxMerkleTreeBranch(), + m_blocktemplate.outputType() == 3 ); # endif @@ -438,7 +447,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) } uint8_t derivation[32]; - if (!generate_key_derivation(m_blocktemplate.blob(BlockTemplate::TX_PUBKEY_OFFSET), secret_viewkey, derivation)) { + if (!generate_key_derivation(m_blocktemplate.blob(BlockTemplate::TX_PUBKEY_OFFSET), secret_viewkey, derivation, nullptr)) { return jobError("Failed to generate key derivation for miner signature."); } @@ -553,9 +562,13 @@ int64_t xmrig::DaemonClient::getBlockTemplate() } -int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc) +int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc, const std::map &headers) { FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet()); + for (const auto &header : headers) { + req.headers.insert(header); + } + fetch(tag(), std::move(req), m_httpListener); return m_sequence++; diff --git a/src/base/net/stratum/DaemonClient.h b/src/base/net/stratum/DaemonClient.h index 94d2b973..e852f428 100644 --- a/src/base/net/stratum/DaemonClient.h +++ b/src/base/net/stratum/DaemonClient.h @@ -86,7 +86,7 @@ class DaemonClient : public BaseClient, public IDnsListener, public ITimerListen bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); int64_t getBlockTemplate(); - int64_t rpcSend(const rapidjson::Document &doc); + int64_t rpcSend(const rapidjson::Document &doc, const std::map &headers = {}); void retry(); void send(const char *path); void setState(SocketState state); diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 56f5de80..d62e00b1 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -245,6 +245,7 @@ void xmrig::Job::copy(const Job &other) m_minerTxExtraNonceOffset = other.m_minerTxExtraNonceOffset; m_minerTxExtraNonceSize = other.m_minerTxExtraNonceSize; m_minerTxMerkleTreeBranch = other.m_minerTxMerkleTreeBranch; + m_hasViewTag = other.m_hasViewTag; # else memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey)); memcpy(m_ephSecretKey, other.m_ephSecretKey, sizeof(m_ephSecretKey)); @@ -300,6 +301,7 @@ void xmrig::Job::move(Job &&other) m_minerTxExtraNonceOffset = other.m_minerTxExtraNonceOffset; m_minerTxExtraNonceSize = other.m_minerTxExtraNonceSize; m_minerTxMerkleTreeBranch = std::move(other.m_minerTxMerkleTreeBranch); + m_hasViewTag = other.m_hasViewTag; # else memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey)); memcpy(m_ephSecretKey, other.m_ephSecretKey, sizeof(m_ephSecretKey)); @@ -323,7 +325,7 @@ void xmrig::Job::setSpendSecretKey(const uint8_t *key) } -void xmrig::Job::setMinerTx(const uint8_t *begin, const uint8_t *end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer &minerTxMerkleTreeBranch) +void xmrig::Job::setMinerTx(const uint8_t *begin, const uint8_t *end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer &minerTxMerkleTreeBranch, bool hasViewTag) { m_minerTxPrefix.assign(begin, end); m_minerTxEphPubKeyOffset = minerTxEphPubKeyOffset; @@ -331,6 +333,13 @@ void xmrig::Job::setMinerTx(const uint8_t *begin, const uint8_t *end, size_t min m_minerTxExtraNonceOffset = minerTxExtraNonceOffset; m_minerTxExtraNonceSize = minerTxExtraNonceSize; m_minerTxMerkleTreeBranch = minerTxMerkleTreeBranch; + m_hasViewTag = hasViewTag; +} + + +void xmrig::Job::setViewTagInMinerTx(uint8_t view_tag) +{ + memcpy(m_minerTxPrefix.data() + m_minerTxEphPubKeyOffset + 32, &view_tag, 1); } @@ -340,7 +349,7 @@ void xmrig::Job::setExtraNonceInMinerTx(uint32_t extra_nonce) } -void xmrig::Job::generateSignatureData(String &signatureData) const +void xmrig::Job::generateSignatureData(String &signatureData, uint8_t& view_tag) const { uint8_t* eph_public_key = m_minerTxPrefix.data() + m_minerTxEphPubKeyOffset; uint8_t* txkey_pub = m_minerTxPrefix.data() + m_minerTxPubKeyOffset; @@ -351,14 +360,14 @@ void xmrig::Job::generateSignatureData(String &signatureData) const uint8_t derivation[32]; - generate_key_derivation(m_viewPublicKey, txkey_sec, derivation); + generate_key_derivation(m_viewPublicKey, txkey_sec, derivation, &view_tag); derive_public_key(derivation, 0, m_spendPublicKey, eph_public_key); uint8_t buf[32 * 3] = {}; memcpy(buf, txkey_pub, 32); memcpy(buf + 32, eph_public_key, 32); - generate_key_derivation(txkey_pub, m_viewSecretKey, derivation); + generate_key_derivation(txkey_pub, m_viewSecretKey, derivation, nullptr); derive_secret_key(derivation, 0, m_spendSecretKey, buf + 64); signatureData = Cvt::toHex(buf, sizeof(buf)); diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index e314a266..1ecff369 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -120,10 +120,13 @@ class Job # endif # ifdef XMRIG_PROXY_PROJECT + inline bool hasViewTag() const { return m_hasViewTag; } + void setSpendSecretKey(const uint8_t* key); - void setMinerTx(const uint8_t* begin, const uint8_t* end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer& minerTxMerkleTreeBranch); + void setMinerTx(const uint8_t* begin, const uint8_t* end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer& minerTxMerkleTreeBranch, bool hasViewTag); + void setViewTagInMinerTx(uint8_t view_tag); void setExtraNonceInMinerTx(uint32_t extra_nonce); - void generateSignatureData(String& signatureData) const; + void generateSignatureData(String& signatureData, uint8_t& view_tag) const; void generateHashingBlob(String& blob) const; # else inline const uint8_t* ephSecretKey() const { return m_hasMinerSignature ? m_ephSecretKey : nullptr; } @@ -178,6 +181,7 @@ class Job size_t m_minerTxExtraNonceOffset = 0; size_t m_minerTxExtraNonceSize = 0; Buffer m_minerTxMerkleTreeBranch; + bool m_hasViewTag = false; # else // Miner signatures uint8_t m_ephPublicKey[32]{}; diff --git a/src/base/tools/cryptonote/Signatures.cpp b/src/base/tools/cryptonote/Signatures.cpp index 93571258..13f0c948 100644 --- a/src/base/tools/cryptonote/Signatures.cpp +++ b/src/base/tools/cryptonote/Signatures.cpp @@ -147,7 +147,7 @@ bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8 } -bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation) +bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation, uint8_t* view_tag) { ge_p3 point; ge_p2 point2; @@ -162,6 +162,22 @@ bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* ge_p1p1_to_p2(&point2, &point3); ge_tobytes(derivation, &point2); + if (view_tag) { + constexpr uint8_t salt[] = "view_tag"; + constexpr size_t SALT_SIZE = sizeof(salt) - 1; + + uint8_t buf[SALT_SIZE + 32 + 1]; + memcpy(buf, salt, SALT_SIZE); + memcpy(buf + SALT_SIZE, derivation, 32); + + // Assuming output_index == 0 + buf[SALT_SIZE + 32] = 0; + + uint8_t view_tag_full[32]; + xmrig::keccak(buf, sizeof(buf), view_tag_full, sizeof(view_tag_full)); + *view_tag = view_tag_full[0]; + } + return true; } diff --git a/src/base/tools/cryptonote/Signatures.h b/src/base/tools/cryptonote/Signatures.h index 04813313..24ea9ac6 100644 --- a/src/base/tools/cryptonote/Signatures.h +++ b/src/base/tools/cryptonote/Signatures.h @@ -31,7 +31,7 @@ namespace xmrig { void generate_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sec, uint8_t* sig); bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sig); -bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation); +bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation, uint8_t* view_tag); void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); bool derive_public_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); diff --git a/src/net/JobResult.cpp b/src/net/JobResult.cpp index 91501025..37db9c2f 100644 --- a/src/net/JobResult.cpp +++ b/src/net/JobResult.cpp @@ -25,12 +25,13 @@ #include -xmrig::JobResult::JobResult(int64_t id, const char *jobId, const char *nonce, const char *result, const xmrig::Algorithm &algorithm, const char* sig, const char* sig_data, int64_t extra_nonce) : +xmrig::JobResult::JobResult(int64_t id, const char *jobId, const char *nonce, const char *result, const xmrig::Algorithm &algorithm, const char* sig, const char* sig_data, uint8_t view_tag, int64_t extra_nonce) : algorithm(algorithm), nonce(nonce), result(result), sig(sig), sig_data(sig_data), + view_tag(view_tag), id(id), extra_nonce(extra_nonce), jobId(jobId) diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 9996caac..a7feb762 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -37,7 +37,7 @@ class JobResult static constexpr uint32_t backend = 0; JobResult() = default; - JobResult(int64_t id, const char *jobId, const char *nonce, const char *result, const xmrig::Algorithm &algorithm, const char* sig, const char* sig_data, int64_t extra_nonce); + JobResult(int64_t id, const char *jobId, const char *nonce, const char *result, const xmrig::Algorithm &algorithm, const char* sig, const char* sig_data, uint8_t view_tag, int64_t extra_nonce); bool isCompatible(uint8_t fixedByte) const; bool isValid() const; @@ -49,6 +49,7 @@ class JobResult const char *result = nullptr; const char *sig = nullptr; const char *sig_data = nullptr; + const uint8_t view_tag = 0; const int64_t id = 0; const int64_t extra_nonce = -1; String jobId; diff --git a/src/proxy/Miner.cpp b/src/proxy/Miner.cpp index 6b78ff65..c7be63d3 100644 --- a/src/proxy/Miner.cpp +++ b/src/proxy/Miner.cpp @@ -162,12 +162,16 @@ void xmrig::Miner::setJob(Job &job, int64_t extra_nonce) String tmp_blob; if (job.hasMinerSignature()) { - job.generateSignatureData(m_signatureData); + job.generateSignatureData(m_signatureData, m_viewTag); } else if (!job.rawSigKey().isNull()) { m_signatureData = job.rawSigKey(); } + if (job.hasViewTag()) { + job.setViewTagInMinerTx(m_viewTag); + } + if (extra_nonce >= 0) { m_extraNonce = extra_nonce; job.setExtraNonceInMinerTx(static_cast(m_extraNonce)); @@ -250,7 +254,7 @@ bool xmrig::Miner::parseRequest(int64_t id, const char *method, const rapidjson: Algorithm algorithm(Json::getString(params, "algo")); - SubmitEvent *event = SubmitEvent::create(this, id, Json::getString(params, "job_id"), Json::getString(params, "nonce"), Json::getString(params, "result"), algorithm, Json::getString(params, "sig"), m_signatureData, m_extraNonce); + SubmitEvent *event = SubmitEvent::create(this, id, Json::getString(params, "job_id"), Json::getString(params, "nonce"), Json::getString(params, "result"), algorithm, Json::getString(params, "sig"), m_signatureData, m_viewTag, m_extraNonce); if (!event->request.isValid() || event->request.actualDiff() < diff()) { event->reject(Error::LowDifficulty); diff --git a/src/proxy/Miner.h b/src/proxy/Miner.h index 932038b5..7ce4f451 100644 --- a/src/proxy/Miner.h +++ b/src/proxy/Miner.h @@ -147,6 +147,7 @@ class Miner : public ILineListener String m_rigId; String m_user; String m_signatureData; + uint8_t m_viewTag; Tls *m_tls = nullptr; uint16_t m_localPort; uint64_t m_customDiff = 0; diff --git a/src/proxy/events/SubmitEvent.h b/src/proxy/events/SubmitEvent.h index 55460a81..cf5fd052 100644 --- a/src/proxy/events/SubmitEvent.h +++ b/src/proxy/events/SubmitEvent.h @@ -37,9 +37,9 @@ namespace xmrig { class SubmitEvent : public MinerEvent { public: - static inline SubmitEvent *create(Miner *miner, int64_t id, const char *jobId, const char *nonce, const char *result, const Algorithm &algorithm, const char* sig, const char* sig_data, int64_t extra_nonce) + static inline SubmitEvent *create(Miner *miner, int64_t id, const char *jobId, const char *nonce, const char *result, const Algorithm &algorithm, const char* sig, const char* sig_data, uint8_t view_tag, int64_t extra_nonce) { - return new (m_buf) SubmitEvent(miner, id, jobId, nonce, result, algorithm, sig, sig_data, extra_nonce); + return new (m_buf) SubmitEvent(miner, id, jobId, nonce, result, algorithm, sig, sig_data, view_tag, extra_nonce); } @@ -54,9 +54,9 @@ class SubmitEvent : public MinerEvent protected: - inline SubmitEvent(Miner *miner, int64_t id, const char *jobId, const char *nonce, const char *result, const Algorithm &algorithm, const char* sig, const char* sig_data, int64_t extra_nonce) + inline SubmitEvent(Miner *miner, int64_t id, const char *jobId, const char *nonce, const char *result, const Algorithm &algorithm, const char* sig, const char* sig_data, uint8_t view_tag, int64_t extra_nonce) : MinerEvent(SubmitType, miner), - request(id, jobId, nonce, result, algorithm, sig, sig_data, extra_nonce), + request(id, jobId, nonce, result, algorithm, sig, sig_data, view_tag, extra_nonce), m_error(Error::NoError) {} From 67a99bc50ccd9ec98be3c4641582bc3730fe8dac Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 3 Apr 2023 20:45:10 +0700 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 655682cb..dd93770a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v6.19.2 +- [#532](https://github.com/xmrig/xmrig-proxy/pull/532) Added view tag calculation (fixes Wownero solo mining issue). +- Sync with latest XMRig. + # v6.19.0 - [#530](https://github.com/xmrig/xmrig-proxy/pull/530) Sync with latest XMRig.