Skip to content

Commit a228e0e

Browse files
authored
Merge pull request #1075 from graphprotocol/tmigone/trust-fixes-dispute-manager
2 parents 2fbe0e1 + 8aa05c4 commit a228e0e

File tree

13 files changed

+750
-210
lines changed

13 files changed

+750
-210
lines changed

packages/subgraph-service/contracts/DisputeManager.sol

Lines changed: 134 additions & 114 deletions
Large diffs are not rendered by default.

packages/subgraph-service/contracts/interfaces/IDisputeManager.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ interface IDisputeManager {
169169
error DisputeManagerDisputeNotPending(IDisputeManager.DisputeStatus status);
170170
error DisputeManagerDisputeAlreadyCreated(bytes32 disputeId);
171171
error DisputeManagerDisputePeriodNotFinished();
172+
error DisputeManagerDisputeInConflict(bytes32 disputeId);
173+
error DisputeManagerDisputeNotInConflict(bytes32 disputeId);
172174
error DisputeManagerMustAcceptRelatedDispute(bytes32 disputeId, bytes32 relatedDisputeId);
173175
error DisputeManagerIndexerNotFound(address allocationId);
174176
error DisputeManagerNonMatchingSubgraphDeployment(bytes32 subgraphDeploymentId1, bytes32 subgraphDeploymentId2);
@@ -180,6 +182,7 @@ interface IDisputeManager {
180182
bytes32 responseCID2,
181183
bytes32 subgraphDeploymentId2
182184
);
185+
error DisputeManagerSubgraphServiceNotSet();
183186

184187
function setDisputePeriod(uint64 disputePeriod) external;
185188

@@ -204,6 +207,13 @@ interface IDisputeManager {
204207

205208
function acceptDispute(bytes32 disputeId, uint256 tokensSlash) external;
206209

210+
function acceptDisputeConflict(
211+
bytes32 disputeId,
212+
uint256 tokensSlash,
213+
bool acceptDisputeInConflict,
214+
uint256 tokensSlashRelated
215+
) external;
216+
207217
function rejectDispute(bytes32 disputeId) external;
208218

209219
function drawDispute(bytes32 disputeId) external;

packages/subgraph-service/test/disputeManager/DisputeManager.t.sol

Lines changed: 333 additions & 63 deletions
Large diffs are not rendered by default.

packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,36 @@ contract DisputeManagerIndexingAcceptDisputeTest is DisputeManagerTest {
2727
_acceptDispute(disputeID, tokensSlash);
2828
}
2929

30+
function test_Indexing_Accept_Dispute_RevertWhen_SubgraphServiceNotSet(
31+
uint256 tokens,
32+
uint256 tokensSlash
33+
) public useIndexer useAllocation(tokens) {
34+
tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens));
35+
36+
resetPrank(users.fisherman);
37+
bytes32 disputeID = _createIndexingDispute(allocationID, bytes32("POI1"));
38+
39+
resetPrank(users.arbitrator);
40+
// clear subgraph service address from storage
41+
_setStorage_SubgraphService(address(0));
42+
43+
vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerSubgraphServiceNotSet.selector));
44+
disputeManager.acceptDispute(disputeID, tokensSlash);
45+
}
46+
47+
function test_Indexing_Accept_Dispute_OptParam(
48+
uint256 tokens,
49+
uint256 tokensSlash
50+
) public useIndexer useAllocation(tokens) {
51+
tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens));
52+
53+
resetPrank(users.fisherman);
54+
bytes32 disputeID = _createIndexingDispute(allocationID, bytes32("POI1"));
55+
56+
resetPrank(users.arbitrator);
57+
_acceptDispute(disputeID, tokensSlash);
58+
}
59+
3060
function test_Indexing_Accept_RevertIf_CallerIsNotArbitrator(
3161
uint256 tokens,
3262
uint256 tokensSlash

packages/subgraph-service/test/disputeManager/disputes/indexing/create.t.sol

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@ import { IDisputeManager } from "../../../../contracts/interfaces/IDisputeManage
77
import { DisputeManagerTest } from "../../DisputeManager.t.sol";
88

99
contract DisputeManagerIndexingCreateDisputeTest is DisputeManagerTest {
10-
1110
/*
1211
* TESTS
1312
*/
1413

15-
function test_Indexing_Create_Dispute(
14+
function test_Indexing_Create_Dispute(uint256 tokens) public useIndexer useAllocation(tokens) {
15+
resetPrank(users.fisherman);
16+
_createIndexingDispute(allocationID, bytes32("POI1"));
17+
}
18+
19+
function test_Indexing_Create_Dispute_RevertWhen_SubgraphServiceNotSet(
1620
uint256 tokens
1721
) public useIndexer useAllocation(tokens) {
1822
resetPrank(users.fisherman);
19-
_createIndexingDispute(allocationID, bytes32("POI1"));
23+
24+
// clear subgraph service address from storage
25+
_setStorage_SubgraphService(address(0));
26+
27+
// // Approve the dispute deposit
28+
token.approve(address(disputeManager), disputeDeposit);
29+
30+
vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerSubgraphServiceNotSet.selector));
31+
disputeManager.createIndexingDispute(allocationID, bytes32("POI2"));
2032
}
2133

2234
function test_Indexing_Create_MultipleDisputes() public {
@@ -33,7 +45,12 @@ contract DisputeManagerIndexingCreateDisputeTest is DisputeManagerTest {
3345
_createProvision(indexer, tokens, maxSlashingPercentage, disputePeriod);
3446
_register(indexer, abi.encode("url", "geoHash", address(0)));
3547
uint256 allocationIDPrivateKey = uint256(keccak256(abi.encodePacked(i)));
36-
bytes memory data = _createSubgraphAllocationData(indexer, subgraphDeployment, allocationIDPrivateKey, tokens);
48+
bytes memory data = _createSubgraphAllocationData(
49+
indexer,
50+
subgraphDeployment,
51+
allocationIDPrivateKey,
52+
tokens
53+
);
3754
_startService(indexer, data);
3855
allocationIDPrivateKeys[i] = allocationIDPrivateKey;
3956
}
@@ -48,7 +65,7 @@ contract DisputeManagerIndexingCreateDisputeTest is DisputeManagerTest {
4865
uint256 tokens
4966
) public useIndexer useAllocation(tokens) {
5067
resetPrank(users.fisherman);
51-
bytes32 disputeID =_createIndexingDispute(allocationID, bytes32("POI1"));
68+
bytes32 disputeID = _createIndexingDispute(allocationID, bytes32("POI1"));
5269

5370
// Create another dispute with different fisherman
5471
address otherFisherman = makeAddr("otherFisherman");
@@ -78,9 +95,7 @@ contract DisputeManagerIndexingCreateDisputeTest is DisputeManagerTest {
7895
vm.stopPrank();
7996
}
8097

81-
function test_Indexing_Create_RevertIf_AllocationDoesNotExist(
82-
uint256 tokens
83-
) public useFisherman {
98+
function test_Indexing_Create_RevertIf_AllocationDoesNotExist(uint256 tokens) public useFisherman {
8499
tokens = bound(tokens, disputeDeposit, 10_000_000_000 ether);
85100
token.approve(address(disputeManager), tokens);
86101
bytes memory expectedError = abi.encodeWithSelector(
@@ -92,9 +107,7 @@ contract DisputeManagerIndexingCreateDisputeTest is DisputeManagerTest {
92107
vm.stopPrank();
93108
}
94109

95-
function test_Indexing_Create_RevertIf_IndexerIsBelowStake(
96-
uint256 tokens
97-
) public useIndexer useAllocation(tokens) {
110+
function test_Indexing_Create_RevertIf_IndexerIsBelowStake(uint256 tokens) public useIndexer useAllocation(tokens) {
98111
// Close allocation
99112
bytes memory data = abi.encode(allocationID);
100113
_stopService(users.indexer, data);

packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,39 @@ contract DisputeManagerQueryAcceptDisputeTest is DisputeManagerTest {
3434
_acceptDispute(disputeID, tokensSlash);
3535
}
3636

37+
function test_Query_Accept_Dispute_RevertWhen_SubgraphServiceNotSet(
38+
uint256 tokens,
39+
uint256 tokensSlash
40+
) public useIndexer useAllocation(tokens) {
41+
tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens));
42+
43+
resetPrank(users.fisherman);
44+
Attestation.Receipt memory receipt = _createAttestationReceipt(requestCID, responseCID, subgraphDeploymentId);
45+
bytes memory attestationData = _createAtestationData(receipt, allocationIDPrivateKey);
46+
bytes32 disputeID = _createQueryDispute(attestationData);
47+
48+
resetPrank(users.arbitrator);
49+
// clear subgraph service address from storage
50+
_setStorage_SubgraphService(address(0));
51+
vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerSubgraphServiceNotSet.selector));
52+
disputeManager.acceptDispute(disputeID, tokensSlash);
53+
}
54+
55+
function test_Query_Accept_Dispute_OptParam(
56+
uint256 tokens,
57+
uint256 tokensSlash
58+
) public useIndexer useAllocation(tokens) {
59+
tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens));
60+
61+
resetPrank(users.fisherman);
62+
Attestation.Receipt memory receipt = _createAttestationReceipt(requestCID, responseCID, subgraphDeploymentId);
63+
bytes memory attestationData = _createAtestationData(receipt, allocationIDPrivateKey);
64+
bytes32 disputeID = _createQueryDispute(attestationData);
65+
66+
resetPrank(users.arbitrator);
67+
_acceptDispute(disputeID, tokensSlash);
68+
}
69+
3770
function test_Query_Accept_RevertIf_CallerIsNotArbitrator(
3871
uint256 tokens,
3972
uint256 tokensSlash
@@ -72,4 +105,23 @@ contract DisputeManagerQueryAcceptDisputeTest is DisputeManagerTest {
72105
vm.expectRevert(expectedError);
73106
disputeManager.acceptDispute(disputeID, tokensSlash);
74107
}
108+
109+
function test_Query_Accept_RevertWhen_UsingConflictAccept(
110+
uint256 tokens,
111+
uint256 tokensSlash
112+
) public useIndexer useAllocation(tokens) {
113+
tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens));
114+
115+
resetPrank(users.fisherman);
116+
Attestation.Receipt memory receipt = _createAttestationReceipt(requestCID, responseCID, subgraphDeploymentId);
117+
bytes memory attestationData = _createAtestationData(receipt, allocationIDPrivateKey);
118+
bytes32 disputeID = _createQueryDispute(attestationData);
119+
120+
resetPrank(users.arbitrator);
121+
vm.expectRevert(abi.encodeWithSelector(
122+
IDisputeManager.DisputeManagerDisputeNotInConflict.selector,
123+
disputeID
124+
));
125+
disputeManager.acceptDisputeConflict(disputeID, tokensSlash, true, 0);
126+
}
75127
}

