Skip to content

Commit 7695c9e

Browse files
fix: [TRST-H-2] Only agreement owner can collect indexing fee
1 parent da42fb4 commit 7695c9e

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ contract SubgraphService is
298298
paymentCollected = _collectIndexingRewards(indexer, data);
299299
} else if (paymentType == IGraphPayments.PaymentTypes.IndexingFee) {
300300
(bytes16 agreementId, bytes memory iaCollectionData) = IndexingAgreementDecoder.decodeCollectData(data);
301-
paymentCollected = _collectIndexingFees(agreementId, paymentsDestination[indexer], iaCollectionData);
301+
paymentCollected = _collectIndexingFees(
302+
indexer,
303+
agreementId,
304+
paymentsDestination[indexer],
305+
iaCollectionData
306+
);
302307
} else {
303308
revert SubgraphServiceInvalidPaymentType(paymentType);
304309
}
@@ -754,19 +759,22 @@ contract SubgraphService is
754759
* Emits a {StakeClaimLocked} event.
755760
* Emits a {IndexingFeesCollectedV1} event.
756761
*
762+
* @param _indexer The address of the indexer
757763
* @param _agreementId The id of the indexing agreement
758764
* @param _paymentsDestination The address where the fees should be sent
759765
* @param _data The indexing agreement collection data
760766
* @return The amount of fees collected
761767
*/
762768
function _collectIndexingFees(
769+
address _indexer,
763770
bytes16 _agreementId,
764771
address _paymentsDestination,
765772
bytes memory _data
766773
) private returns (uint256) {
767774
(address indexer, uint256 tokensCollected) = IndexingAgreement._getStorageManager().collect(
768775
_allocations,
769776
IndexingAgreement.CollectParams({
777+
indexer: _indexer,
770778
agreementId: _agreementId,
771779
currentEpoch: _graphEpochManager().currentEpoch(),
772780
receiverDestination: _paymentsDestination,

packages/subgraph-service/contracts/libraries/IndexingAgreement.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ library IndexingAgreement {
7575

7676
/**
7777
* @notice Parameters for collecting indexing fees
78+
* @param indexer The address of the indexer
7879
* @param agreementId The ID of the indexing agreement
7980
* @param currentEpoch The current epoch
8081
* @param receiverDestination The address where the collected fees should be sent
8182
* @param data The encoded data containing the number of entities indexed, proof of indexing, and epoch
8283
*/
8384
struct CollectParams {
85+
address indexer;
8486
bytes16 agreementId;
8587
uint256 currentEpoch;
8688
address receiverDestination;
@@ -523,6 +525,10 @@ library IndexingAgreement {
523525
wrapper.agreement.allocationId,
524526
wrapper.collectorAgreement.serviceProvider
525527
);
528+
require(
529+
allocation.indexer == params.indexer,
530+
IndexingAgreementNotAuthorized(params.agreementId, params.indexer)
531+
);
526532
require(_isCollectable(wrapper), IndexingAgreementNotCollectable(params.agreementId));
527533

528534
require(

packages/subgraph-service/test/unit/subgraphService/indexing-agreement/collect.t.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,35 @@ contract SubgraphServiceIndexingAgreementCollectTest is SubgraphServiceIndexingA
232232
);
233233
}
234234

235+
function test_SubgraphService_CollectIndexingFees_Reverts_WhenIndexingAgreementNotAuthorized(
236+
Seed memory seed,
237+
uint256 entities,
238+
bytes32 poi
239+
) public {
240+
Context storage ctx = _newCtx(seed);
241+
IndexerState memory indexerState = _withIndexer(ctx);
242+
IndexerState memory otherIndexerState = _withIndexer(ctx);
243+
IRecurringCollector.SignedRCA memory accepted = _withAcceptedIndexingAgreement(ctx, indexerState);
244+
245+
vm.assume(otherIndexerState.addr != indexerState.addr);
246+
247+
resetPrank(otherIndexerState.addr);
248+
249+
uint256 currentEpochBlock = epochManager.currentEpochBlock();
250+
251+
bytes memory expectedErr = abi.encodeWithSelector(
252+
IndexingAgreement.IndexingAgreementNotAuthorized.selector,
253+
accepted.rca.agreementId,
254+
otherIndexerState.addr
255+
);
256+
vm.expectRevert(expectedErr);
257+
subgraphService.collect(
258+
otherIndexerState.addr,
259+
IGraphPayments.PaymentTypes.IndexingFee,
260+
_encodeCollectDataV1(accepted.rca.agreementId, entities, poi, currentEpochBlock, bytes(""))
261+
);
262+
}
263+
235264
function test_SubgraphService_CollectIndexingFees_Reverts_WhenStopService(
236265
Seed memory seed,
237266
uint256 entities,

0 commit comments

Comments
 (0)