Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xmrig committed Apr 3, 2023
2 parents 58b1c89 + 67a99bc commit 0581081
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 6 additions & 4 deletions src/base/kernel/Platform.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand All @@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "base/kernel/Platform.h"


Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/base/net/dns/DnsRecord.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down Expand Up @@ -46,11 +46,11 @@ xmrig::String xmrig::DnsRecord::ip() const

if (m_type == AAAA) {
buf = new char[45]();
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(m_data), buf, 45);
uv_ip6_name(reinterpret_cast<const sockaddr_in6*>(m_data), buf, 45);
}
else {
buf = new char[16]();
uv_ip4_name(reinterpret_cast<sockaddr_in*>(m_data), buf, 16);
uv_ip4_name(reinterpret_cast<const sockaddr_in*>(m_data), buf, 16);
}

return buf;
Expand Down
29 changes: 18 additions & 11 deletions src/base/net/dns/DnsUvBackend.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down Expand Up @@ -28,18 +28,19 @@

namespace xmrig {

static Storage<DnsUvBackend>* storage = nullptr;

Storage<DnsUvBackend>& DnsUvBackend::getStorage()
static Storage<DnsUvBackend> *storage = nullptr;


Storage<DnsUvBackend> &DnsUvBackend::getStorage()
{
if (storage == nullptr) storage = new Storage<DnsUvBackend>();
if (storage == nullptr) {
storage = new Storage<DnsUvBackend>();
}

return *storage;
}

void DnsUvBackend::releaseStorage()
{
delete storage;
}

static addrinfo hints{};

Expand All @@ -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;
}
}


Expand Down
21 changes: 17 additions & 4 deletions src/base/net/stratum/DaemonClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<std::string, std::string> headers;
headers.insert({"X-Hash-Difficulty", std::to_string(result.actualDiff())});

return rpcSend(doc, headers);
}


Expand Down Expand Up @@ -401,7 +409,8 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, 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

Expand Down Expand Up @@ -438,7 +447,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, 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.");
}

Expand Down Expand Up @@ -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<std::string, std::string> &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++;
Expand Down
2 changes: 1 addition & 1 deletion src/base/net/stratum/DaemonClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DaemonClient : public BaseClient, public IDnsListener, public ITimerListen
bool parseJob(const rapidjson::Value &params, 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<std::string, std::string> &headers = {});
void retry();
void send(const char *path);
void setState(SocketState state);
Expand Down
17 changes: 13 additions & 4 deletions src/base/net/stratum/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -323,14 +325,21 @@ 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;
m_minerTxPubKeyOffset = minerTxPubKeyOffset;
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);
}


Expand All @@ -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;
Expand All @@ -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));
Expand Down
8 changes: 6 additions & 2 deletions src/base/net/stratum/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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]{};
Expand Down
36 changes: 34 additions & 2 deletions src/base/net/tls/TlsContext.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down Expand Up @@ -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[] = {
Expand Down Expand Up @@ -96,6 +97,8 @@ static DH *get_dh2048()

return dh;
}
#endif


} // namespace xmrig

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 5 additions & 7 deletions src/base/net/tls/TlsContext.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand All @@ -24,9 +24,6 @@
#include "base/tools/Object.h"


#include <cstdint>


using SSL_CTX = struct ssl_ctx_st;


Expand Down Expand Up @@ -60,6 +57,7 @@ class TlsContext
};


} /* namespace xmrig */
} // namespace xmrig


#endif /* XMRIG_TLSCONTEXT_H */
#endif // XMRIG_TLSCONTEXT_H
8 changes: 6 additions & 2 deletions src/base/net/tls/TlsGen.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down Expand Up @@ -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;
Expand All @@ -53,6 +54,9 @@ static EVP_PKEY *generate_pkey()
BN_free(exponent);

return pkey;
# else
return EVP_RSA_gen(2048);
# endif
}


Expand Down
Loading

0 comments on commit 0581081

Please sign in to comment.