KlerosCore

Git Source

Inherits: IArbitrator

State Variables

FORKING_COURT

uint96 public constant FORKING_COURT = 0;

GENERAL_COURT

uint96 public constant GENERAL_COURT = 1;

NULL_DISPUTE_KIT

uint256 public constant NULL_DISPUTE_KIT = 0;

DISPUTE_KIT_CLASSIC

uint256 public constant DISPUTE_KIT_CLASSIC = 1;

DEFAULT_NB_OF_JURORS

uint256 public constant DEFAULT_NB_OF_JURORS = 3;

ALPHA_DIVISOR

uint256 public constant ALPHA_DIVISOR = 1e4;

NON_PAYABLE_AMOUNT

uint256 public constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2;

SEARCH_ITERATIONS

uint256 public constant SEARCH_ITERATIONS = 10;

governor

address public governor;

pinakion

IERC20 public pinakion;

jurorProsecutionModule

address public jurorProsecutionModule;

sortitionModule

ISortitionModule public sortitionModule;

courts

Court[] public courts;

disputeKitNodes

DisputeKitNode[] public disputeKitNodes;

disputes

Dispute[] public disputes;

jurors

mapping(address => Juror) internal jurors;

Functions

onlyByGovernor

modifier onlyByGovernor();

constructor

Constructor.

constructor(
    address _governor,
    IERC20 _pinakion,
    address _jurorProsecutionModule,
    IDisputeKit _disputeKit,
    bool _hiddenVotes,
    uint256[4] memory _courtParameters,
    uint256[4] memory _timesPerPeriod,
    bytes memory _sortitionExtraData,
    ISortitionModule _sortitionModuleAddress
);

Parameters

NameTypeDescription
_governoraddressThe governor's address.
_pinakionIERC20The address of the token contract.
_jurorProsecutionModuleaddressThe address of the juror prosecution module.
_disputeKitIDisputeKitThe address of the default dispute kit.
_hiddenVotesboolThe hiddenVotes property value of the general court.
_courtParametersuint256[4]Numeric parameters of General court (minStake, alpha, feeForJuror and jurorsForCourtJump respectively).
_timesPerPerioduint256[4]The timesPerPeriod property value of the general court.
_sortitionExtraDatabytesThe extra data for sortition module.
_sortitionModuleAddressISortitionModuleThe sortition module responsible for sortition of the jurors.

executeGovernorProposal

Allows the governor to call anything on behalf of the contract.

function executeGovernorProposal(address _destination, uint256 _amount, bytes memory _data) external onlyByGovernor;

Parameters

NameTypeDescription
_destinationaddressThe destination of the call.
_amountuint256The value sent with the call.
_databytesThe data sent with the call.

changeGovernor

Changes the governor storage variable.

function changeGovernor(address payable _governor) external onlyByGovernor;

Parameters

NameTypeDescription
_governoraddress payableThe new value for the governor storage variable.

changePinakion

Changes the pinakion storage variable.

function changePinakion(IERC20 _pinakion) external onlyByGovernor;

Parameters

NameTypeDescription
_pinakionIERC20The new value for the pinakion storage variable.

changeJurorProsecutionModule

Changes the jurorProsecutionModule storage variable.

function changeJurorProsecutionModule(address _jurorProsecutionModule) external onlyByGovernor;

Parameters

NameTypeDescription
_jurorProsecutionModuleaddressThe new value for the jurorProsecutionModule storage variable.

changeSortitionModule

Changes the _sortitionModule storage variable. Note that the new module should be initialized for all courts.

function changeSortitionModule(ISortitionModule _sortitionModule) external onlyByGovernor;

Parameters

NameTypeDescription
_sortitionModuleISortitionModuleThe new value for the sortitionModule storage variable.

addNewDisputeKit

Add a new supported dispute kit module to the court.

function addNewDisputeKit(IDisputeKit _disputeKitAddress, uint256 _parent) external onlyByGovernor;

Parameters

NameTypeDescription
_disputeKitAddressIDisputeKitThe address of the dispute kit contract.
_parentuint256The ID of the parent dispute kit. It is left empty when root DK is created. Note that the root DK must be supported by the general court.

createCourt

Creates a court under a specified parent court.

function createCourt(
    uint96 _parent,
    bool _hiddenVotes,
    uint256 _minStake,
    uint256 _alpha,
    uint256 _feeForJuror,
    uint256 _jurorsForCourtJump,
    uint256[4] memory _timesPerPeriod,
    bytes memory _sortitionExtraData,
    uint256[] memory _supportedDisputeKits
) external onlyByGovernor;

Parameters