packages/subgraph-service/test/disputeManager/disputes/query/create.t.sol

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ contract DisputeManagerQueryCreateDisputeTest is DisputeManagerTest {
1717
* TESTS
1818
*/
1919

20-
function test_Query_Create_Dispute(uint256 tokens) public useIndexer useAllocation(tokens) {
20+
function test_Query_Create_Dispute_Only(uint256 tokens) public useIndexer useAllocation(tokens) {
2121
resetPrank(users.fisherman);
2222
Attestation.Receipt memory receipt = _createAttestationReceipt(requestCID, responseCID, subgraphDeploymentId);
2323
bytes memory attestationData = _createAtestationData(receipt, allocationIDPrivateKey);
2424
_createQueryDispute(attestationData);
2525
}
2626

27+
function test_Query_Create_Dispute_RevertWhen_SubgraphServiceNotSet(uint256 tokens) public useIndexer useAllocation(tokens) {
28+
resetPrank(users.fisherman);
29+
Attestation.Receipt memory receipt = _createAttestationReceipt(requestCID, responseCID, subgraphDeploymentId);
30+
bytes memory attestationData = _createAtestationData(receipt, allocationIDPrivateKey);
31+
32+
// clear subgraph service address from storage
33+
_setStorage_SubgraphService(address(0));
34+
35+
// // Approve the dispute deposit
36+
token.approve(address(disputeManager), disputeDeposit);
37+
38+
vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerSubgraphServiceNotSet.selector));
39+
disputeManager.createQueryDispute(attestationData);
40+
}
41+
2742
function test_Query_Create_MultipleDisputes_DifferentFisherman(
2843
uint256 tokens
2944
) public useIndexer useAllocation(tokens) {

0 commit comments

Comments
 (0)