From 3dfeed475f92db33d7826c571eff250e8276507a Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 6 Aug 2024 23:32:20 +0700 Subject: [PATCH] Sync changes with the proxy. --- src/base/net/stratum/Client.cpp | 4 +-- src/base/net/stratum/Job.cpp | 59 +++++++++++++++++---------------- src/base/net/stratum/Job.h | 2 +- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 54246e72..b412a543 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -363,7 +363,7 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) Job job(has(), m_pool.algorithm(), m_rpcId); - if (!job.setId(params["job_id"].GetString())) { + if (!job.setId(Json::getString(params, "job_id"))) { *code = 3; return false; } @@ -400,7 +400,7 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) } } - if (!job.setTarget(params["target"].GetString())) { + if (!job.setTarget(Json::getString(params, "target"))) { *code = 5; return false; } diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index a46473e5..1a7cfbfe 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -110,16 +110,12 @@ bool xmrig::Job::setSeedHash(const char *hash) bool xmrig::Job::setTarget(const char *target) { - static auto parse = [](const char *target, const Algorithm &algorithm) -> uint64_t { - if (!target) { - return 0; - } - + static auto parse = [](const char *target, size_t size, const Algorithm &algorithm) -> uint64_t { if (algorithm == Algorithm::RX_YADA) { return strtoull(target, nullptr, 16); } - const auto raw = Cvt::fromHex(target, strlen(target)); + const auto raw = Cvt::fromHex(target, size); switch (raw.size()) { case 4: @@ -135,23 +131,48 @@ bool xmrig::Job::setTarget(const char *target) return 0; }; - if ((m_target = parse(target, algorithm())) == 0) { + const size_t size = target ? strlen(target) : 0; + + if (size < 4 || (m_target = parse(target, size, algorithm())) == 0) { return false; } m_diff = toDiff(m_target); # ifdef XMRIG_PROXY_PROJECT - assert(sizeof(m_rawTarget) > (size * 2)); + if (size >= sizeof(m_rawTarget)) { + return false; + } memset(m_rawTarget, 0, sizeof(m_rawTarget)); - memcpy(m_rawTarget, target, std::min(size * 2, sizeof(m_rawTarget))); + memcpy(m_rawTarget, target, size); # endif return true; } +size_t xmrig::Job::nonceOffset() const +{ + switch (algorithm().family()) { + case Algorithm::KAWPOW: + return 32; + + case Algorithm::GHOSTRIDER: + return 76; + + default: + break; + } + + if (algorithm() == Algorithm::RX_YADA) { + return 147; + } + + return 39; +} + + void xmrig::Job::setDiff(uint64_t diff) { m_diff = diff; @@ -182,26 +203,6 @@ void xmrig::Job::setSigKey(const char *sig_key) } -int32_t xmrig::Job::nonceOffset() const -{ - switch (algorithm().family()) { - case Algorithm::KAWPOW: - return 32; - - case Algorithm::GHOSTRIDER: - return 76; - - default: - break; - } - - if (algorithm() == Algorithm::RX_YADA) { - return 147; - } - - return 39; -} - uint32_t xmrig::Job::getNumTransactions() const { if (!(m_algorithm.isCN() || m_algorithm.family() == Algorithm::RANDOM_X)) { diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 1bdd5b75..5d29e68e 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -61,6 +61,7 @@ public: bool setBlob(const char *blob); bool setSeedHash(const char *hash); bool setTarget(const char *target); + size_t nonceOffset() const; void setDiff(uint64_t diff); void setSigKey(const char *sig_key); @@ -75,7 +76,6 @@ public: inline const String &poolWallet() const { return m_poolWallet; } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + nonceOffset()); } inline const uint8_t *blob() const { return m_blob; } - int32_t nonceOffset() const; inline size_t nonceSize() const { return (algorithm().family() == Algorithm::KAWPOW) ? 8 : 4; } inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + nonceOffset()); }