NameTypeDescription
_parentuint96The parent property value of the court.
_hiddenVotesboolThe hiddenVotes property value of the court.
_minStakeuint256The minStake property value of the court.
_alphauint256The alpha property value of the court.
_feeForJuroruint256The feeForJuror property value of the court.
_jurorsForCourtJumpuint256The jurorsForCourtJump property value of the court.
_timesPerPerioduint256[4]The timesPerPeriod property value of the court.
_sortitionExtraDatabytesExtra data for sortition module.
_supportedDisputeKitsuint256[]Indexes of dispute kits that this court will support.

changeCourtMinStake

Changes the minStake property value of a specified court. Don't set to a value lower than its parent's minStake property value.

function changeCourtMinStake(uint96 _courtID, uint256 _minStake) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_minStakeuint256The new value for the minStake property value.

changeCourtAlpha

Changes the alpha property value of a specified court.

function changeCourtAlpha(uint96 _courtID, uint256 _alpha) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_alphauint256The new value for the alpha property value.

changeCourtJurorFee

Changes the feeForJuror property value of a specified court.

function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_feeForJuroruint256The new value for the feeForJuror property value.

changeCourtJurorsForJump

Changes the jurorsForCourtJump property value of a specified court.

function changeCourtJurorsForJump(uint96 _courtID, uint256 _jurorsForCourtJump) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_jurorsForCourtJumpuint256The new value for the jurorsForCourtJump property value.

changeCourtHiddenVotes

Changes the hiddenVotes property value of a specified court.

function changeCourtHiddenVotes(uint96 _courtID, bool _hiddenVotes) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_hiddenVotesboolThe new value for the hiddenVotes property value.

changeCourtTimesPerPeriod

Changes the timesPerPeriod property value of a specified court.

function changeCourtTimesPerPeriod(uint96 _courtID, uint256[4] memory _timesPerPeriod) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_timesPerPerioduint256[4]The new value for the timesPerPeriod property value.

enableDisputeKits

Adds/removes court's support for specified dispute kits.

function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_disputeKitIDsuint256[]The IDs of dispute kits which support should be added/removed.
_enableboolWhether add or remove the dispute kits from the court.

setStake

Sets the caller's stake in a court.

function setStake(uint96 _courtID, uint256 _stake) external;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court.
_stakeuint256The new stake.

setStakeBySortitionModule

function setStakeBySortitionModule(address _account, uint96 _courtID, uint256 _stake, uint256 _penalty) external;

createDispute

Creates a dispute. Must be called by the arbitrable contract.

function createDispute(uint256 _numberOfChoices, bytes memory _extraData)
    external
    payable
    override
    returns (uint256 disputeID);

Parameters

NameTypeDescription
_numberOfChoicesuint256Number of choices for the jurors to choose from.
_extraDatabytesAdditional info about the dispute. We use it to pass the ID of the dispute's court (first 32 bytes), the minimum number of jurors required (next 32 bytes) and the ID of the specific dispute kit (last 32 bytes).

Returns

NameTypeDescription
disputeIDuint256The ID of the created dispute.

passPeriod

Passes the period of a specified dispute.

function passPeriod(uint256 _disputeID) external;

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

draw

Draws jurors for the dispute. Can be called in parts.

function draw(uint256 _disputeID, uint256 _iterations) external;

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.
_iterationsuint256The number of iterations to run.

appeal

Appeals the ruling of a specified dispute. Note: Access restricted to the Dispute Kit for this disputeID.

function appeal(uint256 _disputeID, uint256 _numberOfChoices, bytes memory _extraData) external payable;

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.
_numberOfChoicesuint256Number of choices for the dispute. Can be required during court jump.
_extraDatabytesExtradata for the dispute. Can be required during court jump.

execute

Distribute tokens and ETH for the specific round of the dispute. Can be called in parts.

function execute(uint256 _disputeID, uint256 _round, uint256 _iterations) external;

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.
_rounduint256The appeal round.
_iterationsuint256The number of iterations to run.

_executePenalties

Distribute the tokens and ETH for the specific round of the dispute, penalties only.

function _executePenalties(ExecuteParams memory _params) internal returns (uint256);

Parameters

NameTypeDescription
_paramsExecuteParamsThe parameters for the execution, see ExecuteParams.

Returns

NameTypeDescription
<none>uint256penaltiesInRoundCache The updated penalties in round cache.

_executeRewards

Distribute the tokens and ETH for the specific round of the dispute, rewards only.

function _executeRewards(ExecuteParams memory _params) internal;

Parameters

NameTypeDescription
_paramsExecuteParamsThe parameters for the execution, see ExecuteParams.

executeRuling

Executes a specified dispute's ruling. UNTRUSTED.

function executeRuling(uint256 _disputeID) external;

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

arbitrationCost

Gets the cost of arbitration in a specified court.

function arbitrationCost(bytes memory _extraData) public view override returns (uint256 cost);

Parameters

NameTypeDescription
_extraDatabytesAdditional info about the dispute. We use it to pass the ID of the court to create the dispute in (first 32 bytes) and the minimum number of jurors required (next 32 bytes).

