Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dao hardfork activation check underflow #776

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

agostbiro
Copy link
Member

@agostbiro agostbiro commented Jan 27, 2025

The operation

let drift = header.number - dao_hardfork_activation_block

underflows if for example header.number is 1 and dao_hardfork_activation_block is the actual hardfork activation (1_920_000).

This panics in debug mode and wraps around in release mode silently. The wrapping doesn't cause any problems, because the subsequent check drift <= DAO_FORCE_EXTRA_DATA_RANGE is false if it wrapped around.

Still, it's not great to have a panic here in debug mode, so I fixed it by refactoring the drift check. Since there is no user impact, I don't think we need a changelog item.

We haven't caught this before, because we run Hardhat integration tests in release mode.

@agostbiro agostbiro self-assigned this Jan 27, 2025
Copy link

changeset-bot bot commented Jan 27, 2025

⚠️ No Changeset found

Latest commit: d644969

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@agostbiro agostbiro temporarily deployed to github-action-benchmark January 27, 2025 09:25 — with GitHub Actions Inactive
@agostbiro agostbiro requested a review from a team January 27, 2025 09:25
@agostbiro agostbiro added the no changeset needed This PR doesn't require a changeset label Jan 27, 2025
@agostbiro agostbiro changed the title fix: dao hardfork activation check overflow fix: dao hardfork activation check underflow Jan 27, 2025
&& drift <= DAO_FORCE_EXTRA_DATA_RANGE
// Prevent overflow by checking that activation block is smaller
&& dao_hardfork_activation_block <= header.number
&& header.number - dao_hardfork_activation_block <= DAO_FORCE_EXTRA_DATA_RANGE
Copy link
Member

Choose a reason for hiding this comment

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

Bikeshedding: maybe replacing these two conditions with header.number <= dao_hardfork_activation_block + DAO_FORCE_EXTRA_DATA_RANGE is more concise and more self-explanatory. YMMV though, feel free to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure that's correct tbh. The condition should only activate if the block number is in the range [1_920_000, 1_920_009]

Copy link
Member

Choose a reason for hiding this comment

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

Ah, got it!

Copy link
Member

@Wodann Wodann left a comment

Choose a reason for hiding this comment

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

LGTM

@agostbiro agostbiro added this pull request to the merge queue Jan 27, 2025
Merged via the queue into main with commit e09aa22 Jan 27, 2025
38 checks passed
@agostbiro agostbiro deleted the fix/dao-hardfork-activation-overflow branch January 27, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changeset needed This PR doesn't require a changeset
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants