mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-10 21:04:37 +00:00
Make single thread bench cheat-resistant
Each hash is dependent on the previous hash to make multi-threaded cheating impossible.
This commit is contained in:
parent
0d3c2752c9
commit
c10ec90b60
11 changed files with 43 additions and 15 deletions
|
@ -35,6 +35,7 @@ namespace xmrig {
|
||||||
|
|
||||||
class VirtualMemory;
|
class VirtualMemory;
|
||||||
class Job;
|
class Job;
|
||||||
|
class Config;
|
||||||
|
|
||||||
|
|
||||||
class IWorker
|
class IWorker
|
||||||
|
@ -48,7 +49,7 @@ public:
|
||||||
virtual size_t intensity() const = 0;
|
virtual size_t intensity() const = 0;
|
||||||
virtual uint64_t rawHashes() const = 0;
|
virtual uint64_t rawHashes() const = 0;
|
||||||
virtual void getHashrateData(uint64_t&, uint64_t&) const = 0;
|
virtual void getHashrateData(uint64_t&, uint64_t&) const = 0;
|
||||||
virtual void start() = 0;
|
virtual void start(Config*) = 0;
|
||||||
virtual void jobEarlyNotification(const Job&) = 0;
|
virtual void jobEarlyNotification(const Job&) = 0;
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
|
|
@ -390,7 +390,7 @@ void xmrig::CpuBackend::start(IWorker *worker, bool ready)
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
|
||||||
if (ready) {
|
if (ready) {
|
||||||
worker->start();
|
worker->start(d_ptr->controller->config());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "backend/cpu/CpuWorker.h"
|
#include "backend/cpu/CpuWorker.h"
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
|
#include "core/config/Config.h"
|
||||||
#include "core/Miner.h"
|
#include "core/Miner.h"
|
||||||
#include "crypto/cn/CnCtx.h"
|
#include "crypto/cn/CnCtx.h"
|
||||||
#include "crypto/cn/CryptoNight_test.h"
|
#include "crypto/cn/CryptoNight_test.h"
|
||||||
|
@ -198,7 +199,7 @@ bool xmrig::CpuWorker<N>::selfTest()
|
||||||
|
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
void xmrig::CpuWorker<N>::start()
|
void xmrig::CpuWorker<N>::start(xmrig::Config* config)
|
||||||
{
|
{
|
||||||
while (Nonce::sequence(Nonce::CPU) > 0) {
|
while (Nonce::sequence(Nonce::CPU) > 0) {
|
||||||
if (Nonce::isPaused()) {
|
if (Nonce::isPaused()) {
|
||||||
|
@ -219,6 +220,10 @@ void xmrig::CpuWorker<N>::start()
|
||||||
alignas(16) uint64_t tempHash[8] = {};
|
alignas(16) uint64_t tempHash[8] = {};
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
const size_t benchThreads = config->cpu().threads().get(m_job.currentJob().algorithm()).count();
|
||||||
|
# endif
|
||||||
|
|
||||||
while (!Nonce::isOutdated(Nonce::CPU, m_job.sequence())) {
|
while (!Nonce::isOutdated(Nonce::CPU, m_job.sequence())) {
|
||||||
const Job &job = m_job.currentJob();
|
const Job &job = m_job.currentJob();
|
||||||
|
|
||||||
|
@ -231,6 +236,29 @@ void xmrig::CpuWorker<N>::start()
|
||||||
current_job_nonces[i] = *m_job.nonce(i);
|
current_job_nonces[i] = *m_job.nonce(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
if (m_benchSize) {
|
||||||
|
bool done = true;
|
||||||
|
for (size_t i = 0; i < N; ++i) {
|
||||||
|
if (current_job_nonces[i] < m_benchSize) {
|
||||||
|
done = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop benchmark when all hashes have been counted
|
||||||
|
if (done) {
|
||||||
|
m_benchDoneTime = Chrono::steadyMSecs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make each hash dependent on the previous one in single thread benchmark to prevent cheating with multiple threads
|
||||||
|
if (benchThreads == 1) {
|
||||||
|
*(uint64_t*)(m_job.blob()) ^= m_benchData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_RANDOMX
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
|
@ -274,10 +302,6 @@ void xmrig::CpuWorker<N>::start()
|
||||||
if (current_job_nonces[i] < m_benchSize) {
|
if (current_job_nonces[i] < m_benchSize) {
|
||||||
m_benchData ^= value;
|
m_benchData ^= value;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
m_benchDoneTime = Chrono::steadyMSecs();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif
|
# endif
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class RxVm;
|
class RxVm;
|
||||||
|
class Config;
|
||||||
|
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
|
@ -56,7 +57,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool selfTest() override;
|
bool selfTest() override;
|
||||||
void start() override;
|
void start(Config*) override;
|
||||||
|
|
||||||
inline const VirtualMemory *memory() const override { return m_memory; }
|
inline const VirtualMemory *memory() const override { return m_memory; }
|
||||||
inline size_t intensity() const override { return N; }
|
inline size_t intensity() const override { return N; }
|
||||||
|
|
|
@ -481,7 +481,7 @@ void xmrig::CudaBackend::start(IWorker *worker, bool ready)
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
|
||||||
if (ready) {
|
if (ready) {
|
||||||
worker->start();
|
worker->start(d_ptr->controller->config());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ size_t xmrig::CudaWorker::intensity() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::CudaWorker::start()
|
void xmrig::CudaWorker::start(xmrig::Config*)
|
||||||
{
|
{
|
||||||
while (Nonce::sequence(Nonce::CUDA) > 0) {
|
while (Nonce::sequence(Nonce::CUDA) > 0) {
|
||||||
if (!isReady()) {
|
if (!isReady()) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class ICudaRunner;
|
class ICudaRunner;
|
||||||
|
class Config;
|
||||||
|
|
||||||
|
|
||||||
class CudaWorker : public Worker
|
class CudaWorker : public Worker
|
||||||
|
@ -58,7 +59,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
bool selfTest() override;
|
bool selfTest() override;
|
||||||
size_t intensity() const override;
|
size_t intensity() const override;
|
||||||
void start() override;
|
void start(Config*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool consumeJob();
|
bool consumeJob();
|
||||||
|
|
|
@ -463,7 +463,7 @@ void xmrig::OclBackend::start(IWorker *worker, bool ready)
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
|
||||||
if (ready) {
|
if (ready) {
|
||||||
worker->start();
|
worker->start(d_ptr->controller->config());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ size_t xmrig::OclWorker::intensity() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::OclWorker::start()
|
void xmrig::OclWorker::start(xmrig::Config*)
|
||||||
{
|
{
|
||||||
cl_uint results[0x100];
|
cl_uint results[0x100];
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace xmrig {
|
||||||
|
|
||||||
class IOclRunner;
|
class IOclRunner;
|
||||||
class Job;
|
class Job;
|
||||||
|
class Config;
|
||||||
|
|
||||||
|
|
||||||
class OclWorker : public Worker
|
class OclWorker : public Worker
|
||||||
|
@ -59,7 +60,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
bool selfTest() override;
|
bool selfTest() override;
|
||||||
size_t intensity() const override;
|
size_t intensity() const override;
|
||||||
void start() override;
|
void start(Config*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool consumeJob();
|
bool consumeJob();
|
||||||
|
|
|
@ -297,7 +297,7 @@ namespace randomx {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JitCompilerX86::generateProgramPrologue(Program& prog, ProgramConfiguration& pcfg) {
|
void JitCompilerX86::generateProgramPrologue(Program& prog, ProgramConfiguration& pcfg) {
|
||||||
codePos = ((uint8_t*)randomx_program_prologue_first_load) - ((uint8_t*)randomx_program_prologue);
|
codePos = ADDR(randomx_program_prologue_first_load) - ADDR(randomx_program_prologue);
|
||||||
code[codePos + 2] = 0xc0 + pcfg.readReg0;
|
code[codePos + 2] = 0xc0 + pcfg.readReg0;
|
||||||
code[codePos + 5] = 0xc0 + pcfg.readReg1;
|
code[codePos + 5] = 0xc0 + pcfg.readReg1;
|
||||||
*(uint32_t*)(code + codePos + 10) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated;
|
*(uint32_t*)(code + codePos + 10) = RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated;
|
||||||
|
|
Loading…
Reference in a new issue