Returns

NameTypeDescription
costuint256The arbitration cost.

appealCost

Gets the cost of appealing a specified dispute.

function appealCost(uint256 _disputeID) public view returns (uint256 cost);

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

Returns

NameTypeDescription
costuint256The appeal cost.

appealPeriod

Gets the start and the end of a specified dispute's current appeal period.

function appealPeriod(uint256 _disputeID) public view returns (uint256 start, uint256 end);

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

Returns

NameTypeDescription
startuint256The start of the appeal period.
enduint256The end of the appeal period.

currentRuling

Gets the current ruling of a specified dispute.

function currentRuling(uint256 _disputeID) public view returns (uint256 ruling, bool tied, bool overridden);

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

Returns

NameTypeDescription
rulinguint256The current ruling.
tiedboolWhether it's a tie or not.
overriddenboolWhether the ruling was overridden by appeal funding or not.

getRoundInfo

function getRoundInfo(uint256 _disputeID, uint256 _round)
    external
    view
    returns (
        uint256 tokensAtStakePerJuror,
        uint256 totalFeesForJurors,
        uint256 repartitions,
        uint256 penalties,
        address[] memory drawnJurors,
        uint256 disputeKitID,
        uint256 sumRewardPaid,
        uint256 sumTokenRewardPaid
    );

getNumberOfRounds

function getNumberOfRounds(uint256 _disputeID) external view returns (uint256);

getJurorBalance

function getJurorBalance(address _juror, uint96 _courtID)
    external
    view
    returns (uint256 staked, uint256 locked, uint256 nbCourts);

isSupported

function isSupported(uint96 _courtID, uint256 _disputeKitID) external view returns (bool);

getDisputeKitChildren

Gets non-primitive properties of a specified dispute kit node.

function getDisputeKitChildren(uint256 _disputeKitID) external view returns (uint256[] memory);

Parameters

NameTypeDescription
_disputeKitIDuint256The ID of the dispute kit.

Returns

NameTypeDescription
<none>uint256[]children Indexes of children of this DK.

getTimesPerPeriod

Gets the timesPerPeriod array for a given court.

function getTimesPerPeriod(uint96 _courtID) external view returns (uint256[4] memory timesPerPeriod);

Parameters

NameTypeDescription
_courtIDuint96The ID of the court to get the times from.

Returns

NameTypeDescription
timesPerPerioduint256[4]The timesPerPeriod array for the given court.

getNumberOfVotes

Gets the number of votes permitted for the specified dispute in the latest round.

function getNumberOfVotes(uint256 _disputeID) external view returns (uint256);

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

isDisputeKitJumping

Returns true if the dispute kit will be switched to a parent DK.

function isDisputeKitJumping(uint256 _disputeID) external view returns (bool);

Parameters

NameTypeDescription
_disputeIDuint256The ID of the dispute.

Returns

NameTypeDescription
<none>boolWhether DK will be switched or not.

getDisputeKitNodesLength

function getDisputeKitNodesLength() external view returns (uint256);

getDisputeKit

Gets the dispute kit for a specific _disputeKitID.

function getDisputeKit(uint256 _disputeKitID) external view returns (IDisputeKit);

Parameters

NameTypeDescription
_disputeKitIDuint256The ID of the dispute kit.

getJurorCourtIDs

Gets the court identifiers where a specific _juror has staked.

function getJurorCourtIDs(address _juror) public view returns (uint96[] memory);

Parameters

NameTypeDescription
_juroraddressThe address of the juror.

_enableDisputeKit

Toggles the dispute kit support for a given court.

function _enableDisputeKit(uint96 _courtID, uint256 _disputeKitID, bool _enable) internal;

Parameters

NameTypeDescription
_courtIDuint96The ID of the court to toggle the support for.
_disputeKitIDuint256The ID of the dispute kit to toggle the support for.
_enableboolWhether to enable or disable the support.

_setStakeForAccount

Sets the specified juror's stake in a court. O(n + p * log_k(j)) where n is the number of courts the juror has staked in, p is the depth of the court tree, k is the minimum number of children per node of one of these courts' sortition sum tree, and j is the maximum number of jurors that ever staked in one of these courts simultaneously.

function _setStakeForAccount(address _account, uint96 _courtID, uint256 _stake, uint256 _penalty)
    internal
    returns (bool succeeded);

Parameters

NameTypeDescription
_accountaddressThe address of the juror.
_courtIDuint96The ID of the court.
_stakeuint256The new stake.
_penaltyuint256Penalized amount won't be transferred back to juror when the stake is lowered.

Returns

NameTypeDescription
succeededboolTrue if the call succeeded, false otherwise.

_extraDataToCourtIDMinJurorsDisputeKit

