Skip to content

Commit

Permalink
Merge pull request #1041 from graphprotocol/fix_oz_n-11
Browse files Browse the repository at this point in the history
fix: remove use of magic numbers in __ProvisionManager_init_unchained function (OZ N-11)
  • Loading branch information
MoonBoi9001 authored Oct 1, 2024
2 parents 157216a + ffd1f79 commit 3a51379
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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 @@ -372,7 +372,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 @@ -485,7 +485,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 @@ -495,7 +495,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

0 comments on commit 3a51379

Please sign in to comment.