Skip to content

Commit 95b8ada

Browse files
committed
feat: dispute kit in progress
1 parent 348cd9b commit 95b8ada

File tree

8 files changed

+152
-3
lines changed

8 files changed

+152
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## 0.1.0 (2021-11-30)
1+
## 0.1.0 (2021-12-13)
22

33
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
44
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
5+
- fix(IArbitrator): change name to arbitration cost ([0ba4f29](https://github.com/kleros/kleros-v2/commit/0ba4f29))
56
- fix(IArbitrator): interface simplification ([e81fb8b](https://github.com/kleros/kleros-v2/commit/e81fb8b))
67
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
78
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))

contracts/src/arbitration/ArbitrableExample.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "./IArbitrable.sol";
66

77
/**
88
* @title ArbitrableExample
9-
* An example of the arbitrable contract which connects to the arbitator that implements IArbitrator interface.
9+
* An example of an arbitrable contract which connects to the arbitator that implements the updated interface.
1010
*/
1111
contract ArbitrableExample is IArbitrable {
1212
struct DisputeStruct {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8;
4+
5+
import "./IArbitrator.sol";
6+
import "../rng/RNG.sol";
7+
import "../data-structures/SortitionSumTreeFactory.sol";
8+
9+
contract DisputeKitPlurality {
10+
// Core --> IN
11+
// createDispute
12+
13+
// OUT -> Core
14+
// report drawn jurors
15+
// report ruling
16+
17+
// Jurors -> IN
18+
// vote
19+
20+
// Anyone -> IN
21+
// requestAppeal
22+
23+
// INTERNAL
24+
// draw jurors <-> RNG
25+
// receive evidence
26+
// aggregate votes
27+
// incentive (who earns how much PNK and ETH)
28+
// appeal crowdfunding
29+
// redistribution when ruling is final
30+
31+
IArbitrator public immutable core;
32+
RNG public immutable rng;
33+
34+
using SortitionSumTreeFactory for SortitionSumTreeFactory.SortitionSumTrees; // Use library functions for sortition sum trees.
35+
36+
// SortitionSumTreeFactory.SortitionSumTrees internal sortitionSumTrees; // The sortition sum trees.
37+
38+
constructor(IArbitrator _core, RNG _rng) {
39+
core = _core;
40+
rng = _rng;
41+
}
42+
43+
/**
44+
* Note: disputeID is maintained by Kleros Core, not the dispute kit
45+
* Note: the dispute kit does not receive any payment, Kleros Core does
46+
* Note: Permissioned
47+
*/
48+
function createDispute(
49+
uint256 _disputeID,
50+
uint256 _minJuror,
51+
uint256 _choices,
52+
bytes calldata _extraData
53+
) external {
54+
require(msg.sender == address(core), "Not allowed: sender is not core");
55+
56+
// -- dispute specific --
57+
//
58+
59+
// -- subcourt specific --
60+
// uint minStake: min tokens required to stake on this subcourt
61+
// bool hiddenVotes:
62+
// uint alpha: bps of tokens lost when incoherent
63+
// uint feeForJuror: paid per juror
64+
// uint jurorsForCourtJump: evaluated by the appeal logic
65+
66+
// PROBLEM: have an interface that works for and "1 human 1 vote"
67+
68+
// votes = msg.value / subcourt.feeForJuror
69+
// tokenAtStakePerJuror = (subcourt.minStake * subcourt.alpha) / ALPHA_DIVISOR
70+
// ALPHA_DIVISOR = 10000
71+
}
72+
73+
function drawJurors(SortitionSumTreeFactory.SortitionSumTrees calldata tree) public {}
74+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8;
4+
5+
import {SortitionSumTreeFactory} from "../../data-structures/SortitionSumTreeFactory.sol";
6+
import {DisputeKitPlurality} from "../DisputeKitPlurality.sol";
7+
8+
contract MockKlerosCore {
9+
using SortitionSumTreeFactory for SortitionSumTreeFactory.SortitionSumTrees; // Use library functions for sortition sum trees.
10+
SortitionSumTreeFactory.SortitionSumTrees internal sortitionSumTrees; // The sortition sum trees.
11+
12+
DisputeKitPlurality disputeKit;
13+
14+
constructor() {
15+
sortitionSumTrees.createTree(bytes32(0), 3);
16+
}
17+
18+
// function getSortitionSumTrees() view public returns(SortitionSumTreeFactory.SortitionSumTrees calldata) {
19+
// return sortitionSumTrees;
20+
// }
21+
22+
function drawJurors(uint256 _disputeID, uint256 _iterations) public {
23+
disputeKit.draw(sortitionSumTrees);
24+
}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8;
4+
5+
library SortitionSumTreeFactory {
6+
/* Structs */
7+
8+
struct SortitionSumTree {
9+
uint256 K; // The maximum number of childs per node.
10+
// We use this to keep track of vacant positions in the tree after removing a leaf. This is for keeping the tree as balanced as possible without spending gas on moving nodes around.
11+
uint256[] stack;
12+
uint256[] nodes;
13+
// Two-way mapping of IDs to node indexes. Note that node index 0 is reserved for the root node, and means the ID does not have a node.
14+
mapping(bytes32 => uint256) IDsToNodeIndexes;
15+
mapping(uint256 => bytes32) nodeIndexesToIDs;
16+
}
17+
18+
/* Storage */
19+
20+
struct SortitionSumTrees {
21+
mapping(bytes32 => SortitionSumTree) sortitionSumTrees;
22+
}
23+
24+
function createTree(
25+
SortitionSumTrees storage self,
26+
bytes32 _key,
27+
uint256 _K
28+
) public {
29+
SortitionSumTree storage tree = self.sortitionSumTrees[_key];
30+
require(tree.K == 0, "Tree already exists.");
31+
require(_K > 1, "K must be greater than one.");
32+
tree.K = _K;
33+
// tree.stack.length = 0;
34+
// tree.nodes.length = 0;
35+
tree.nodes.push(0);
36+
}
37+
}

contracts/typechain/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
/* Autogenerated file. Do not edit manually. */
22
/* tslint:disable */
33
/* eslint-disable */
4+
export type { ArbitrableExample } from "./ArbitrableExample";
5+
export type { CentralizedArbitrator } from "./CentralizedArbitrator";
6+
export type { DiputeKitPlurality } from "./DiputeKitPlurality";
7+
export type { IArbitrable } from "./IArbitrable";
8+
export type { IArbitrator } from "./IArbitrator";
9+
export type { MockKlerosCore } from "./MockKlerosCore";
410
export type { ConstantNG } from "./ConstantNG";
511
export type { IncrementalNG } from "./IncrementalNG";
612
export type { RNG } from "./RNG";
713

14+
export { ArbitrableExample__factory } from "./factories/ArbitrableExample__factory";
15+
export { CentralizedArbitrator__factory } from "./factories/CentralizedArbitrator__factory";
16+
export { DiputeKitPlurality__factory } from "./factories/DiputeKitPlurality__factory";
17+
export { IArbitrable__factory } from "./factories/IArbitrable__factory";
18+
export { IArbitrator__factory } from "./factories/IArbitrator__factory";
19+
export { MockKlerosCore__factory } from "./factories/MockKlerosCore__factory";
820
export { ConstantNG__factory } from "./factories/ConstantNG__factory";
921
export { IncrementalNG__factory } from "./factories/IncrementalNG__factory";
1022
export { RNG__factory } from "./factories/RNG__factory";

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14414,7 +14414,7 @@ __metadata:
1441414414

1441514415
"typescript@patch:typescript@^4.4.3#~builtin<compat/typescript>, typescript@patch:typescript@^4.4.4#~builtin<compat/typescript>":
1441614416
version: 4.4.4
14417-
resolution: "typescript@patch:typescript@npm%3A4.4.4#~builtin<compat/typescript>::version=4.4.4&hash=ddd1e8"
14417+
resolution: "typescript@patch:typescript@npm%3A4.4.4#~builtin<compat/typescript>::version=4.4.4&hash=493e53"
1441814418
bin:
1441914419
tsc: bin/tsc
1442014420
tsserver: bin/tsserver

0 commit comments

Comments
 (0)