From af019fed8e25ca5ef0a95614717e6cd3efdae5d1 Mon Sep 17 00:00:00 2001
From: XMRig <support@xmrig.com>
Date: Mon, 11 Jan 2021 18:29:56 +0700
Subject: [PATCH 1/5] v6.7.2-dev

---
 src/version.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/version.h b/src/version.h
index 1f69d3ffd..159b29d6a 100644
--- a/src/version.h
+++ b/src/version.h
@@ -28,7 +28,7 @@
 #define APP_ID        "xmrig"
 #define APP_NAME      "XMRig"
 #define APP_DESC      "XMRig miner"
-#define APP_VERSION   "6.7.1"
+#define APP_VERSION   "6.7.2-dev"
 #define APP_DOMAIN    "xmrig.com"
 #define APP_SITE      "www.xmrig.com"
 #define APP_COPYRIGHT "Copyright (C) 2016-2021 xmrig.com"
@@ -36,7 +36,7 @@
 
 #define APP_VER_MAJOR  6
 #define APP_VER_MINOR  7
-#define APP_VER_PATCH  0
+#define APP_VER_PATCH  2
 
 #ifdef _MSC_VER
 #   if (_MSC_VER >= 1920)

From 5c449913afcfee17f40418980be9ae297a17b846 Mon Sep 17 00:00:00 2001
From: SChernykh <sergey.v.chernykh@gmail.com>
Date: Fri, 15 Jan 2021 11:18:36 +0100
Subject: [PATCH 2/5] Fixed solo mining

It was broken since 6.7.0
---
 src/base/net/stratum/DaemonClient.cpp | 4 ++--
 src/base/tools/Cvt.cpp                | 7 +++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp
index 8b4d0fb69..554ee8a89 100644
--- a/src/base/net/stratum/DaemonClient.cpp
+++ b/src/base/net/stratum/DaemonClient.cpp
@@ -104,7 +104,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
 #   ifdef XMRIG_PROXY_PROJECT
     memcpy(data + 78, result.nonce, 8);
 #   else
-    Cvt::toHex(data + 78, 9, reinterpret_cast<const uint8_t *>(&result.nonce), 4);
+    Cvt::toHex(data + 78, 8, reinterpret_cast<const uint8_t *>(&result.nonce), 4);
 #   endif
 
     using namespace rapidjson;
@@ -227,7 +227,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
     m_blockhashingblob = Json::getString(params, "blockhashing_blob");
     if (m_apiVersion == API_DERO) {
         const uint64_t offset = Json::getUint64(params, "reserved_offset");
-        Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2 + 1, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
+        Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
     }
 
     if (blocktemplate.isNull() || !job.setBlob(m_blockhashingblob)) {
diff --git a/src/base/tools/Cvt.cpp b/src/base/tools/Cvt.cpp
index c80c022c0..0c9cdbf1e 100644
--- a/src/base/tools/Cvt.cpp
+++ b/src/base/tools/Cvt.cpp
@@ -46,7 +46,7 @@ static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigne
     int          b;
     int          c;
 
-    if (bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U) {
+    if (bin_len >= SIZE_MAX / 2 || hex_maxlen < bin_len * 2U) {
         return nullptr; /* LCOV_EXCL_LINE */
     }
 
@@ -60,7 +60,10 @@ static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigne
         hex[i * 2U + 1U] = (char) x;
         i++;
     }
-    hex[i * 2U] = 0U;
+
+    if (i * 2U < hex_maxlen) {
+        hex[i * 2U] = 0U;
+    }
 
     return hex;
 }

From 7da04c6a2c1e3ffd7c858bc472678a819190977a Mon Sep 17 00:00:00 2001
From: SChernykh <sergey.v.chernykh@gmail.com>
Date: Fri, 15 Jan 2021 12:46:27 +0100
Subject: [PATCH 3/5] Always use cvt_bin2hex

---
 src/base/tools/Cvt.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/base/tools/Cvt.cpp b/src/base/tools/Cvt.cpp
index 0c9cdbf1e..be46bc0c5 100644
--- a/src/base/tools/Cvt.cpp
+++ b/src/base/tools/Cvt.cpp
@@ -140,7 +140,6 @@ static int cvt_hex2bin(unsigned char *const bin, const size_t bin_maxlen, const
     return ret;
 }
 
-#define sodium_bin2hex cvt_bin2hex
 #define sodium_hex2bin cvt_hex2bin
 #endif
 
