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: remove use of magic numbers in __ProvisionManager_init_unchained function (OZ N-11) #1041

Merged
merged 8 commits into from
Oct 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ import { ProvisionManagerV1Storage } from "./ProvisionManagerStorage.sol";
abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionManagerV1Storage {
using UintRange for uint256;

// Constants
uint32 internal constant DEFAULT_MIN_VERIFIER_CUT = type(uint32).min;
uint32 internal constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM);
uint64 internal constant DEFAULT_MIN_THAWING_PERIOD = type(uint64).min;
uint64 internal constant DEFAULT_MAX_THAWING_PERIOD = type(uint64).max;
uint256 internal constant DEFAULT_MIN_PROVISION_TOKENS = type(uint256).min;
uint256 internal constant DEFAULT_MAX_PROVISION_TOKENS = type(uint256).max;

/**
* @notice Emitted when the provision tokens range is set.
* @param min The minimum allowed value for the provision tokens.
Expand Down Expand Up @@ -115,9 +123,9 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
*/
// solhint-disable-next-line func-name-mixedcase
function __ProvisionManager_init_unchained() internal onlyInitializing {
_setProvisionTokensRange(type(uint256).min, type(uint256).max);
_setVerifierCutRange(type(uint32).min, uint32(PPMMath.MAX_PPM));
_setThawingPeriodRange(type(uint64).min, type(uint64).max);
_setProvisionTokensRange(DEFAULT_MIN_PROVISION_TOKENS, DEFAULT_MAX_PROVISION_TOKENS);
_setVerifierCutRange(DEFAULT_MIN_VERIFIER_CUT, DEFAULT_MAX_VERIFIER_CUT);
_setThawingPeriodRange(DEFAULT_MIN_THAWING_PERIOD, DEFAULT_MAX_THAWING_PERIOD);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/subgraph-service/contracts/SubgraphService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ contract SubgraphService is
* @notice See {ISubgraphService.setMinimumProvisionTokens}
*/
function setMinimumProvisionTokens(uint256 minimumProvisionTokens) external override onlyOwner {
_setProvisionTokensRange(minimumProvisionTokens, type(uint256).max);
_setProvisionTokensRange(minimumProvisionTokens, DEFAULT_MAX_PROVISION_TOKENS);
}

/**
Expand Down Expand Up @@ -480,7 +480,7 @@ contract SubgraphService is
*/
function _getThawingPeriodRange() internal view override returns (uint64 min, uint64 max) {
uint64 disputePeriod = _disputeManager().getDisputePeriod();
return (disputePeriod, type(uint64).max);
return (disputePeriod, DEFAULT_MAX_THAWING_PERIOD);
}

/**
Expand All @@ -490,7 +490,7 @@ contract SubgraphService is
*/
function _getVerifierCutRange() internal view override returns (uint32 min, uint32 max) {
uint32 verifierCut = _disputeManager().getVerifierCut();
return (verifierCut, uint32(PPMMath.MAX_PPM));
return (verifierCut, DEFAULT_MAX_VERIFIER_CUT);
}

/**
Expand Down