Skip to content

Commit e81fb8b

Browse files
fix(IArbitrator): interface simplification
1 parent 02c20ce commit e81fb8b

File tree

4 files changed

+35
-71
lines changed

4 files changed

+35
-71
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 0.1.0 (2021-11-25)
1+
## 0.1.0 (2021-11-30)
22

33
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
4+
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
45
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
56
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))
67
- feat(Arbitration): standard update ([ed930de](https://github.com/kleros/kleros-v2/commit/ed930de))

contracts/src/arbitration/ArbitrableExample.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "./IArbitrable.sol";
66

77
/**
88
* @title ArbitrableExample
9-
* An example of an arbitrable contract which connects to the arbitator that implements the updated interface.
9+
* An example of the arbitrable contract which connects to the arbitator that implements IArbitrator interface.
1010
*/
1111
contract ArbitrableExample is IArbitrable {
1212
struct DisputeStruct {

contracts/src/arbitration/CentralizedArbitrator.sol

+28-45
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ pragma solidity ^0.8;
55
import "./IArbitrator.sol";
66

77
/** @title Centralized Arbitrator
8-
* @dev This is a centralized arbitrator deciding alone on the result of disputes. It illustrates how the appeals can be handled on the arbitrator level.
9-
* In this particular contract the rulings can be appealed by crowdfunding a desired choice.
10-
* Note that normally the arbitrator should use a Dispute Kit contract which will define the algorithm for appeals/withdrawals.
11-
* However to avoid complexity the code of the Dispute Kit is inlined within this contract.
8+
* @dev This is a centralized arbitrator deciding alone on the result of disputes. It illustrates how IArbitrator interface can be implemented.
9+
* Note that this contract supports appeals. The ruling given by the arbitrator can be appealed by crowdfunding a desired choice.
1210
*/
1311
contract CentralizedArbitrator is IArbitrator {
1412
/* Constants */
@@ -19,6 +17,14 @@ contract CentralizedArbitrator is IArbitrator {
1917
uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000; // Multiplier of the appeal period for the choice that wasn't voted for in the previous round, in basis points. Default is 1/2 of original appeal period.
2018
uint256 public constant MULTIPLIER_DIVISOR = 10000;
2119

20+
/* Enums */
21+
22+
enum DisputeStatus {
23+
Waiting, // The dispute is waiting for the ruling or not created.
24+
Appealable, // The dispute can be appealed.
25+
Solved // The dispute is resolved.
26+
}
27+
2228
/* Structs */
2329

2430
struct DisputeStruct {
@@ -44,7 +50,7 @@ contract CentralizedArbitrator is IArbitrator {
4450
address public owner = msg.sender; // Owner of the contract.
4551
uint256 public appealDuration; // The duration of the appeal period.
4652

47-
uint256 private arbitrationFee; // The cost to create a dispute. Made private because of the arbitrationCost() getter.
53+
uint256 private arbitrationFee; // The cost to create a dispute. Made private because of the cost() getter.
4854
uint256 public appealFee; // The cost to fund one of the choices, not counting the additional fee stake amount.
4955

5056
DisputeStruct[] public disputes; // Stores the dispute info. disputes[disputeID].
@@ -149,7 +155,7 @@ contract CentralizedArbitrator is IArbitrator {
149155
}
150156

151157
/** @dev Create a dispute. Must be called by the arbitrable contract.
152-
* Must be paid at least arbitrationCost().
158+
* Must be paid at least cost().
153159
* @param _choices Amount of choices the arbitrator can make in this dispute.
154160
* @param _extraData Can be used to give additional info on the dispute to be created.
155161
* @return disputeID ID of the dispute created.
@@ -160,8 +166,8 @@ contract CentralizedArbitrator is IArbitrator {
160166
override
161167
returns (uint256 disputeID)
162168
{
163-
uint256 localArbitrationCost = arbitrationCost(_extraData);
164-
require(msg.value >= localArbitrationCost, "Not enough ETH to cover arbitration costs.");
169+
uint256 arbitrationCost = cost(_extraData);
170+
require(msg.value >= arbitrationCost, "Not enough ETH to cover arbitration costs.");
165171
disputeID = disputes.length;
166172
disputes.push(
167173
DisputeStruct({
@@ -193,18 +199,15 @@ contract CentralizedArbitrator is IArbitrator {
193199
require(block.timestamp >= appealPeriodStart && block.timestamp < appealPeriodEnd, "Appeal period is over.");
194200

195201
uint256 multiplier;
196-
{
197-
uint256 winner = currentRuling(_disputeID);
198-
if (winner == _choice) {
199-
multiplier = WINNER_STAKE_MULTIPLIER;
200-
} else {
201-
require(
202-
block.timestamp - appealPeriodStart <
203-
((appealPeriodEnd - appealPeriodStart) * LOSER_APPEAL_PERIOD_MULTIPLIER) / MULTIPLIER_DIVISOR,
204-
"Appeal period is over for loser"
205-
);
206-
multiplier = LOSER_STAKE_MULTIPLIER;
207-
}
202+
if (dispute.ruling == _choice) {
203+
multiplier = WINNER_STAKE_MULTIPLIER;
204+
} else {
205+
require(
206+
block.timestamp - appealPeriodStart <
207+
((appealPeriodEnd - appealPeriodStart) * LOSER_APPEAL_PERIOD_MULTIPLIER) / MULTIPLIER_DIVISOR,
208+
"Appeal period is over for loser"
209+
);
210+
multiplier = LOSER_STAKE_MULTIPLIER;
208211
}
209212

210213
Round[] storage rounds = disputeIDtoRoundArray[_disputeID];
@@ -248,7 +251,7 @@ contract CentralizedArbitrator is IArbitrator {
248251
/** @dev Give a ruling to a dispute. Once it's given the dispute can be appealed, and after the appeal period has passed this function should be called again to finalize the ruling.
249252
* Accounts for the situation where the winner loses a case due to paying less appeal fees than expected.
250253
* @param _disputeID ID of the dispute to rule.
251-
* @param _ruling Ruling given by the arbitrator. Note that 0 means "Not able/wanting to make a decision".
254+
* @param _ruling Ruling given by the arbitrator. Note that 0 means that arbitrator chose "Refused to rule".
252255
*/
253256
function giveRuling(uint256 _disputeID, uint256 _ruling) external onlyOwner {
254257
DisputeStruct storage dispute = disputes[_disputeID];
@@ -326,7 +329,7 @@ contract CentralizedArbitrator is IArbitrator {
326329
/** @dev Cost of arbitration.
327330
* @return fee The required amount.
328331
*/
329-
function arbitrationCost(
332+
function cost(
330333
bytes calldata /*_extraData*/
331334
) public view override returns (uint256 fee) {
332335
return arbitrationFee;
@@ -343,16 +346,12 @@ contract CentralizedArbitrator is IArbitrator {
343346
require(_choice <= dispute.choices, "There is no such ruling to fund.");
344347
require(dispute.status == DisputeStatus.Appealable, "Dispute not appealable.");
345348

346-
uint256 multiplier;
347-
uint256 winner = currentRuling(_disputeID);
348-
if (winner == _choice) {
349-
multiplier = WINNER_STAKE_MULTIPLIER;
349+
if (dispute.ruling == _choice) {
350+
goal = appealFee + (appealFee * WINNER_STAKE_MULTIPLIER) / MULTIPLIER_DIVISOR;
350351
} else {
351-
multiplier = LOSER_STAKE_MULTIPLIER;
352+
goal = appealFee + (appealFee * LOSER_STAKE_MULTIPLIER) / MULTIPLIER_DIVISOR;
352353
}
353354

354-
goal = appealFee + (appealFee * multiplier) / MULTIPLIER_DIVISOR;
355-
356355
Round[] storage rounds = disputeIDtoRoundArray[_disputeID];
357356
Round storage lastRound = rounds[rounds.length - 1];
358357

@@ -372,20 +371,4 @@ contract CentralizedArbitrator is IArbitrator {
372371
}
373372
return (start, end);
374373
}
375-
376-
/** @dev Return the status of a dispute.
377-
* @param _disputeID ID of the dispute.
378-
* @return status The status of the dispute.
379-
*/
380-
function disputeStatus(uint256 _disputeID) public view override returns (DisputeStatus status) {
381-
return disputes[_disputeID].status;
382-
}
383-
384-
/** @dev Return the ruling of a dispute.
385-
* @param _disputeID ID of the dispute.
386-
* @return ruling The ruling which would or has been given.
387-
*/
388-
function currentRuling(uint256 _disputeID) public view override returns (uint256 ruling) {
389-
return disputes[_disputeID].ruling;
390-
}
391374
}

contracts/src/arbitration/IArbitrator.sol

+4-24
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@ import "./IArbitrable.sol";
66

77
/**
88
* @title Arbitrator
9-
* Arbitrator interface for CourtV2.
9+
* Arbitrator interface that implements the new arbitration standard.
1010
* Unlike the ERC-792 this standard doesn't have anything related to appeals, so each arbitrator can implement an appeal system that suits it the most.
1111
* When developing arbitrator contracts we need to:
1212
* - Define the functions for dispute creation (createDispute). Don't forget to store the arbitrated contract and the disputeID (which should be unique, may nbDisputes).
13-
* - Define the functions for cost display (arbitrationCost).
13+
* - Define the functions for cost display (cost).
1414
* - Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
1515
*/
1616
interface IArbitrator {
17-
enum DisputeStatus {
18-
Waiting,
19-
Appealable,
20-
Solved
21-
}
22-
2317
/**
2418
* @dev To be emitted when a dispute is created.
2519
* @param _disputeID ID of the dispute.
@@ -29,7 +23,7 @@ interface IArbitrator {
2923

3024
/**
3125
* @dev Create a dispute. Must be called by the arbitrable contract.
32-
* Must pay at least arbitrationCost(_extraData).
26+
* Must pay at least cost(_extraData).
3327
* @param _choices Amount of choices the arbitrator can make in this dispute.
3428
* @param _extraData Can be used to give additional info on the dispute to be created.
3529
* @return disputeID ID of the dispute created.
@@ -41,19 +35,5 @@ interface IArbitrator {
4135
* @param _extraData Can be used to give additional info on the dispute to be created.
4236
* @return cost Required cost of arbitration.
4337
*/
44-
function arbitrationCost(bytes calldata _extraData) external view returns (uint256 cost);
45-
46-
/**
47-
* @dev Return the status of a dispute.
48-
* @param _disputeID ID of the dispute to rule.
49-
* @return status The status of the dispute.
50-
*/
51-
function disputeStatus(uint256 _disputeID) external view returns (DisputeStatus status);
52-
53-
/**
54-
* @dev Return the current ruling of a dispute. This is useful for parties to know if they should appeal.
55-
* @param _disputeID ID of the dispute.
56-
* @return ruling The ruling which has been given or the one which will be given if there is no appeal.
57-
*/
58-
function currentRuling(uint256 _disputeID) external view returns (uint256 ruling);
38+
function cost(bytes calldata _extraData) external view returns (uint256 cost);
5939
}

0 commit comments

Comments
 (0)