Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
95b8ada
feat: dispute kit in progress
jaybuidl Dec 13, 2021
f30d6bf
Merge branch 'feat/core-plurality-disputekit' into feat/core-pluralit…
jaybuidl Dec 17, 2021
f339e2b
feat(DisputeKitPlurality): split the responsibility of drawing jurors…
jaybuidl Dec 17, 2021
6a2490e
feat(DisputeKitPlurality): dispute creation
jaybuidl Dec 18, 2021
f32da6f
feat(KlerosCore): add first version
unknownunknown1 Dec 27, 2021
cd4a3df
test(DisputeKitPlurality): added basic test, work in progress
jaybuidl Dec 28, 2021
df9b414
Merge branch 'feat/core-plurality-disputekit-jaybuidl' of github.com:…
jaybuidl Dec 28, 2021
ba60d8f
chore: prettify and removal of CHANGELOG.md (cause of too many confli…
jaybuidl Dec 28, 2021
21f2f10
Merge remote-tracking branch 'origin/master' into feat/core-plurality…
jaybuidl Dec 28, 2021
319934a
chore: added hardhat-docgen
jaybuidl Dec 29, 2021
764a83e
feat(DisputeKit): changeCore() for the governor
jaybuidl Dec 29, 2021
373cc24
refactor(DisputeKit): abstraction of the dispute kit
jaybuidl Dec 29, 2021
da37929
refactor(KlerosCore): extracted a Round struct from the Dispute struct
jaybuidl Dec 30, 2021
7b39ade
feat(DisputeKitSybilResistant): naive sybil-resistant juror drawing
jaybuidl Dec 30, 2021
f09124a
chore(Code Climate): disable TS quote check
jaybuidl Jan 17, 2022
3317ffc
chore(contracts): github workflow for contracts testing (#10)
jaybuidl Jan 6, 2022
25fbf41
docs: pinned the Contracts Testing badge to master
jaybuidl Jan 6, 2022
cbde56a
Merge branch 'master' into feat/core-plurality-disputekit-jaybuidl
jaybuidl Jan 20, 2022
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(DisputeKitPlurality): split the responsibility of drawing jurors…
… between Core and Dispute Kit
  • Loading branch information
jaybuidl committed Dec 17, 2021
commit f339e2b54980fcabb01148fba7e185c9187cea4b
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.9+commit.e5eed63a",
"solidity.compileUsingRemoteVersion": "v0.8.10+commit.fc410830",
"mochaExplorer.files": "contracts/test/**/*.{j,t}s"
}
25 changes: 22 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
## 0.1.0 (2021-12-17)

- refactor: add arbitrator data index getter ([47a1623](https://github.com/kleros/kleros-v2/commit/47a1623))
- refactor: add evidence contracts ([09a34f3](https://github.com/kleros/kleros-v2/commit/09a34f3))
- refactor: add interfaces + capped math ([e25b21f](https://github.com/kleros/kleros-v2/commit/e25b21f))
- refactor: add simple evidence home contract ([1b82f62](https://github.com/kleros/kleros-v2/commit/1b82f62))
- refactor: fix contract name ([6eb744a](https://github.com/kleros/kleros-v2/commit/6eb744a))
- refactor: remove foreign evidence interface ([ff8c50c](https://github.com/kleros/kleros-v2/commit/ff8c50c))
- refactor(bridge): use ArbRetryableTx#getSubmissionPrice ([61bc2f3](https://github.com/kleros/kleros-v2/commit/61bc2f3))
- refactor(sdk): rename ([3241d10](https://github.com/kleros/kleros-v2/commit/3241d10))
- feat: add arbitrum L1 bridge and dependencies ([b412772](https://github.com/kleros/kleros-v2/commit/b412772))
- feat: add arbitrum L2 bridge ([457b060](https://github.com/kleros/kleros-v2/commit/457b060))
- feat: dispute kit in progress ([95b8ada](https://github.com/kleros/kleros-v2/commit/95b8ada))
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))
- feat(Arbitration): standard update ([ed930de](https://github.com/kleros/kleros-v2/commit/ed930de))
- chore: .gitignore ([0ed4d74](https://github.com/kleros/kleros-v2/commit/0ed4d74))
- chore: .gitignore and removal of unnecessary yarn cache as we are using "zero installs" ([a6cfdd0](https://github.com/kleros/kleros-v2/commit/a6cfdd0))
- chore: added GitHub code scanning ([4a70475](https://github.com/kleros/kleros-v2/commit/4a70475))
- chore: added the hardhat config for layer 2 networks, added hardhat-deploy and mocha ([a12ea0e](https://github.com/kleros/kleros-v2/commit/a12ea0e))
- chore: gitignore typechain ([b50f777](https://github.com/kleros/kleros-v2/commit/b50f777))
- chore(typechain): clean generated files ([775ddd0](https://github.com/kleros/kleros-v2/commit/775ddd0))
- test: add evidence contract tests ([590d800](https://github.com/kleros/kleros-v2/commit/590d800))
- test: added a test for IncrementalNG ([65a996b](https://github.com/kleros/kleros-v2/commit/65a996b))
- test(EvidenceModule): add test file ([9f00f98](https://github.com/kleros/kleros-v2/commit/9f00f98))
- fix: according to evidence standard + comments ([5c95828](https://github.com/kleros/kleros-v2/commit/5c95828))
- fix: unused code ([26b5dc3](https://github.com/kleros/kleros-v2/commit/26b5dc3))
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
- fix(EvidenceModule): typos + castings + imports ([789c022](https://github.com/kleros/kleros-v2/commit/789c022))
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
- fix(IArbitrator): change name to arbitration cost ([0ba4f29](https://github.com/kleros/kleros-v2/commit/0ba4f29))
- fix(IArbitrator): interface simplification ([e81fb8b](https://github.com/kleros/kleros-v2/commit/e81fb8b))
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
- chore: added GitHub code scanning ([4a70475](https://github.com/kleros/kleros-v2/commit/4a70475))
- chore: added the hardhat config for layer 2 networks, added hardhat-deploy and mocha ([a12ea0e](https://github.com/kleros/kleros-v2/commit/a12ea0e))
- test: added a test for IncrementalNG ([65a996b](https://github.com/kleros/kleros-v2/commit/65a996b))
- docs: initial commit ([23356e7](https://github.com/kleros/kleros-v2/commit/23356e7))
- docs: license file added ([cb62d2c](https://github.com/kleros/kleros-v2/commit/cb62d2c))
- docs: readme and spdx headers ([8a5b397](https://github.com/kleros/kleros-v2/commit/8a5b397))
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/arbitration/CentralizedArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contract CentralizedArbitrator is IArbitrator {
uint256 _arbitrationFee,
uint256 _appealDuration,
uint256 _appealFee
) public {
) {
arbitrationFee = _arbitrationFee;
appealDuration = _appealDuration;
appealFee = _appealFee;
Expand Down
98 changes: 90 additions & 8 deletions contracts/src/arbitration/DisputeKitPlurality.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8;

import "./IArbitrator.sol";
import "../rng/RNG.sol";
import "../data-structures/SortitionSumTreeFactory.sol";
import "./mock/MockKlerosCore.sol";

contract DisputeKitPlurality {
// Core --> IN
Expand All @@ -28,14 +28,12 @@ contract DisputeKitPlurality {
// appeal crowdfunding
// redistribution when ruling is final

IArbitrator public immutable core;
RNG public immutable rng;

using SortitionSumTreeFactory for SortitionSumTreeFactory.SortitionSumTrees; // Use library functions for sortition sum trees.
// TODO: extract the necessary interfaces
MockKlerosCore public immutable core;

// SortitionSumTreeFactory.SortitionSumTrees internal sortitionSumTrees; // The sortition sum trees.
RNG public immutable rng;

constructor(IArbitrator _core, RNG _rng) {
constructor(MockKlerosCore _core, RNG _rng) {
core = _core;
rng = _rng;
}
Expand Down Expand Up @@ -70,5 +68,89 @@ contract DisputeKitPlurality {
// ALPHA_DIVISOR = 10000
}

function drawJurors(SortitionSumTreeFactory.SortitionSumTrees calldata tree) public {}
/**
* @dev Draws jurors for a dispute. Can be called in parts.
* @param _disputeID The ID of the dispute.
* @param _iterations The number of iterations to run.
*/
function drawJurors(uint256 _disputeID, uint256 _iterations) public {
uint96 subcourtID = core.getDispute(_disputeID).subcourtID;
bytes32 key = bytes32(bytes12(subcourtID)); // due to new conversion restrictions in v0.8
(
uint256 k, /* stack */
,
uint256[] memory nodes
) = core.getSortitionSumTree(key);

// TODO: run this only when starting the drawing period
uint256 randomNumber = rng.getUncorrelatedRN(block.number);

// TODO: batching with boundary checks
for (uint256 i = 0; i < _iterations; i++) {
uint256 treeIndex = draw(uint256(keccak256(abi.encodePacked(randomNumber, _disputeID, i))), k, nodes);
bytes32 id = core.getSortitionSumTreeID(key, treeIndex);
(
address drawnAddress, /* subcourtID */

) = stakePathIDToAccountAndSubcourtID(id);

// TODO: Save the vote.
// dispute.votes[dispute.votes.length - 1][i].account = drawnAddress;
// jurors[drawnAddress].lockedTokens += dispute.tokensAtStakePerJuror[dispute.tokensAtStakePerJuror.length - 1];
// emit Draw(drawnAddress, _disputeID, dispute.votes.length - 1, i);

// TODO: Stop if dispute is fully drawn.
// if (i == dispute.votes[dispute.votes.length - 1].length - 1) break;
}
}

function draw(
uint256 _drawnNumber,
uint256 _k,
uint256[] memory _nodes
) private pure returns (uint256 treeIndex) {
uint256 currentDrawnNumber = _drawnNumber % _nodes[0];
while ((_k * treeIndex) + 1 < _nodes.length) {
// While it still has children.
for (uint256 i = 1; i <= _k; i++) {
// Loop over children.
uint256 nodeIndex = (_k * treeIndex) + i;
uint256 nodeValue = _nodes[nodeIndex];

if (currentDrawnNumber >= nodeValue)
currentDrawnNumber -= nodeValue; // Go to the next child.
else {
// Pick this child.
treeIndex = nodeIndex;
break;
}
}
}
}

/**
* @dev Unpacks a stake path ID into an account and a subcourt ID.
* @param _stakePathID The stake path ID to unpack.
* @return account The account.
* @return subcourtID The subcourt ID.
*/
function stakePathIDToAccountAndSubcourtID(bytes32 _stakePathID)
internal
pure
returns (address account, uint96 subcourtID)
{
assembly {
// solium-disable-line security/no-inline-assembly
let ptr := mload(0x40)
for {
let i := 0x00
} lt(i, 0x14) {
i := add(i, 0x01)
} {
mstore8(add(add(ptr, 0x0c), i), byte(i, _stakePathID))
}
account := mload(ptr)
subcourtID := _stakePathID
}
}
}
25 changes: 0 additions & 25 deletions contracts/src/arbitration/Mock/MockKlerosCore.sol

This file was deleted.

65 changes: 65 additions & 0 deletions contracts/src/arbitration/mock/MockKlerosCore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

import {SortitionSumTreeFactory} from "../../data-structures/SortitionSumTreeFactory.sol";
// import "../DisputeKitPlurality.sol";
import "../IArbitrable.sol";

contract MockKlerosCore {
using SortitionSumTreeFactory for SortitionSumTreeFactory.SortitionSumTrees; // Use library functions for sortition sum trees.
SortitionSumTreeFactory.SortitionSumTrees internal sortitionSumTrees; // The sortition sum trees.

struct Dispute {
// Note that appeal `0` is equivalent to the first round of the dispute.
uint96 subcourtID; // The ID of the subcourt the dispute is in.
IArbitrable arbitrated; // The arbitrated arbitrable contract.
// The number of choices jurors have when voting. This does not include choice `0` which is reserved for "refuse to arbitrate"/"no ruling".
uint256 numberOfChoices;
//Period period; // The current period of the dispute.
uint256 lastPeriodChange; // The last time the period was changed.
// The votes in the form `votes[appeal][voteID]`. On each round, a new list is pushed and packed with as many empty votes as there are draws. We use `dispute.votes.length` to get the number of appeals plus 1 for the first round.
// Vote[][] votes;
//VoteCounter[] voteCounters; // The vote counters in the form `voteCounters[appeal]`.
uint256[] tokensAtStakePerJuror; // The amount of tokens at stake for each juror in the form `tokensAtStakePerJuror[appeal]`.
uint256[] totalFeesForJurors; // The total juror fees paid in the form `totalFeesForJurors[appeal]`.
uint256 drawsInRound; // A counter of draws made in the current round.
uint256 commitsInRound; // A counter of commits made in the current round.
uint256[] votesInEachRound; // A counter of votes made in each round in the form `votesInEachRound[appeal]`.
// A counter of vote reward repartitions made in each round in the form `repartitionsInEachRound[appeal]`.
uint256[] repartitionsInEachRound;
uint256[] penaltiesInEachRound; // The amount of tokens collected from penalties in each round in the form `penaltiesInEachRound[appeal]`.
bool ruled; // True if the ruling has been executed, false otherwise.
}

Dispute[] public disputes;

constructor() {
sortitionSumTrees.createTree(bytes32(0), 3);
}

// DisputeKitPlurality disputeKit;

function getSortitionSumTree(bytes32 _key)
public
view
returns (
uint256 K,
uint256[] memory stack,
uint256[] memory nodes
)
{
SortitionSumTreeFactory.SortitionSumTree storage tree = sortitionSumTrees.sortitionSumTrees[_key];
K = tree.K;
stack = tree.stack;
nodes = tree.nodes;
}

function getSortitionSumTreeID(bytes32 _key, uint256 _nodeIndex) public view returns (bytes32 ID) {
ID = sortitionSumTrees.sortitionSumTrees[_key].nodeIndexesToIDs[_nodeIndex];
}

function getDispute(uint256 _id) public view returns (Dispute memory) {
return disputes[_id];
}
}