Skip to content

Commit

Permalink
test: Adjust difficulty value if below minimal difficulty (0x20000)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Feb 1, 2024
1 parent 1580602 commit 43c8ee9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/state/ethash_difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 43c8ee9

Please sign in to comment.