@@ -218,7 +217,7 @@ xmrig::Buffer xmrig::Cvt::fromHex(const char *in, size_t size)
 
 bool xmrig::Cvt::toHex(char *hex, size_t hex_maxlen, const uint8_t *bin, size_t bin_len)
 {
-    return sodium_bin2hex(hex, hex_maxlen, bin, bin_len) != nullptr;
+    return cvt_bin2hex(hex, hex_maxlen, bin, bin_len) != nullptr;
 }
 
 

From 45d12314f41e0d04710e32a1f4a6375f8818e64a Mon Sep 17 00:00:00 2001
From: XMRig <support@xmrig.com>
Date: Fri, 15 Jan 2021 19:18:52 +0700
Subject: [PATCH 4/5] Sync changes.

---
 src/base/tools/Cvt.cpp | 28 +++++++++++++++++++++-------
 src/base/tools/Cvt.h   |  5 +++--
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/base/tools/Cvt.cpp b/src/base/tools/Cvt.cpp
index be46bc0c5..18d5e627a 100644
--- a/src/base/tools/Cvt.cpp
+++ b/src/base/tools/Cvt.cpp
@@ -1,7 +1,7 @@
 /* XMRig
  * Copyright (c) 2013-2020 Frank Denis <j at pureftpd dot org>
- * Copyright (c) 2018-2020 SChernykh   <https://github.com/SChernykh>
- * Copyright (c) 2016-2020 XMRig       <https://github.com/xmrig>, <support@xmrig.com>
+ * Copyright (c) 2018-2021 SChernykh   <https://github.com/SChernykh>
+ * Copyright (c) 2016-2021 XMRig       <https://github.com/xmrig>, <support@xmrig.com>
  *
  *   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,11 +34,6 @@
 namespace xmrig {
 
 
-#ifndef XMRIG_SODIUM
-static std::random_device randomDevice;
-static std::mt19937 randomEngine(randomDevice());
-
-
 static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigned char *const bin, const size_t bin_len)
 {
     size_t       i = 0U;
@@ -69,6 +64,11 @@ static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigne
 }
 
 
+#ifndef XMRIG_SODIUM
+static std::random_device randomDevice;
+static std::mt19937 randomEngine(randomDevice());
+
+
 static int cvt_hex2bin(unsigned char *const bin, const size_t bin_maxlen, const char *const hex, const size_t hex_len, const char *const ignore, size_t *const bin_len, const char **const hex_end)
 {
     size_t        bin_pos = 0U;
@@ -275,3 +275,17 @@ xmrig::String xmrig::Cvt::toHex(const uint8_t *in, size_t size)
 
     return buf;
 }
+
+
+void xmrig::Cvt::randomBytes(void *buf, size_t size)
+{
+#   ifndef XMRIG_SODIUM
+    std::uniform_int_distribution<> dis(0, 255);
+
+    for (size_t i = 0; i < size; ++i) {
+        static_cast<uint8_t *>(buf)[i] = static_cast<char>(dis(randomEngine));
+    }
+#   else
+    randombytes_buf(buf, size);
+#   endif
+}
diff --git a/src/base/tools/Cvt.h b/src/base/tools/Cvt.h
index 8b67b1466..e7507aafd 100644
--- a/src/base/tools/Cvt.h
+++ b/src/base/tools/Cvt.h
@@ -1,6 +1,6 @@
 /* XMRig
- * Copyright (c) 2018-2020 SChernykh   <https://github.com/SChernykh>
- * Copyright (c) 2016-2020 XMRig       <https://github.com/xmrig>, <support@xmrig.com>
+ * Copyright (c) 2018-2021 SChernykh   <https://github.com/SChernykh>
+ * Copyright (c) 2016-2021 XMRig       <https://github.com/xmrig>, <support@xmrig.com>
  *
  *   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
@@ -52,6 +52,7 @@ public:
     static rapidjson::Value toHex(const std::string &data, rapidjson::Document &doc);
     static rapidjson::Value toHex(const uint8_t *in, size_t size, rapidjson::Document &doc);
     static String toHex(const uint8_t *in, size_t size);
+    static void randomBytes(void *buf, size_t size);
 };
 
 

From eae84d47e769523a37b651de887cefecee1f1a80 Mon Sep 17 00:00:00 2001
From: xmrig <support@xmrig.com>
Date: Fri, 15 Jan 2021 19:30:22 +0700
Subject: [PATCH 5/5] Update CHANGELOG.md

---
 CHANGELOG.md | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 25fd77aff..708d712ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+# v6.7.2
+- [#2039](https://github.com/xmrig/xmrig/pull/2039) Fixed solo mining.
+
 # v6.7.1
 - [#1995](https://github.com/xmrig/xmrig/issues/1995) Fixed log initialization.
 - [#1998](https://github.com/xmrig/xmrig/pull/1998) Added hashrate in the benchmark finished message.