KawPow WIP

This commit is contained in:
SChernykh 2020-05-24 23:57:41 +02:00
parent 07025dc41b
commit 22b937cc1c
88 changed files with 11004 additions and 8383 deletions

View file

@ -43,7 +43,7 @@ class JobResult
public:
JobResult() = delete;
inline JobResult(const Job &job, uint32_t nonce, const uint8_t *result) :
inline JobResult(const Job &job, uint64_t nonce, const uint8_t *result, const uint8_t* header_hash = nullptr, const uint8_t *mix_hash = nullptr) :
algorithm(job.algorithm()),
clientId(job.clientId()),
jobId(job.id()),
@ -53,6 +53,14 @@ public:
index(job.index())
{
memcpy(m_result, result, sizeof(m_result));
if (header_hash) {
memcpy(m_headerHash, header_hash, sizeof(m_headerHash));
}
if (mix_hash) {
memcpy(m_mixHash, mix_hash, sizeof(m_mixHash));
}
}
inline JobResult(const Job &job) :
@ -66,20 +74,24 @@ public:
{
}
inline const uint8_t *result() const { return m_result; }
inline uint64_t actualDiff() const { return Job::toDiff(reinterpret_cast<const uint64_t*>(m_result)[3]); }
inline uint8_t *result() { return m_result; }
inline const uint8_t *result() const { return m_result; }
inline uint64_t actualDiff() const { return Job::toDiff(reinterpret_cast<const uint64_t*>(m_result)[3]); }
inline uint8_t *result() { return m_result; }
inline const uint8_t *headerHash() const { return m_headerHash; }
inline const uint8_t *mixHash() const { return m_mixHash; }
const Algorithm algorithm;
const String clientId;
const String jobId;
const uint32_t backend;
const uint32_t nonce;
const uint64_t nonce;
const uint64_t diff;
const uint8_t index;
private:
uint8_t m_result[32] = { 0 };
uint8_t m_result[32] = { 0 };
uint8_t m_headerHash[32] = { 0 };
uint8_t m_mixHash[32] = { 0 };
};

View file

@ -38,6 +38,12 @@
#endif
#ifdef XMRIG_ALGO_KAWPOW
# include "crypto/kawpow/KPCache.h"
# include "crypto/kawpow/KPHash.h"
#endif
#if defined(XMRIG_FEATURE_OPENCL) || defined(XMRIG_FEATURE_CUDA)
# include "base/tools/Baton.h"
# include "crypto/cn/CnCtx.h"
@ -132,6 +138,39 @@ static void getResults(JobBundle &bundle, std::vector<JobResult> &results, uint3
else if (algorithm.family() == Algorithm::ARGON2) {
errors += bundle.nonces.size(); // TODO ARGON2
}
else if (algorithm.family() == Algorithm::KAWPOW) {
# ifdef XMRIG_ALGO_KAWPOW
for (uint32_t nonce : bundle.nonces) {
*bundle.job.nonce() = nonce;
uint8_t header_hash[32];
uint64_t full_nonce;
memcpy(header_hash, bundle.job.blob(), sizeof(header_hash));
memcpy(&full_nonce, bundle.job.blob() + sizeof(header_hash), sizeof(full_nonce));
uint32_t output[8];
uint32_t mix_hash[8];
{
std::lock_guard<std::mutex> lock(KPCache::s_cacheMutex);
KPCache::s_cache.init(bundle.job.height() / KPHash::EPOCH_LENGTH);
KPHash::calculate(KPCache::s_cache, bundle.job.height(), header_hash, full_nonce, output, mix_hash);
}
for (size_t i = 0; i < sizeof(hash); ++i) {
hash[i] = ((uint8_t*)output)[sizeof(hash) - 1 - i];
}
if (*reinterpret_cast<uint64_t*>(hash + 24) < bundle.job.target()) {
results.emplace_back(bundle.job, full_nonce, (uint8_t*)output, bundle.job.blob(), (uint8_t*)mix_hash);
}
else {
LOG_ERR("COMPUTE ERROR"); // TODO Extend information.
++errors;
}
}
# endif
}
else {
cryptonight_ctx *ctx[1];
CnCtx::create(ctx, memory->scratchpad(), memory->size(), 1);