Skip to content

Conversation

souradeep-das
Copy link
Contributor

What was wrong?

Frontier block difficulty calculation was broken

How was it fixed?

Type conversion

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@souradeep-das souradeep-das changed the title fix block difficulty calc frontier fix: block difficulty calc frontier Sep 4, 2025
Copy link
Contributor

@SamWilsn SamWilsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, is this broken all the way up to the merge?

@@ -768,7 +768,7 @@ def calculate_block_difficulty(
# See https://github.com/ethereum/go-ethereum/pull/1588
num_bomb_periods = (int(block_number) // 100000) - 2
if num_bomb_periods >= 0:
difficulty += 2**num_bomb_periods
difficulty += Uint(2**num_bomb_periods)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_bomb_periods = (block_number // Uint(100000)) - Uint(2)
if num_bomb_periods >= 0:
    difficulty += Uint(2) ** num_bomb_periods

Kinda just thinking out loud, but would it be better in your opinion to do the math as Uint, or do the conversion at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah was thinking the same! that would make it consistent with the other forks. Also do you think in that case converting difficulty to int for doing the calculations is better to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

difficulty = int(difficulty)
num_bomb_periods = (int(block_number) // 100000) - 2
if num_bomb_periods >= 0:
    difficulty += 2**num_bomb_periods

return max(Uint(difficulty), MINIMUM_DIFFICULTY)

is this better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Frontier have a minimum difficulty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@souradeep-das
Copy link
Contributor Author

the other forks seems to be okay with the calculation - looks like only a problem with frontier

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.94%. Comparing base (6b0f795) to head (e68bc58).
⚠️ Report is 1 commits behind head on forks/osaka.

Files with missing lines Patch % Lines
src/ethereum/frontier/fork.py 0.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##           forks/osaka    #1409   +/-   ##
============================================
  Coverage        94.94%   94.94%           
============================================
  Files              583      583           
  Lines            34665    34665           
  Branches          3070     3070           
============================================
  Hits             32914    32914           
  Misses            1198     1198           
  Partials           553      553           
Flag Coverage Δ
unittests 94.94% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SamWilsn SamWilsn merged commit 67bc568 into ethereum:forks/osaka Sep 8, 2025
8 checks passed
@SamWilsn
Copy link
Contributor

SamWilsn commented Sep 8, 2025

What you had is fine, now that I've looked a bit more deeply at it. Post-Frontier forks convert everything to int before doing the math, so if we want to fix this, we should do it for all the forks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants