Skip to content

Commit

Permalink
fix: operator check in closeAllocation (TRST-M12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Dec 4, 2024
1 parent 91cda56 commit 07ef418
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
// Anyone is allowed to close ONLY under two concurrent conditions
// - After maxAllocationEpochs passed
// - When the allocation is for non-zero amount of tokens
bool isIndexerOrOperator = msg.sender == alloc.indexer ||
isOperator(alloc.indexer, SUBGRAPH_DATA_SERVICE_ADDRESS);
bool isIndexerOrOperator = msg.sender == alloc.indexer || isOperator(msg.sender, alloc.indexer);
if (epochs <= __DEPRECATED_maxAllocationEpochs || alloc.tokens == 0) {
require(isIndexerOrOperator, "!auth");
}
Expand Down
22 changes: 22 additions & 0 deletions packages/horizon/test/staking/allocation/close.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ contract HorizonStakingCloseAllocationTest is HorizonStakingTest {

bytes32 internal constant _poi = keccak256("poi");

/*
* MODIFIERS
*/

modifier useLegacyOperator() {
resetPrank(users.indexer);
_setOperator(subgraphDataServiceLegacyAddress, users.operator, true);
vm.startPrank(users.operator);
_;
vm.stopPrank();
}

/*
* TESTS
*/
Expand All @@ -26,6 +38,16 @@ contract HorizonStakingCloseAllocationTest is HorizonStakingTest {
_closeAllocation(_allocationId, _poi);
}

function testCloseAllocation_Operator(uint256 tokens) public useLegacyOperator() useAllocation(1 ether) {
tokens = bound(tokens, 1, MAX_STAKING_TOKENS);
_createProvision(users.indexer, subgraphDataServiceLegacyAddress, tokens, 0, 0);

// Skip 15 epochs
vm.roll(15);

_closeAllocation(_allocationId, _poi);
}

function testCloseAllocation_WithBeneficiaryAddress(uint256 tokens) public useIndexer useAllocation(1 ether) {
tokens = bound(tokens, 1, MAX_STAKING_TOKENS);
_createProvision(users.indexer, subgraphDataServiceLegacyAddress, tokens, 0, 0);
Expand Down

0 comments on commit 07ef418

Please sign in to comment.