Skip to content

Commit 2e15da9

Browse files
authored
disputes: update events and setters (#183)
* disputes: improve events * disputes: add a salt to the domain separator * disputes: add setter for staking contract
1 parent 7540bb2 commit 2e15da9

File tree

3 files changed

+61
-28
lines changed

3 files changed

+61
-28
lines changed

contracts/DisputeManager.sol

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
pragma solidity ^0.6.4;
22
pragma experimental ABIEncoderV2;
33

4-
/*
5-
* @title Dispute management
6-
* @notice Provides a way to align the incentives of participants ensuring that Query Results are trustful.
7-
*/
8-
94
import "./Governed.sol";
105
import "./GraphToken.sol";
116
import "./Staking.sol";
127
import "./bytes/BytesLib.sol";
138
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
149

1510

11+
/*
12+
* @title DisputeManager
13+
* @dev Provides a way to align the incentives of participants ensuring that query results are trustful.
14+
*/
1615
contract DisputeManager is Governed {
1716
using BytesLib for bytes;
1817
using ECDSA for bytes32;
@@ -63,6 +62,7 @@ contract DisputeManager is Governed {
6362
);
6463
bytes32 private constant DOMAIN_NAME_HASH = keccak256("Graph Protocol");
6564
bytes32 private constant DOMAIN_VERSION_HASH = keccak256("0.1");
65+
bytes32 private constant DOMAIN_SALT = 0xa070ffb1cd7409649bf77822cce74495468e06dbfaef09556838bf188679b9c2;
6666
bytes32 private constant ATTESTATION_TYPE_HASH = keccak256(
6767
"Attestation(IpfsHash requestCID,IpfsHash responseCID,uint256 gasUsed,uint256 responseNumBytes)IpfsHash(bytes32 hash,uint16 hashFunction)"
6868
);
@@ -108,6 +108,7 @@ contract DisputeManager is Governed {
108108
bytes32 indexed subgraphID,
109109
address indexed indexNode,
110110
address indexed fisherman,
111+
uint256 tokens,
111112
bytes attestation
112113
);
113114

@@ -116,23 +117,23 @@ contract DisputeManager is Governed {
116117
bytes32 indexed subgraphID,
117118
address indexed indexNode,
118119
address indexed fisherman,
119-
uint256 deposit
120+
uint256 tokens
120121
);
121122

122123
event DisputeRejected(
123124
bytes32 disputeID,
124125
bytes32 indexed subgraphID,
125126
address indexed indexNode,
126127
address indexed fisherman,
127-
uint256 deposit
128+
uint256 tokens
128129
);
129130

130131
event DisputeIgnored(
131132
bytes32 disputeID,
132133
bytes32 indexed subgraphID,
133134
address indexed indexNode,
134135
address indexed fisherman,
135-
uint256 deposit
136+
uint256 tokens
136137
);
137138

138139
modifier onlyArbitrator {
@@ -173,7 +174,8 @@ contract DisputeManager is Governed {
173174
DOMAIN_NAME_HASH,
174175
DOMAIN_VERSION_HASH,
175176
_getChainID(),
176-
address(this)
177+
address(this),
178+
DOMAIN_SALT
177179
)
178180
);
179181
}
@@ -267,6 +269,15 @@ contract DisputeManager is Governed {
267269
slashingPercentage = _percentage;
268270
}
269271

272+
/**
273+
* @dev Set the staking contract used for slashing
274+
* @notice Update the staking contract to `_staking`
275+
* @param _staking Address of the staking contract
276+
*/
277+
function setStaking(Staking _staking) external onlyGovernor {
278+
staking = _staking;
279+
}
280+
270281
/**
271282
* @dev Accept tokens
272283
* @notice Receive Graph tokens
@@ -418,7 +429,7 @@ contract DisputeManager is Governed {
418429
// Store dispute
419430
disputes[disputeID] = Dispute(_subgraphID, indexNode, _fisherman, _deposit);
420431

421-
emit DisputeCreated(disputeID, _subgraphID, indexNode, _fisherman, _attestation);
432+
emit DisputeCreated(disputeID, _subgraphID, indexNode, _fisherman, _deposit, _attestation);
422433
}
423434

424435
/**

test/disputes.test.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ contract('Disputes', ([me, other, governor, arbitrator, indexNode, fisherman]) =
7272
})
7373
})
7474

75+
describe('minimumDeposit', function() {
76+
it('should set `minimumDeposit`', async function() {
77+
const minimumDeposit = defaults.dispute.minimumDeposit
78+
const newMinimumDeposit = web3.utils.toBN(1)
79+
80+
// Set right in the constructor
81+
expect(await this.disputeManager.minimumDeposit()).to.be.bignumber.eq(minimumDeposit)
82+
83+
// Set new value
84+
await this.disputeManager.setMinimumDeposit(newMinimumDeposit, {
85+
from: governor,
86+
})
87+
expect(await this.disputeManager.minimumDeposit()).to.be.bignumber.eq(newMinimumDeposit)
88+
})
89+
90+
it('reject set `minimumDeposit` if not allowed', async function() {
91+
await expectRevert(
92+
this.disputeManager.setMinimumDeposit(defaults.dispute.minimumDeposit, {
93+
from: other,
94+
}),
95+
'Only Governor can call',
96+
)
97+
})
98+
})
99+
75100
describe('rewardPercentage', function() {
76101
it('should set `rewardPercentage`', async function() {
77102
const rewardPercentage = defaults.dispute.rewardPercentage
@@ -140,24 +165,19 @@ contract('Disputes', ([me, other, governor, arbitrator, indexNode, fisherman]) =
140165
})
141166
})
142167

143-
describe('minimumDeposit', function() {
144-
it('should set `minimumDeposit`', async function() {
145-
const minimumDeposit = defaults.dispute.minimumDeposit
146-
const newMinimumDeposit = web3.utils.toBN(1)
147-
168+
describe('staking', function() {
169+
it('should set `staking`', async function() {
148170
// Set right in the constructor
149-
expect(await this.disputeManager.minimumDeposit()).to.be.bignumber.eq(minimumDeposit)
171+
expect(await this.disputeManager.staking()).to.eq(this.staking.address)
150172

151-
// Set new value
152-
await this.disputeManager.setMinimumDeposit(newMinimumDeposit, {
153-
from: governor,
154-
})
155-
expect(await this.disputeManager.minimumDeposit()).to.be.bignumber.eq(newMinimumDeposit)
173+
// Can set if allowed
174+
await this.disputeManager.setStaking(this.graphToken.address, { from: governor })
175+
expect(await this.disputeManager.staking()).to.eq(this.graphToken.address)
156176
})
157177

158-
it('reject set `minimumDeposit` if not allowed', async function() {
178+
it('reject set `staking` if not allowed', async function() {
159179
await expectRevert(
160-
this.disputeManager.setMinimumDeposit(defaults.dispute.minimumDeposit, {
180+
this.disputeManager.setStaking(this.graphToken.address, {
161181
from: other,
162182
}),
163183
'Only Governor can call',
@@ -302,6 +322,7 @@ contract('Disputes', ([me, other, governor, arbitrator, indexNode, fisherman]) =
302322
subgraphID: this.subgraphId,
303323
indexNode: indexNode,
304324
fisherman: fisherman,
325+
tokens: this.tokensForFisherman,
305326
attestation: this.dispute.attestation,
306327
})
307328
})
@@ -429,7 +450,7 @@ contract('Disputes', ([me, other, governor, arbitrator, indexNode, fisherman]) =
429450
subgraphID: this.subgraphId,
430451
indexNode: indexNode,
431452
fisherman: fisherman,
432-
deposit: deposit.add(reward),
453+
tokens: deposit.add(reward),
433454
})
434455
})
435456
})
@@ -477,7 +498,7 @@ contract('Disputes', ([me, other, governor, arbitrator, indexNode, fisherman]) =
477498
subgraphID: this.subgraphId,
478499
indexNode: indexNode,
479500
fisherman: fisherman,
480-
deposit: this.tokensForFisherman,
501+
tokens: this.tokensForFisherman,
481502
})
482503
})
483504
})
@@ -520,7 +541,7 @@ contract('Disputes', ([me, other, governor, arbitrator, indexNode, fisherman]) =
520541
subgraphID: this.subgraphId,
521542
indexNode: indexNode,
522543
fisherman: fisherman,
523-
deposit: this.tokensForFisherman,
544+
tokens: this.tokensForFisherman,
524545
})
525546
})
526547
})

test/lib/attestation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ function createDomainSeparatorHash(contractAddress) {
4646
)
4747
const domainNameHash = web3.utils.sha3('Graph Protocol')
4848
const domainVersionHash = web3.utils.sha3('0.1')
49+
const domainSalt = '0xa070ffb1cd7409649bf77822cce74495468e06dbfaef09556838bf188679b9c2'
4950

5051
// ABI encoded
5152
return web3.utils.sha3(
5253
web3.eth.abi.encodeParameters(
53-
['bytes32', 'bytes32', 'bytes32', 'uint256', 'address'],
54-
[domainTypeHash, domainNameHash, domainVersionHash, chainId, contractAddress],
54+
['bytes32', 'bytes32', 'bytes32', 'uint256', 'address', 'bytes32'],
55+
[domainTypeHash, domainNameHash, domainVersionHash, chainId, contractAddress, domainSalt],
5556
),
5657
)
5758
}

0 commit comments

Comments
 (0)