Gets a court ID, the minimum number of jurors and an ID of a dispute kit from a specified extra data bytes array. Note that if extradata contains an incorrect value then this value will be switched to default.

function _extraDataToCourtIDMinJurorsDisputeKit(bytes memory _extraData)
    internal
    view
    returns (uint96 courtID, uint256 minJurors, uint256 disputeKitID);

Parameters

NameTypeDescription
_extraDatabytesThe extra data bytes array. The first 32 bytes are the court ID, the next are the minimum number of jurors and the last are the dispute kit ID.

Returns

NameTypeDescription
courtIDuint96The court ID.
minJurorsuint256The minimum number of jurors required.
disputeKitIDuint256The ID of the dispute kit.

_safeTransfer

Calls transfer() without reverting.

function _safeTransfer(address _to, uint256 _value) internal returns (bool);

Parameters

NameTypeDescription
_toaddressRecepient address.
_valueuint256Amount transferred.

Returns

NameTypeDescription
<none>boolWhether transfer succeeded or not.

_safeTransferFrom

Calls transferFrom() without reverting.

function _safeTransferFrom(address _from, address _to, uint256 _value) internal returns (bool);

Parameters

NameTypeDescription
_fromaddressSender address.
_toaddressRecepient address.
_valueuint256Amount transferred.

Returns

NameTypeDescription
<none>boolWhether transfer succeeded or not.

Events

StakeSet

event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount);

StakeDelayed

event StakeDelayed(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _penalty);

NewPeriod

event NewPeriod(uint256 indexed _disputeID, Period _period);

AppealPossible

event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);

AppealDecision

event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);

Draw

event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _roundID, uint256 _voteID);

CourtCreated

event CourtCreated(
    uint256 indexed _courtID,
    uint96 indexed _parent,
    bool _hiddenVotes,
    uint256 _minStake,
    uint256 _alpha,
    uint256 _feeForJuror,
    uint256 _jurorsForCourtJump,
    uint256[4] _timesPerPeriod,
    uint256[] _supportedDisputeKits
);

CourtModified

event CourtModified(uint96 indexed _courtID, string _param);

DisputeKitCreated

event DisputeKitCreated(uint256 indexed _disputeKitID, IDisputeKit indexed _disputeKitAddress, uint256 indexed _parent);

DisputeKitEnabled

event DisputeKitEnabled(uint96 indexed _courtID, uint256 indexed _disputeKitID, bool indexed _enable);

CourtJump

event CourtJump(uint256 indexed _disputeID, uint256 indexed _roundID, uint96 indexed _fromCourtID, uint96 _toCourtID);

DisputeKitJump

event DisputeKitJump(
    uint256 indexed _disputeID, uint256 indexed _roundID, uint256 indexed _fromDisputeKitID, uint256 _toDisputeKitID
);

TokenAndETHShift

event TokenAndETHShift(
    address indexed _account,
    uint256 indexed _disputeID,
    uint256 indexed _roundID,
    uint256 _degreeOfCoherency,
    int256 _tokenAmount,
    int256 _ethAmount
);

LeftoverRewardSent

event LeftoverRewardSent(
    uint256 indexed _disputeID, uint256 indexed _roundID, uint256 _tokenAmount, uint256 _ethAmount
);

Structs

Court

struct Court {
    uint96 parent;
    bool hiddenVotes;
    uint256[] children;
    uint256 minStake;
    uint256 alpha;
    uint256 feeForJuror;
    uint256 jurorsForCourtJump;
    uint256[4] timesPerPeriod;
    mapping(uint256 => bool) supportedDisputeKits;
    bool disabled;
}

Dispute

struct Dispute {
    uint96 courtID;
    IArbitrable arbitrated;
    Period period;
    bool ruled;
    uint256 lastPeriodChange;
    Round[] rounds;
}

Round

struct Round {
    uint256 disputeKitID;
    uint256 tokensAtStakePerJuror;
    uint256 totalFeesForJurors;
    uint256 nbVotes;
    uint256 repartitions;
    uint256 penalties;
    address[] drawnJurors;
    uint256 sumRewardPaid;
    uint256 sumTokenRewardPaid;
}

Juror

struct Juror {
    uint96[] courtIDs;
    mapping(uint96 => uint256) stakedTokens;
    mapping(uint96 => uint256) lockedTokens;
}

DisputeKitNode

struct DisputeKitNode {
    uint256 parent;
    uint256[] children;
    IDisputeKit disputeKit;
    uint256 depthLevel;
    bool disabled;
}

ExecuteParams

struct ExecuteParams {
    uint256 disputeID;
    uint256 round;
    uint256 coherentCount;
    uint256 numberOfVotesInRound;
    uint256 penaltiesInRound;
    uint256 repartition;
}

Enums

Period

enum Period {
    evidence,
    commit,
    vote,
    appeal,
    execution
}