From 3f8720fabe0b06e5c14f0f6a7b491c61287b0cb5 Mon Sep 17 00:00:00 2001 From: Michael Toutonghi Date: Fri, 20 Jul 2018 20:57:28 -0700 Subject: [PATCH] Fix new nonce issue --- src/hash.h | 2 ++ src/primitives/nonce.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hash.h b/src/hash.h index 537ba3dcb..d288af305 100644 --- a/src/hash.h +++ b/src/hash.h @@ -204,6 +204,7 @@ public: int nVersion; CVerusHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn), state() { } + void Reset() { state.Reset(); } CVerusHashWriter& write(const char *pch, size_t size) { state.Write((const unsigned char*)pch, size); @@ -239,6 +240,7 @@ public: int nVersion; CVerusHashV2Writer(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn), state() {} + void Reset() { state.Reset(); } CVerusHashV2Writer& write(const char *pch, size_t size) { state.Write((const unsigned char*)pch, size); diff --git a/src/primitives/nonce.cpp b/src/primitives/nonce.cpp index 58970a80f..6ff258174 100644 --- a/src/primitives/nonce.cpp +++ b/src/primitives/nonce.cpp @@ -46,10 +46,10 @@ void CPOSNonce::SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t vou // printf("before %s\n", ArithToUint256(arNonce).GetHex().c_str()); - CVerusHashWriter newWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - newWriter << ArithToUint256(arNonce); + hashWriter.Reset(); + hashWriter << ArithToUint256(arNonce); - *this = CPOSNonce(ArithToUint256((UintToArith256(newWriter.GetHash()) << 128) | arNonce)); + *this = CPOSNonce(ArithToUint256((UintToArith256(hashWriter.GetHash()) << 128) | arNonce)); // printf("after %s\n", this->GetHex().c_str()); } @@ -67,7 +67,7 @@ bool CPOSNonce::CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t v arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) | (UintToArith256(hashWriter.GetHash()) & entropyMask); - hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); + hashWriter.Reset(); hashWriter << ArithToUint256(arNonce); return UintToArith256(*this) == (UintToArith256(hashWriter.GetHash()) << 128 | arNonce);