Skip to content

Commit c90a4ec

Browse files
authored
Merge pull request #1114 from graphprotocol/tmigone/fix-escape-hatch
2 parents 314c6da + 6460b84 commit c90a4ec

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ interface IHorizonStakingMain {
362362
*/
363363
error HorizonStakingNotAuthorized(address serviceProvider, address verifier, address caller);
364364

365+
/**
366+
* @notice Thrown when attempting to create a provision with a verifier other than the
367+
* subgraph data service. This restriction only applies during the transition period.
368+
* @param verifier The verifier address
369+
*/
370+
error HorizonStakingInvalidVerifier(address verifier);
371+
365372
/**
366373
* @notice Thrown when attempting to create a provision with an invalid maximum verifier cut.
367374
* @param maxVerifierCut The maximum verifier cut
@@ -562,6 +569,8 @@ interface IHorizonStakingMain {
562569
* service, where the data service is the verifier.
563570
* This function can be called by the service provider or by an operator authorized by the provider
564571
* for this specific verifier.
572+
* @dev During the transition period, only the subgraph data service can be used as a verifier. This
573+
* prevents an escape hatch for legacy allocation stake.
565574
* @dev Requirements:
566575
* - `tokens` cannot be zero.
567576
* - The `serviceProvider` must have enough idle stake to cover the tokens to provision.

packages/horizon/contracts/staking/HorizonStaking.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
720720
uint64 _thawingPeriod
721721
) private {
722722
require(_tokens > 0, HorizonStakingInvalidZeroTokens());
723+
// TODO: Remove this after the transition period - it prevents an early escape hatch for legacy allocations
724+
require(
725+
_verifier == SUBGRAPH_DATA_SERVICE_ADDRESS || __DEPRECATED_thawingPeriod == 0,
726+
HorizonStakingInvalidVerifier(_verifier)
727+
);
723728
require(PPMMath.isValidPPM(_maxVerifierCut), HorizonStakingInvalidMaxVerifierCut(_maxVerifierCut));
724729
require(
725730
_thawingPeriod <= _maxThawingPeriod,

packages/horizon/hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const config: HardhatUserConfig = {
2222
settings: {
2323
optimizer: {
2424
enabled: true,
25-
runs: 70,
25+
runs: 20,
2626
},
2727
},
2828
},

packages/horizon/test/staking/provision/provision.t.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,20 @@ contract HorizonStakingProvisionTest is HorizonStakingTest {
108108
vm.expectRevert(expectedError);
109109
staking.provision(users.indexer, subgraphDataServiceAddress, amount, maxVerifierCut, thawingPeriod);
110110
}
111+
112+
function testProvision_RevertWhen_VerifierIsNotSubgraphDataServiceDuringTransitionPeriod(
113+
uint256 amount
114+
) public useIndexer useStake(amount) {
115+
// simulate the transition period
116+
_setStorage_DeprecatedThawingPeriod(THAWING_PERIOD_IN_BLOCKS);
117+
118+
// oddly we use subgraphDataServiceLegacyAddress as the subgraph service address
119+
// so subgraphDataServiceAddress is not the subgraph service ¯\_(ツ)_/¯
120+
bytes memory expectedError = abi.encodeWithSignature(
121+
"HorizonStakingInvalidVerifier(address)",
122+
subgraphDataServiceAddress
123+
);
124+
vm.expectRevert(expectedError);
125+
staking.provision(users.indexer, subgraphDataServiceAddress, amount, 0, 0);
126+
}
111127
}

packages/horizon/test/staking/stake/unstake.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ contract HorizonStakingUnstakeTest is HorizonStakingTest {
6262
_setStorage_ServiceProvider(users.indexer, tokensLocked, 0, tokensLocked, block.number, 0);
6363

6464
// create provision, thaw and deprovision
65-
_createProvision(users.indexer, subgraphDataServiceAddress, tokens, 0, MAX_THAWING_PERIOD);
66-
_thaw(users.indexer, subgraphDataServiceAddress, tokens);
65+
_createProvision(users.indexer, subgraphDataServiceLegacyAddress, tokens, 0, MAX_THAWING_PERIOD);
66+
_thaw(users.indexer, subgraphDataServiceLegacyAddress, tokens);
6767
skip(MAX_THAWING_PERIOD + 1);
68-
_deprovision(users.indexer, subgraphDataServiceAddress, 0);
68+
_deprovision(users.indexer, subgraphDataServiceLegacyAddress, 0);
6969

7070
// unstake
7171
_unstake(tokensToUnstake);
@@ -90,10 +90,10 @@ contract HorizonStakingUnstakeTest is HorizonStakingTest {
9090
_setStorage_ServiceProvider(users.indexer, tokensThawing, 0, tokensThawing, tokensThawingUntilBlock, 0);
9191

9292
// create provision, thaw and deprovision
93-
_createProvision(users.indexer, subgraphDataServiceAddress, tokens, 0, MAX_THAWING_PERIOD);
94-
_thaw(users.indexer, subgraphDataServiceAddress, tokens);
93+
_createProvision(users.indexer, subgraphDataServiceLegacyAddress, tokens, 0, MAX_THAWING_PERIOD);
94+
_thaw(users.indexer, subgraphDataServiceLegacyAddress, tokens);
9595
skip(MAX_THAWING_PERIOD + 1);
96-
_deprovision(users.indexer, subgraphDataServiceAddress, 0);
96+
_deprovision(users.indexer, subgraphDataServiceLegacyAddress, 0);
9797

9898
// unstake
9999
_unstake(tokensToUnstake);

0 commit comments

Comments
 (0)