From 59723e0be5aeb8f5b1f9f97d26307bafe7f5d249 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 17 Nov 2017 16:16:58 +0000 Subject: [PATCH] NH nonce verification --- xmrstak/backend/amd/minethd.cpp | 10 +++++++-- xmrstak/backend/cpu/minethd.cpp | 33 ++++++++++++++++++++++++++---- xmrstak/backend/nvidia/minethd.cpp | 10 +++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/xmrstak/backend/amd/minethd.cpp b/xmrstak/backend/amd/minethd.cpp index c1399e0..313ba84 100644 --- a/xmrstak/backend/amd/minethd.cpp +++ b/xmrstak/backend/amd/minethd.cpp @@ -214,8 +214,8 @@ void minethd::work_main() uint64_t target = oWork.iTarget; XMRSetJob(pGpuCtx, oWork.bWorkBlob, oWork.iWorkSize, target); - if(oWork.bNiceHash) - pGpuCtx->Nonce = *(uint32_t*)(oWork.bWorkBlob + 39); + //if(oWork.bNiceHash) + pGpuCtx->Nonce = 0xEB000000;//*(uint32_t*)(oWork.bWorkBlob + 39); while(globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) { @@ -240,6 +240,12 @@ void minethd::work_main() *(uint32_t*)(bWorkBlob + 39) = results[i]; + if((results[i] | 0xEB000000u) != 0xEB000000u) + { + printf("Invalid NH nonce on AMD - 0x%x\n", results[i]); + exit(0); + } + hash_fun(bWorkBlob, oWork.iWorkSize, bResult, cpu_ctx); if ( (*((uint64_t*)(bResult + 24))) < oWork.iTarget) executor::inst()->push_event(ex_event(job_result(oWork.sJobID, results[i], bResult, iThreadNo), oWork.iPoolId)); diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp index cbb01f9..07e0ab3 100644 --- a/xmrstak/backend/cpu/minethd.cpp +++ b/xmrstak/backend/cpu/minethd.cpp @@ -382,8 +382,9 @@ void minethd::work_main() assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID)); memcpy(result.sJobID, oWork.sJobID, sizeof(job_result::sJobID)); - if(oWork.bNiceHash) - result.iNonce = *piNonce; + //if(oWork.bNiceHash) + // result.iNonce = *piNonce; + result.iNonce = 0xEB000000u; while(globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) { @@ -405,6 +406,13 @@ void minethd::work_main() hash_fun(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); if (*piHashVal < oWork.iTarget) + { + if((result.iNonce | 0xEB000000u) != 0xEB000000u) + { + printf("Invalid NH nonce on CPU SINGLE - 0x%x\n", result.iNonce); + exit(0); + } + executor::inst()->push_event(ex_event(result, oWork.iPoolId)); std::this_thread::yield(); @@ -524,8 +532,9 @@ void minethd::double_work_main() assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID)); - if(oWork.bNiceHash) - iNonce = *piNonce0; + //if(oWork.bNiceHash) + // iNonce = *piNonce0; + iNonce = 0xEB000000u; while (globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) { @@ -550,11 +559,27 @@ void minethd::double_work_main() hash_fun(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1); if (*piHashVal0 < oWork.iTarget) + { executor::inst()->push_event(ex_event(job_result(oWork.sJobID, iNonce-1, bDoubleHashOut, iThreadNo), oWork.iPoolId)); + if((iNonce-1 | 0xEB000000u) != 0xEB000000u) + { + printf("Invalid NH nonce on CPU DOUBLE - 0x%x\n", iNonce-1); + exit(0); + } + } + if (*piHashVal1 < oWork.iTarget) + { executor::inst()->push_event(ex_event(job_result(oWork.sJobID, iNonce, bDoubleHashOut + 32, iThreadNo), oWork.iPoolId)); + if((iNonce | 0xEB000000u) != 0xEB000000u) + { + printf("Invalid NH nonce on CPU DOUBLE - 0x%x\n", iNonce); + exit(0); + } + } + std::this_thread::yield(); } diff --git a/xmrstak/backend/nvidia/minethd.cpp b/xmrstak/backend/nvidia/minethd.cpp index 9eab1c0..1b1b33f 100644 --- a/xmrstak/backend/nvidia/minethd.cpp +++ b/xmrstak/backend/nvidia/minethd.cpp @@ -251,8 +251,8 @@ void minethd::work_main() assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID)); - if(oWork.bNiceHash) - iNonce = *(uint32_t*)(oWork.bWorkBlob + 39); + //if(oWork.bNiceHash) + iNonce = 0xEB000000u;//*(uint32_t*)(oWork.bWorkBlob + 39); while(globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) { @@ -282,6 +282,12 @@ void minethd::work_main() *(uint32_t*)(bWorkBlob + 39) = foundNonce[i]; + if((foundNonce[i] | 0xEB000000u) != 0xEB000000u) + { + printf("Invalid NH nonce on NVIDIA - 0x%x\n", foundNonce[i]; + exit(0); + } + hash_fun(bWorkBlob, oWork.iWorkSize, bResult, cpu_ctx); if ( (*((uint64_t*)(bResult + 24))) < oWork.iTarget) executor::inst()->push_event(ex_event(job_result(oWork.sJobID, foundNonce[i], bResult, iThreadNo), oWork.iPoolId));