Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.26;
import { IHorizonStaking } from "../../interfaces/IHorizonStaking.sol";

import { UintRange } from "../../libraries/UintRange.sol";
import { PPMMath } from "../../libraries/PPMMath.sol";

import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { GraphDirectory } from "../../utilities/GraphDirectory.sol";
Expand Down Expand Up @@ -150,7 +151,7 @@ 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, type(uint32).max);
_setVerifierCutRange(type(uint32).min, uint32(PPMMath.MAX_PPM));
_setThawingPeriodRange(type(uint64).min, type(uint64).max);
}

Expand Down Expand Up @@ -197,6 +198,7 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
*/
function _setVerifierCutRange(uint32 _min, uint32 _max) internal {
require(_min <= _max, ProvisionManagerInvalidRange(_min, _max));
require(PPMMath.isValidPPM(_max), ProvisionManagerInvalidRange(_min, _max));
minimumVerifierCut = _min;
maximumVerifierCut = _max;
emit VerifierCutRangeSet(_min, _max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ abstract contract ProvisionManagerV1Storage {
/// @notice The maximum thawing period allowed to register a provision in the data service
uint64 public maximumThawingPeriod;

/// @notice The minimum verifier cut required to register a provision in the data service
/// @notice The minimum verifier cut required to register a provision in the data service (in PPM)
uint32 public minimumVerifierCut;

/// @notice The maximum verifier cut allowed to register a provision in the data service
/// @notice The maximum verifier cut allowed to register a provision in the data service (in PPM)
uint32 public maximumVerifierCut;

/// @notice How much delegation the service provider can effectively use
Expand Down
11 changes: 10 additions & 1 deletion packages/horizon/test/data-service/DataService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract DataServiceTest is HorizonStakingSharedTest {
function test_Constructor_WhenTheContractIsDeployedWithAValidController() external view {
_assert_delegationRatio(type(uint32).min);
_assert_provisionTokens_range(type(uint256).min, type(uint256).max);
_assert_verifierCut_range(type(uint32).min, type(uint32).max);
_assert_verifierCut_range(type(uint32).min, uint32(PPMMath.MAX_PPM));
_assert_thawingPeriod_range(type(uint64).min, type(uint64).max);
}

Expand Down Expand Up @@ -106,6 +106,7 @@ contract DataServiceTest is HorizonStakingSharedTest {

function test_VerifierCut_WhenSettingAValidRange(uint32 min, uint32 max) external {
vm.assume(min <= max);
vm.assume(max <= uint32(PPMMath.MAX_PPM));
_assert_set_verifierCut_range(min, max);
}

Expand All @@ -116,6 +117,14 @@ contract DataServiceTest is HorizonStakingSharedTest {
dataService.setVerifierCutRange(min, max);
}

function test_VerifierCut_RevertWhen_SettingAnInvalidMax(uint32 min, uint32 max) external {
vm.assume(max > uint32(PPMMath.MAX_PPM));
vm.assume(min <= max);

vm.expectRevert(abi.encodeWithSelector(ProvisionManager.ProvisionManagerInvalidRange.selector, min, max));
dataService.setVerifierCutRange(min, max);
}

function test_VerifierCut_WhenGettingTheRange() external {
dataService.setVerifierCutRange(dataService.VERIFIER_CUT_MIN(), dataService.VERIFIER_CUT_MAX());
_assert_verifierCut_range(dataService.VERIFIER_CUT_MIN(), dataService.VERIFIER_CUT_MAX());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { GraphBaseTest } from "../GraphBase.t.sol";
import { DataServiceBaseUpgradeable } from "./implementations/DataServiceBaseUpgradeable.sol";
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";

import { PPMMath } from "./../../contracts/libraries/PPMMath.sol";

contract DataServiceUpgradeableTest is GraphBaseTest {
function test_WhenTheContractIsDeployed() external {
(DataServiceBaseUpgradeable dataService, DataServiceBaseUpgradeable implementation) = _deployDataService();
Expand All @@ -20,7 +22,7 @@ contract DataServiceUpgradeableTest is GraphBaseTest {

(uint32 minVerifierCut, uint32 maxVerifierCut) = dataService.getVerifierCutRange();
assertEq(minVerifierCut, type(uint32).min);
assertEq(maxVerifierCut, type(uint32).max);
assertEq(maxVerifierCut, uint32(PPMMath.MAX_PPM));

(uint64 minThawingPeriod, uint64 maxThawingPeriod) = dataService.getThawingPeriodRange();
assertEq(minThawingPeriod, type(uint64).min);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { GraphBaseTest } from "../../GraphBase.t.sol";
import { DataServiceImpPausableUpgradeable } from "../implementations/DataServiceImpPausableUpgradeable.sol";
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";

import { PPMMath } from "./../../../contracts/libraries/PPMMath.sol";

contract DataServicePausableUpgradeableTest is GraphBaseTest {
function test_WhenTheContractIsDeployed() external {
(
Expand All @@ -23,7 +25,7 @@ contract DataServicePausableUpgradeableTest is GraphBaseTest {

(uint32 minVerifierCut, uint32 maxVerifierCut) = dataService.getVerifierCutRange();
assertEq(minVerifierCut, type(uint32).min);
assertEq(maxVerifierCut, type(uint32).max);
assertEq(maxVerifierCut, uint32(PPMMath.MAX_PPM));

(uint64 minThawingPeriod, uint64 maxThawingPeriod) = dataService.getThawingPeriodRange();
assertEq(minThawingPeriod, type(uint64).min);
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph-service/contracts/SubgraphService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,11 @@ contract SubgraphService is
/**
* @notice Getter for the accepted verifier cut range for provisions
* @return min The minimum verifier cut which is defined by {DisputeManager-getVerifierCut}
* @return max The maximum is unbounded
* @return max The maximum is 100% in PPM
*/
function _getVerifierCutRange() internal view override returns (uint32 min, uint32 max) {
uint32 verifierCut = _disputeManager().getVerifierCut();
return (verifierCut, type(uint32).max);
return (verifierCut, uint32(PPMMath.MAX_PPM));
}

/**
Expand Down