-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
|
&& 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The operation
underflows if for example
header.number
is 1 anddao_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.