From ffe9b89775af33d5aedff2c5757d14b819c80e94 Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Wed, 18 Sep 2024 19:14:11 +0100 Subject: [PATCH 1/7] fix: address magic number use. (OZ N-11) --- .../data-service/utilities/ProvisionManager.sol | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol index d1cf94287..ee5f5e048 100644 --- a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol @@ -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; + uint64 private constant DEFAULT_MIN_UINT64 = 0; + 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); + /** * @notice Emitted when the provision tokens range is set. * @param min The minimum allowed value for the provision tokens. @@ -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_UINT256, DEFAULT_MAX_UINT256); + _setVerifierCutRange(DEFAULT_MIN_UINT32, MAX_PPM); + _setThawingPeriodRange(DEFAULT_MIN_UINT64, DEFAULT_MAX_UINT64); } /** From 76e4940b8203784d06939e70e45b8779ab9464f9 Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Fri, 20 Sep 2024 12:27:06 +0100 Subject: [PATCH 2/7] fix: update constant names. (OZ N-11) --- .../utilities/ProvisionManager.sol | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol index ee5f5e048..0e79bfa47 100644 --- a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol @@ -24,12 +24,12 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa using UintRange for uint256; // Constants - uint32 private constant DEFAULT_MIN_UINT32 = 0; - uint64 private constant DEFAULT_MIN_UINT64 = 0; - 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); + uint32 private constant DEFAULT_MIN_VERIFIER_CUT = 0; + uint64 private constant DEFAULT_MIN_THAWING_PERIOD = 0; + uint256 private constant DEFAULT_MIN_PROVISION_TOKENS = 0; + uint64 private constant DEFAULT_MAX_THAWING_PERIOD = type(uint64).max; + uint256 private constant DEFAULT_MAX_PROVISION_TOKENS = type(uint256).max; + uint32 private constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM); /** * @notice Emitted when the provision tokens range is set. @@ -123,9 +123,9 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa */ // solhint-disable-next-line func-name-mixedcase function __ProvisionManager_init_unchained() internal onlyInitializing { - _setProvisionTokensRange(DEFAULT_MIN_UINT256, DEFAULT_MAX_UINT256); - _setVerifierCutRange(DEFAULT_MIN_UINT32, MAX_PPM); - _setThawingPeriodRange(DEFAULT_MIN_UINT64, DEFAULT_MAX_UINT64); + _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); } /** From 89121252c6aa6a88404cb385bae812d3dbadd071 Mon Sep 17 00:00:00 2001 From: MoonBoi9001 <67825802+MoonBoi9001@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:33:08 +0100 Subject: [PATCH 3/7] Update packages/horizon/contracts/data-service/utilities/ProvisionManager.sol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomás Migone --- .../contracts/data-service/utilities/ProvisionManager.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol index 0e79bfa47..8608fd2fa 100644 --- a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol @@ -24,12 +24,12 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa using UintRange for uint256; // Constants - uint32 private constant DEFAULT_MIN_VERIFIER_CUT = 0; - uint64 private constant DEFAULT_MIN_THAWING_PERIOD = 0; - uint256 private constant DEFAULT_MIN_PROVISION_TOKENS = 0; + uint32 private constant DEFAULT_MIN_VERIFIER_CUT = type(uint32).min; + uint32 private constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM); + uint64 private constant DEFAULT_MIN_THAWING_PERIOD = type(uint64).min; uint64 private constant DEFAULT_MAX_THAWING_PERIOD = type(uint64).max; + uint256 private constant DEFAULT_MIN_PROVISION_TOKENS = type(uint256).min; uint256 private constant DEFAULT_MAX_PROVISION_TOKENS = type(uint256).max; - uint32 private constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM); /** * @notice Emitted when the provision tokens range is set. From 2729a376ac0be6386bcd7d02ea39e74d5cb4fc32 Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Mon, 30 Sep 2024 15:44:50 +0100 Subject: [PATCH 4/7] fix: use new constants in subgraphservice.sol --- .../data-service/utilities/ProvisionManager.sol | 6 +++--- .../subgraph-service/contracts/SubgraphService.sol | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol index 8608fd2fa..b5c905ad5 100644 --- a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol @@ -25,11 +25,11 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa // Constants uint32 private constant DEFAULT_MIN_VERIFIER_CUT = type(uint32).min; - uint32 private constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM); + uint32 internal constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM); uint64 private constant DEFAULT_MIN_THAWING_PERIOD = type(uint64).min; - uint64 private constant DEFAULT_MAX_THAWING_PERIOD = type(uint64).max; + uint64 internal constant DEFAULT_MAX_THAWING_PERIOD = type(uint64).max; uint256 private constant DEFAULT_MIN_PROVISION_TOKENS = type(uint256).min; - uint256 private constant DEFAULT_MAX_PROVISION_TOKENS = type(uint256).max; + uint256 internal constant DEFAULT_MAX_PROVISION_TOKENS = type(uint256).max; /** * @notice Emitted when the provision tokens range is set. diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index 5023e6160..909aa7750 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -21,9 +21,14 @@ import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol" import { Allocation } from "./libraries/Allocation.sol"; import { LegacyAllocation } from "./libraries/LegacyAllocation.sol"; +import { ProvisionManager } from "@graphprotocol/horizon/contracts/data-service/utilities/ProvisionManager.sol"; + + + contract SubgraphService is Initializable, OwnableUpgradeable, + ProvisionManager, DataService, DataServicePausableUpgradeable, DataServiceFees, @@ -359,7 +364,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); } /** @@ -473,7 +478,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); } /** @@ -483,7 +488,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); } /** From a598eca7e6ab93252d10197b8b0ea4228b39c7b8 Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Tue, 1 Oct 2024 17:20:03 +0100 Subject: [PATCH 5/7] fix: set all ProvisionManager constants internal. --- .../contracts/data-service/utilities/ProvisionManager.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol index b5c905ad5..1af1a28b4 100644 --- a/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol @@ -24,11 +24,11 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa using UintRange for uint256; // Constants - uint32 private constant DEFAULT_MIN_VERIFIER_CUT = type(uint32).min; + uint32 internal constant DEFAULT_MIN_VERIFIER_CUT = type(uint32).min; uint32 internal constant DEFAULT_MAX_VERIFIER_CUT = uint32(PPMMath.MAX_PPM); - uint64 private constant DEFAULT_MIN_THAWING_PERIOD = type(uint64).min; + uint64 internal constant DEFAULT_MIN_THAWING_PERIOD = type(uint64).min; uint64 internal constant DEFAULT_MAX_THAWING_PERIOD = type(uint64).max; - uint256 private constant DEFAULT_MIN_PROVISION_TOKENS = type(uint256).min; + uint256 internal constant DEFAULT_MIN_PROVISION_TOKENS = type(uint256).min; uint256 internal constant DEFAULT_MAX_PROVISION_TOKENS = type(uint256).max; /** From de6c82214254106fbb354186e6b5981a58bd59cd Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Tue, 1 Oct 2024 17:21:30 +0100 Subject: [PATCH 6/7] fix: remove ProvisionManager inheritance. --- packages/subgraph-service/contracts/SubgraphService.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index 098307ceb..a928c0b0f 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -22,14 +22,12 @@ import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol" import { Allocation } from "./libraries/Allocation.sol"; import { LegacyAllocation } from "./libraries/LegacyAllocation.sol"; -import { ProvisionManager } from "@graphprotocol/horizon/contracts/data-service/utilities/ProvisionManager.sol"; contract SubgraphService is Initializable, OwnableUpgradeable, - ProvisionManager, MulticallUpgradeable, DataService, DataServicePausableUpgradeable, From ffd1f79c1ec9b397de64be6ef8e7d3714b575ae0 Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Tue, 1 Oct 2024 17:26:10 +0100 Subject: [PATCH 7/7] fix: remove whitespace. --- packages/subgraph-service/contracts/SubgraphService.sol | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index a928c0b0f..b4d1b3f4a 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -22,9 +22,6 @@ import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol" import { Allocation } from "./libraries/Allocation.sol"; import { LegacyAllocation } from "./libraries/LegacyAllocation.sol"; - - - contract SubgraphService is Initializable, OwnableUpgradeable,