Skip to content

Commit 0339f70

Browse files
authored
disputes: attestation commons (#212)
* disputes: make disputes work with the common-ts attestation library * build: bump common-ts version * build: fix install private pkgs in CI
1 parent d59900d commit 0339f70

File tree

7 files changed

+2120
-116
lines changed

7 files changed

+2120
-116
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
2+
cache/
23
coverage/
34
node_modules/
45
truffle.js

.github/workflows/npmtest.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
strategy:
1817
matrix:
1918
node-version: [10.x, 12.x]
2019

2120
steps:
22-
- uses: actions/checkout@v2
23-
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v1
25-
with:
26-
node-version: ${{ matrix.node-version }}
27-
- run: npm ci
28-
- run: npm run build --if-present
29-
- run: npm test
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- shell: bash
27+
env:
28+
NPM_TOKEN: ${{secrets.npm_token}}
29+
run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > ~/.npmrc
30+
- run: npm ci
31+
- run: npm run build --if-present
32+
- run: npm test

contracts/Curation.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,15 @@ contract Curation is Governed, BancorFormula {
197197
function stake(bytes32 _subgraphID, uint256 _tokens) external {
198198
address curator = msg.sender;
199199

200+
// Need to stake some funds
201+
require(_tokens > 0, "Cannot stake zero tokens");
202+
200203
// Transfer tokens from the curator to this contract
201204
require(
202205
token.transferFrom(curator, address(this), _tokens),
203206
"Cannot transfer tokens to stake"
204207
);
208+
205209
// Stake transferred tokens to subgraph
206210
_stake(curator, _subgraphID, _tokens);
207211
}

contracts/DisputeManager.sol

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import "./Governed.sol";
55
import "./GraphToken.sol";
66
import "./Staking.sol";
77

8-
98
/*
109
* @title DisputeManager
1110
* @dev Provides a way to align the incentives of participants ensuring that query results are trustful.
@@ -23,6 +22,13 @@ contract DisputeManager is Governed {
2322

2423
// -- Attestation --
2524

25+
// Receipt content sent from indexer in response to request
26+
struct Receipt {
27+
bytes32 requestCID;
28+
bytes32 responseCID;
29+
bytes32 subgraphID;
30+
}
31+
2632
// Attestation sent from indexer in response to a request
2733
struct Attestation {
2834
bytes32 requestCID;
@@ -215,14 +221,19 @@ contract DisputeManager is Governed {
215221
* @param _receipt Receipt returned by indexer and submitted by fisherman
216222
* @return Message hash used to sign the receipt
217223
*/
218-
function encodeHashReceipt(bytes memory _receipt) public view returns (bytes32) {
224+
function encodeHashReceipt(Receipt memory _receipt) public view returns (bytes32) {
219225
return
220226
keccak256(
221227
abi.encodePacked(
222228
"\x19\x01", // EIP-191 encoding pad, EIP-712 version 1
223229
DOMAIN_SEPARATOR,
224230
keccak256(
225-
abi.encode(RECEIPT_TYPE_HASH, _receipt) // EIP 712-encoded message hash
231+
abi.encode(
232+
RECEIPT_TYPE_HASH,
233+
_receipt.requestCID,
234+
_receipt.responseCID,
235+
_receipt.subgraphID
236+
) // EIP 712-encoded message hash
226237
)
227238
)
228239
);
@@ -292,11 +303,15 @@ contract DisputeManager is Governed {
292303
{
293304
address fisherman = msg.sender;
294305

306+
// Ensure that fisherman has staked at least the minimum amount
307+
require(_deposit >= minimumDeposit, "Dispute deposit is under minimum required");
308+
295309
// Transfer tokens to deposit from fisherman to this contract
296310
require(
297311
token.transferFrom(fisherman, address(this), _deposit),
298312
"Cannot transfer tokens to deposit"
299313
);
314+
300315
// Create a dispute using the received attestation and deposit
301316
_createDispute(fisherman, _deposit, _attestationData);
302317
}
@@ -424,9 +439,6 @@ contract DisputeManager is Governed {
424439
// This also validates that indexer exists
425440
require(staking.hasStake(indexer), "Dispute has no stake by the indexer");
426441

427-
// Ensure that fisherman has staked at least the minimum amount
428-
require(_deposit >= minimumDeposit, "Dispute deposit is under minimum required");
429-
430442
// A fisherman can only open one dispute for a given indexer / subgraphID at a time
431443
require(!isDisputeCreated(disputeID), "Dispute already created"); // Must be empty
432444

@@ -450,7 +462,7 @@ contract DisputeManager is Governed {
450462
*/
451463
function _recoverAttestationSigner(Attestation memory _attestation) private view returns (address) {
452464
// Obtain the hash of the fully-encoded message, per EIP-712 encoding
453-
bytes memory receipt = abi.encode(
465+
Receipt memory receipt = Receipt(
454466
_attestation.requestCID,
455467
_attestation.responseCID,
456468
_attestation.subgraphID

0 commit comments

Comments
 (0)