Use Rust Equihash validator unconditionally

It correctly validates all blocks prior to Heartwood activation.
This commit is contained in:
Jack Grigg 2020-07-14 23:01:42 +12:00
parent 54180fbce5
commit 79846ac1f3
1 changed files with 5 additions and 26 deletions

View File

@ -14,7 +14,6 @@
#include "uint256.h"
#include <librustzcash.h>
#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)