-
Notifications
You must be signed in to change notification settings - Fork 698
fix: prevent unintended mutation of latestHeader.Number in ParentChainIsUsingEIP7623 #4116
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: prevent unintended mutation of latestHeader.Number in ParentChainIsUsingEIP7623 #4116
Conversation
eljobe
left a comment
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.
Nice catch. This isn't currently causing any problems, because the only caller of this method in production code doesn't go on to use the latestHeader.Number later in the code. But, if the code were changed to start reading it, this would, indeed be quite surprising.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4116 +/- ##
===========================================
+ Coverage 33.05% 57.24% +24.19%
===========================================
Files 459 459
Lines 55830 55830
===========================================
+ Hits 18453 31959 +13506
+ Misses 34159 19072 -15087
- Partials 3218 4799 +1581 |
|
@ruslan0012 please add a changelog fragment |
|
done, thanks |
joshuacolvin0
left a comment
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 Sub() method on *big.Int modifies the receiver in place. The old code was mutating latestHeader.Number that was passed from the caller, which could lead to incorrect block number being used after the function returns.
Changed from:
latestHeader.Number.Sub(latestHeader.Number, big.NewInt(5))
To:
new(big.Int).Sub(latestHeader.Number, big.NewInt(5))
This matches the pattern used elsewhere in the codebase (e.g. challenge_manager.go:220).