@@ -51,23 +51,10 @@ int64_t calculate_difficulty_pre_byzantium(int64_t parent_difficulty, int64_t pa
51
51
return diff;
52
52
}
53
53
54
- } // namespace
55
-
56
- int64_t calculate_difficulty (int64_t parent_difficulty, bool parent_has_ommers,
54
+ int64_t calculate_difficulty_since_byzantium (int64_t parent_difficulty, bool parent_has_ommers,
57
55
int64_t parent_timestamp, int64_t current_timestamp, int64_t block_number,
58
56
evmc_revision rev) noexcept
59
57
{
60
- // The calculation follows Ethereum Yellow Paper section 4.3.4. "Block Header Validity".
61
-
62
- if (rev >= EVMC_PARIS)
63
- return 0 ; // No difficulty after the Merge.
64
-
65
- if (rev < EVMC_BYZANTIUM)
66
- return calculate_difficulty_pre_byzantium (
67
- parent_difficulty, parent_timestamp, current_timestamp, block_number, rev);
68
-
69
- static constexpr auto min_difficulty = int64_t {1 } << 17 ;
70
-
71
58
const auto delay = get_bomb_delay (rev);
72
59
const auto fake_block_number = std::max (int64_t {0 }, block_number - delay);
73
60
const auto p = (fake_block_number / 100'000 ) - 2 ;
@@ -79,7 +66,27 @@ int64_t calculate_difficulty(int64_t parent_difficulty, bool parent_has_ommers,
79
66
assert (timestamp_diff > 0 );
80
67
const auto sigma_2 = std::max (y - timestamp_diff / 9 , int64_t {-99 });
81
68
const auto x = parent_difficulty / 2048 ;
82
- const auto difficulty = parent_difficulty + x * sigma_2 + epsilon;
83
- return std::max (min_difficulty, difficulty);
69
+ return parent_difficulty + x * sigma_2 + epsilon;
70
+ }
71
+ } // namespace
72
+
73
+ int64_t calculate_difficulty (int64_t parent_difficulty, bool parent_has_ommers,
74
+ int64_t parent_timestamp, int64_t current_timestamp, int64_t block_number,
75
+ evmc_revision rev) noexcept
76
+ {
77
+ // The calculation follows Ethereum Yellow Paper section 4.3.4. "Block Header Validity".
78
+ static constexpr int64_t MIN_DIFFICULTY = 0x20000 ;
79
+
80
+ if (rev >= EVMC_PARIS)
81
+ return 0 ; // No difficulty after the Merge.
82
+
83
+ const auto difficulty =
84
+ (rev < EVMC_BYZANTIUM) ?
85
+ calculate_difficulty_pre_byzantium (
86
+ parent_difficulty, parent_timestamp, current_timestamp, block_number, rev) :
87
+ calculate_difficulty_since_byzantium (parent_difficulty, parent_has_ommers,
88
+ parent_timestamp, current_timestamp, block_number, rev);
89
+
90
+ return std::max (MIN_DIFFICULTY, difficulty);
84
91
}
85
92
} // namespace evmone::state
0 commit comments