-
Notifications
You must be signed in to change notification settings - Fork 143
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: remove use of magic numbers in __ProvisionManager_init_unchained function (OZ N-11) #1041
Conversation
fix: remove use of magic numbers in __ProvisionManager_init_unchained function (OZ N-11)
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
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.
We also need to use these variables in SubgraphService.sol
in the following functions:
setMinimumProvisionTokens
_getThawingPeriodRange
_getVerifierCutRange
That contract inherits from ProvisionManager.sol
so the variables should be available.
@@ -23,6 +23,14 @@ import { ProvisionManagerV1Storage } from "./ProvisionManagerStorage.sol"; | |||
abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionManagerV1Storage { | |||
using UintRange for uint256; | |||
|
|||
// Constants | |||
uint32 private constant DEFAULT_MIN_UINT32 = 0; |
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.
I think better names for these would be tied to the range they are describing. For example, instead of DEFAULT_MIN_UINT256
and DEFAULT_MAX_UINT256
you would have DEFAULT_MIN_PROVISION_TOKENS
and DEFAULT_MAX_PROVISION_TOKENS
and so forth.
uint256 private constant DEFAULT_MIN_UINT256 = 0; | ||
uint64 private constant DEFAULT_MAX_UINT64 = type(uint64).max; | ||
uint256 private constant DEFAULT_MAX_UINT256 = type(uint256).max; | ||
uint32 private constant MAX_PPM = uint32(PPMMath.MAX_PPM); |
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.
Here I would use DEFAULT_MAX_VERIFIER_CUT
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.
We also need to use these variables in SubgraphService.sol
in the following functions:
- setMinimumProvisionTokens
- _getThawingPeriodRange
- _getVerifierCutRange
packages/horizon/contracts/data-service/utilities/ProvisionManager.sol
Outdated
Show resolved
Hide resolved
…ager.sol Co-authored-by: Tomás Migone <[email protected]>
cc4f315
to
2729a37
Compare
I made a few of these internal so they can be inherited.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## horizon #1041 +/- ##
========================================
Coverage 92.51% 92.51%
========================================
Files 46 46
Lines 2392 2392
Branches 428 428
========================================
Hits 2213 2213
Misses 179 179
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Couple nits!
packages/horizon/contracts/data-service/utilities/ProvisionManager.sol
Outdated
Show resolved
Hide resolved
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.
💎
Motivation:
Title:
N-11 Use Constants for Default Values
Details:
In the ProvisionManager contract, the __ProvisionManager_init_unchained function initializes multiple default values such as type(uint256).min, type(uint256).max, type(uint32).min, type(uint32).max, type(uint64).min, and type(uint64).max directly within the function body.
This approach introduces magic numbers, reducing code readability and maintainability. Moreover, it could potentially introduce errors since the same literal values are used in another part of the codebase as well. In addition, the verifierCutRange is set between 0 and uint32.max but the maximum should be set to MAX_PPM.
Consider revising all uses of literal values, defining constants for them where applicable, and setting a more sensible maximum value for verifierCutRange.
Key changes