From 5ece7cee9ccc12c1a5a7fe02892a07e0f4c978ce Mon Sep 17 00:00:00 2001 From: Javier Smooth Date: Sat, 25 Jul 2015 18:30:31 -0700 Subject: [PATCH] reward calculation fix for 32-bit (from Monero) --- src/cryptonote_core/cryptonote_basic_impl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp index 2d445c8..f673bd7 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.cpp +++ b/src/cryptonote_core/cryptonote_basic_impl.cpp @@ -81,7 +81,11 @@ namespace cryptonote { assert(current_block_size < std::numeric_limits::max()); uint64_t product_hi; - uint64_t product_lo = mul128(base_reward, current_block_size * (2 * median_size - current_block_size), &product_hi); + // BUGFIX: 32-bit saturation bug (e.g. ARM7), the result was being + // treated as 32-bit by default. + uint64_t multiplicand = 2 * median_size - current_block_size; + multiplicand *= current_block_size; + uint64_t product_lo = mul128(base_reward, multiplicand, &product_hi); uint64_t reward_hi; uint64_t reward_lo;