From 46ce4ebee7e74c5f6e2fc48ac91301235fa6ffb7 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 28 Aug 2021 11:50:20 +0200 Subject: [PATCH] check_pow: fixed carry calculation --- src/util.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 89d0f73..5d6471e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -73,8 +73,10 @@ NOINLINE bool difficulty_type::check_pow(const hash& pow_hash) const uint64_t carry = 0; for (int k = i, l = 0; k < 5; ++k, ++l) { - const uint64_t t = result[k] + product[l] + carry; - carry = static_cast(t < result[k]); + uint64_t t = result[k] + product[l]; + const uint64_t next_carry = static_cast(t < result[k]); + t += carry; + carry = next_carry | static_cast(t < result[k]); result[k] = t; } @@ -92,8 +94,10 @@ NOINLINE bool difficulty_type::check_pow(const hash& pow_hash) const uint64_t carry = 0; for (int k = i + j, l = 0; k < 6; ++k, ++l) { - const uint64_t t = result[k] + product[l] + carry; - carry = static_cast(t < result[k]); + uint64_t t = result[k] + product[l]; + const uint64_t next_carry = static_cast(t < result[k]); + t += carry; + carry = next_carry | static_cast(t < result[k]); result[k] = t; }