Skip to content

Commit 59dcba0

Browse files
authored
Merge pull request #25 from kleros/feat/dispute-kit-interface
feat(DisputeKit): Dispute Kits abstraction for interfacing with KlerosCore
2 parents cbf1ddf + 2ae6bad commit 59dcba0

File tree

5 files changed

+107
-154
lines changed

5 files changed

+107
-154
lines changed

contracts/src/arbitration/dispute-kits/DisputeKit.sol renamed to contracts/src/arbitration/IDisputeKit.sol

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
pragma solidity ^0.8;
1212

13-
import "../IArbitrator.sol";
13+
import "./IArbitrator.sol";
1414

1515
/**
1616
* @title DisputeKit
17-
* Dispute kit abstraction for Kleros v2.
17+
* An abstraction of the Dispute Kits intended for interfacing with KlerosCore
18+
* This is not intended for use by the front-end clients for voting or appeal funding to allow for implementation-specific differences in parameters.
1819
*/
19-
abstract contract DisputeKit {
20+
interface IDisputeKit {
2021
// ************************************* //
2122
// * State Modifiers * //
2223
// ************************************* //
@@ -31,63 +32,14 @@ abstract contract DisputeKit {
3132
uint256 _disputeID,
3233
uint256 _numberOfChoices,
3334
bytes calldata _extraData
34-
) external virtual;
35+
) external;
3536

3637
/** @dev Draws the juror from the sortition tree. The drawn address is picked up by Kleros Core.
3738
* Note: Access restricted to Kleros Core only.
3839
* @param _disputeID The ID of the dispute in Kleros Core.
3940
* @return drawnAddress The drawn address.
4041
*/
41-
function draw(uint256 _disputeID) external virtual returns (address drawnAddress);
42-
43-
/** @dev Sets the caller's commit for the specified votes.
44-
* `O(n)` where
45-
* `n` is the number of votes.
46-
* @param _disputeID The ID of the dispute.
47-
* @param _voteIDs The IDs of the votes.
48-
* @param _commit The commit.
49-
*/
50-
function castCommit(
51-
uint256 _disputeID,
52-
uint256[] calldata _voteIDs,
53-
bytes32 _commit
54-
) external virtual;
55-
56-
/** @dev Sets the caller's choices for the specified votes.
57-
* `O(n)` where
58-
* `n` is the number of votes.
59-
* @param _disputeID The ID of the dispute.
60-
* @param _voteIDs The IDs of the votes.
61-
* @param _choice The choice.
62-
* @param _salt The salt for the commit if the votes were hidden.
63-
*/
64-
function castVote(
65-
uint256 _disputeID,
66-
uint256[] calldata _voteIDs,
67-
uint256 _choice,
68-
uint256 _salt
69-
) external virtual;
70-
71-
/** @dev Manages contributions, and appeals a dispute if at least two choices are fully funded.
72-
* Note that the surplus deposit will be reimbursed.
73-
* @param _disputeID Index of the dispute in Kleros Core contract.
74-
* @param _choice A choice that receives funding.
75-
*/
76-
function fundAppeal(uint256 _disputeID, uint256 _choice) external payable virtual;
77-
78-
/** @dev Allows to withdraw any reimbursable fees or rewards after the dispute gets resolved.
79-
* @param _disputeID Index of the dispute in Kleros Core contract.
80-
* @param _beneficiary The address whose rewards to withdraw.
81-
* @param _round The round the caller wants to withdraw from.
82-
* @param _choice The ruling option that the caller wants to withdraw from.
83-
* @return amount The withdrawn amount.
84-
*/
85-
function withdrawFeesAndRewards(
86-
uint256 _disputeID,
87-
address payable _beneficiary,
88-
uint256 _round,
89-
uint256 _choice
90-
) external virtual returns (uint256 amount);
42+
function draw(uint256 _disputeID) external returns (address drawnAddress);
9143

9244
// ************************************* //
9345
// * Public Views * //
@@ -97,7 +49,7 @@ abstract contract DisputeKit {
9749
* @param _disputeID The ID of the dispute in Kleros Core.
9850
* @return ruling The current ruling.
9951
*/
100-
function currentRuling(uint256 _disputeID) public view virtual returns (uint256 ruling);
52+
function currentRuling(uint256 _disputeID) external view returns (uint256 ruling);
10153

10254
/** @dev Gets the degree of coherence of a particular voter. This function is called by Kleros Core in order to determine the amount of the reward.
10355
* @param _disputeID The ID of the dispute in Kleros Core.
@@ -109,14 +61,14 @@ abstract contract DisputeKit {
10961
uint256 _disputeID,
11062
uint256 _round,
11163
uint256 _voteID
112-
) external view virtual returns (uint256);
64+
) external view returns (uint256);
11365

11466
/** @dev Gets the number of jurors who are eligible to a reward in this round.
11567
* @param _disputeID The ID of the dispute in Kleros Core.
11668
* @param _round The ID of the round.
11769
* @return The number of coherent jurors.
11870
*/
119-
function getCoherentCount(uint256 _disputeID, uint256 _round) external view virtual returns (uint256);
71+
function getCoherentCount(uint256 _disputeID, uint256 _round) external view returns (uint256);
12072

12173
/** @dev Returns true if the specified voter was active in this round.
12274
* @param _disputeID The ID of the dispute in Kleros Core.
@@ -128,7 +80,7 @@ abstract contract DisputeKit {
12880
uint256 _disputeID,
12981
uint256 _round,
13082
uint256 _voteID
131-
) external view virtual returns (bool);
83+
) external view returns (bool);
13284

13385
function getRoundInfo(
13486
uint256 _disputeID,
@@ -137,7 +89,6 @@ abstract contract DisputeKit {
13789
)
13890
external
13991
view
140-
virtual
14192
returns (
14293
uint256 winningChoice,
14394
bool tied,
@@ -154,7 +105,6 @@ abstract contract DisputeKit {
154105
)
155106
external
156107
view
157-
virtual
158108
returns (
159109
address account,
160110
bytes32 commit,

contracts/src/arbitration/KlerosCore.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pragma solidity ^0.8;
1212

1313
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1414
import "./IArbitrator.sol";
15-
import "./dispute-kits/DisputeKit.sol";
15+
import "./IDisputeKit.sol";
1616
import {SortitionSumTreeFactory} from "../data-structures/SortitionSumTreeFactory.sol";
1717

1818
/**
@@ -49,7 +49,7 @@ contract KlerosCore is IArbitrator {
4949
struct Dispute {
5050
uint96 subcourtID; // The ID of the subcourt the dispute is in.
5151
IArbitrable arbitrated; // The arbitrable contract.
52-
DisputeKit disputeKit; // ID of the dispute kit that this dispute was assigned to.
52+
IDisputeKit disputeKit; // ID of the dispute kit that this dispute was assigned to.
5353
Period period; // The current period of the dispute.
5454
bool ruled; // True if the ruling has been executed, false otherwise.
5555
uint256 currentRound; // The index of the current appeal round. Note that 0 represents the default dispute round. Former votes.length - 1.
@@ -90,7 +90,7 @@ contract KlerosCore is IArbitrator {
9090
Court[] public courts; // The subcourts.
9191

9292
//TODO: disputeKits forest.
93-
DisputeKit[] public disputeKits; // All supported dispute kits.
93+
IDisputeKit[] public disputeKits; // All supported dispute kits.
9494

9595
Dispute[] public disputes; // The disputes.
9696
mapping(address => Juror) internal jurors; // The jurors.
@@ -138,7 +138,7 @@ contract KlerosCore is IArbitrator {
138138
address _governor,
139139
IERC20 _pinakion,
140140
address _jurorProsecutionModule,
141-
DisputeKit _disputeKit,
141+
IDisputeKit _disputeKit,
142142
bool _hiddenVotes,
143143
uint256 _minStake,
144144
uint256 _alpha,
@@ -211,7 +211,7 @@ contract KlerosCore is IArbitrator {
211211
/** @dev Add a new supported dispute kit module to the court.
212212
* @param _disputeKitAddress The address of the dispute kit contract.
213213
*/
214-
function addNewDisputeKit(DisputeKit _disputeKitAddress) external onlyByGovernor {
214+
function addNewDisputeKit(IDisputeKit _disputeKitAddress) external onlyByGovernor {
215215
// TODO: the dispute kit data structure. For now keep it a simple array.
216216
// Also note that in current state this function doesn't take into account that the added address is actually new.
217217
require(disputeKits.length <= 256); // Can't be more than 256 because the IDs are used in a bitfield.
@@ -375,7 +375,7 @@ contract KlerosCore is IArbitrator {
375375
dispute.subcourtID = subcourtID;
376376
dispute.arbitrated = IArbitrable(msg.sender);
377377

378-
DisputeKit disputeKit = disputeKits[disputeKitID];
378+
IDisputeKit disputeKit = disputeKits[disputeKitID];
379379
dispute.disputeKit = disputeKit;
380380

381381
dispute.lastPeriodChange = block.timestamp;
@@ -449,7 +449,7 @@ contract KlerosCore is IArbitrator {
449449
function draw(uint256 _disputeID, uint256 _iterations) external {
450450
Dispute storage dispute = disputes[_disputeID];
451451
require(dispute.period == Period.evidence, "Should be evidence period.");
452-
DisputeKit disputeKit = dispute.disputeKit;
452+
IDisputeKit disputeKit = dispute.disputeKit;
453453
uint256 startIndex = dispute.drawnJurors[dispute.currentRound].length;
454454
uint256 endIndex = startIndex + _iterations <= dispute.nbVotes ? startIndex + _iterations : dispute.nbVotes;
455455

@@ -652,7 +652,7 @@ contract KlerosCore is IArbitrator {
652652
* @return ruling The current ruling.
653653
*/
654654
function currentRuling(uint256 _disputeID) public view returns (uint256 ruling) {
655-
DisputeKit disputeKit = disputes[_disputeID].disputeKit;
655+
IDisputeKit disputeKit = disputes[_disputeID].disputeKit;
656656
return disputeKit.currentRuling(_disputeID);
657657
}
658658

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
/**
4+
* @authors: [@unknownunknown1, @jaybuidl]
5+
* @reviewers: []
6+
* @auditors: []
7+
* @bounties: []
8+
* @deployments: []
9+
*/
10+
11+
pragma solidity ^0.8;
12+
13+
import "../IDisputeKit.sol";
14+
import "../KlerosCore.sol";
15+
16+
/**
17+
* @title BaseDisputeKit
18+
* Provides common basic behaviours to the Dispute Kit implementations.
19+
*/
20+
abstract contract BaseDisputeKit is IDisputeKit {
21+
// ************************************* //
22+
// * Storage * //
23+
// ************************************* //
24+
25+
address public governor; // The governor of the contract.
26+
KlerosCore public core; // The Kleros Core arbitrator
27+
28+
// ************************************* //
29+
// * Function Modifiers * //
30+
// ************************************* //
31+
32+
modifier onlyByGovernor() {
33+
require(governor == msg.sender, "Access not allowed: Governor only.");
34+
_;
35+
}
36+
37+
modifier onlyByCore() {
38+
require(address(core) == msg.sender, "Access not allowed: KlerosCore only.");
39+
_;
40+
}
41+
42+
/** @dev Constructor.
43+
* @param _governor The governor's address.
44+
* @param _core The KlerosCore arbitrator.
45+
*/
46+
constructor(address _governor, KlerosCore _core) {
47+
governor = _governor;
48+
core = _core;
49+
}
50+
51+
// ************************ //
52+
// * Governance * //
53+
// ************************ //
54+
55+
/** @dev Allows the governor to call anything on behalf of the contract.
56+
* @param _destination The destination of the call.
57+
* @param _amount The value sent with the call.
58+
* @param _data The data sent with the call.
59+
*/
60+
function executeGovernorProposal(
61+
address _destination,
62+
uint256 _amount,
63+
bytes memory _data
64+
) external onlyByGovernor {
65+
(bool success, ) = _destination.call{value: _amount}(_data);
66+
require(success, "Unsuccessful call");
67+
}
68+
}

0 commit comments

Comments
 (0)