From 43c8ee9a1b384f1cf352f8a0bfc653735d665274 Mon Sep 17 00:00:00 2001 From: rodiazet Date: Thu, 1 Feb 2024 15:48:15 +0100 Subject: [PATCH] test: Adjust difficulty value if below minimal difficulty (`0x20000`) --- test/state/ethash_difficulty.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/state/ethash_difficulty.cpp b/test/state/ethash_difficulty.cpp index 0d9bb0d51a..95eaac92b6 100644 --- a/test/state/ethash_difficulty.cpp +++ b/test/state/ethash_difficulty.cpp @@ -32,6 +32,8 @@ int64_t get_bomb_delay(evmc_revision rev) noexcept int64_t calculate_difficulty_pre_byzantium(int64_t parent_difficulty, int64_t parent_timestamp, int64_t current_timestamp, int64_t block_number, evmc_revision rev) { + static constexpr auto MIN_DIFFICULTY = int64_t{0x20000}; + // According to https://eips.ethereum.org/EIPS/eip-2 const auto period_count = block_number / 100'000; const auto offset = parent_difficulty / 2048; @@ -48,7 +50,8 @@ int64_t calculate_difficulty_pre_byzantium(int64_t parent_difficulty, int64_t pa else if (period_count == 2) diff += 1; - return diff; + // Adjust if below min difficulty `0x20000` + return std::max(MIN_DIFFICULTY, diff); } } // namespace