From 79846ac1f33ad1c1343463ac83ba864128e0102c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 14 Jul 2020 23:01:42 +1200 Subject: [PATCH] Use Rust Equihash validator unconditionally It correctly validates all blocks prior to Heartwood activation. --- src/pow.cpp | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 0477a59cb..b6e72e13d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -14,7 +14,6 @@ #include "uint256.h" #include -#include "sodium.h" unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -98,37 +97,17 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, int nHeight, const Consen unsigned int n = params.nEquihashN; unsigned int k = params.nEquihashK; - // Hash state - crypto_generichash_blake2b_state state; - EhInitialiseState(n, k, state); - // I = the block header minus nonce and solution. CEquihashInput I{*pblock}; // I||V CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss << I; - // From Heartwood activation, check with the Rust validator - if (params.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_HEARTWOOD)) { - return librustzcash_eh_isvalid( - n, k, - (unsigned char*)&ss[0], ss.size(), - pblock->nNonce.begin(), pblock->nNonce.size(), - pblock->nSolution.data(), pblock->nSolution.size()); - } - - // Before Heartwood activation, check with the C++ validator - ss << pblock->nNonce; - - // H(I||V||... - crypto_generichash_blake2b_update(&state, (unsigned char*)&ss[0], ss.size()); - - bool isValid; - EhIsValidSolution(n, k, state, pblock->nSolution, isValid); - if (!isValid) - return error("CheckEquihashSolution(): invalid solution"); - - return true; + return librustzcash_eh_isvalid( + n, k, + (unsigned char*)&ss[0], ss.size(), + pblock->nNonce.begin(), pblock->nNonce.size(), + pblock->nSolution.data(), pblock->nSolution.size()); } bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)