Skip to content

Commit de1c7bd

Browse files
unknownunknown1jaybuidl
authored andcommitted
fix(KC): remove null dk
1 parent 3f7de4f commit de1c7bd

File tree

10 files changed

+32
-65
lines changed

10 files changed

+32
-65
lines changed

contracts/scripts/simulations/tasks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ task("simulate:create-court", "callable by Governor only. Create a new Court")
8585
const hiddenVotes = false as boolean;
8686
const timesPerPeriod = [300, 300, 300, 300] as [BigNumberish, BigNumberish, BigNumberish, BigNumberish];
8787
const sortitionSumTreeK = ethers.toBeHex(3);
88-
const supportedDisputeKits = [1] as BigNumberish[]; // IDs of supported dispute kits
88+
const supportedDisputeKits = [0] as BigNumberish[]; // IDs of supported dispute kits
8989
let courtID;
9090
try {
9191
const tx = await (

contracts/src/arbitration/KlerosCoreBase.sol

+4-7
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
207207
jurorProsecutionModule = _jurorProsecutionModule;
208208
sortitionModule = _sortitionModuleAddress;
209209

210-
// NULL_DISPUTE_KIT: an empty element at index 0 to indicate when a dispute kit is not supported.
211-
disputeKits.push();
212-
213210
// DISPUTE_KIT_CLASSIC
214211
disputeKits.push(_disputeKit);
215212

@@ -346,7 +343,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
346343
Court storage court = courts.push();
347344

348345
for (uint256 i = 0; i < _supportedDisputeKits.length; i++) {
349-
if (_supportedDisputeKits[i] == 0 || _supportedDisputeKits[i] >= disputeKits.length) {
346+
if (_supportedDisputeKits[i] >= disputeKits.length) {
350347
revert WrongDisputeKitIndex();
351348
}
352349
_enableDisputeKit(uint96(courtID), _supportedDisputeKits[i], true);
@@ -422,7 +419,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
422419
function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor {
423420
for (uint256 i = 0; i < _disputeKitIDs.length; i++) {
424421
if (_enable) {
425-
if (_disputeKitIDs[i] == 0 || _disputeKitIDs[i] >= disputeKits.length) {
422+
if (_disputeKitIDs[i] >= disputeKits.length) {
426423
revert WrongDisputeKitIndex();
427424
}
428425
_enableDisputeKit(_courtID, _disputeKitIDs[i], true);
@@ -1126,8 +1123,8 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
11261123
if (minJurors == 0) {
11271124
minJurors = DEFAULT_NB_OF_JURORS;
11281125
}
1129-
if (disputeKitID == NULL_DISPUTE_KIT || disputeKitID >= disputeKits.length) {
1130-
disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used.
1126+
if (disputeKitID >= disputeKits.length) {
1127+
disputeKitID = DISPUTE_KIT_CLASSIC;
11311128
}
11321129
} else {
11331130
courtID = GENERAL_COURT;

contracts/src/arbitration/devtools/KlerosCoreRuler.sol

-3
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,6 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable {
657657
if (minJurors == 0) {
658658
minJurors = DEFAULT_NB_OF_JURORS;
659659
}
660-
if (disputeKitID == NULL_DISPUTE_KIT) {
661-
disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used.
662-
}
663660
} else {
664661
courtID = GENERAL_COURT;
665662
minJurors = DEFAULT_NB_OF_JURORS;

contracts/src/arbitration/university/KlerosCoreUniversity.sol

+4-7
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
214214
jurorProsecutionModule = _jurorProsecutionModule;
215215
sortitionModule = _sortitionModuleAddress;
216216

217-
// NULL_DISPUTE_KIT: an empty element at index 0 to indicate when a dispute kit is not supported.
218-
disputeKits.push();
219-
220217
// DISPUTE_KIT_CLASSIC
221218
disputeKits.push(_disputeKit);
222219

@@ -341,7 +338,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
341338
Court storage court = courts.push();
342339

343340
for (uint256 i = 0; i < _supportedDisputeKits.length; i++) {
344-
if (_supportedDisputeKits[i] == 0 || _supportedDisputeKits[i] >= disputeKits.length) {
341+
if (_supportedDisputeKits[i] >= disputeKits.length) {
345342
revert WrongDisputeKitIndex();
346343
}
347344
court.supportedDisputeKits[_supportedDisputeKits[i]] = true;
@@ -415,7 +412,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
415412
function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor {
416413
for (uint256 i = 0; i < _disputeKitIDs.length; i++) {
417414
if (_enable) {
418-
if (_disputeKitIDs[i] == 0 || _disputeKitIDs[i] >= disputeKits.length) {
415+
if (_disputeKitIDs[i] >= disputeKits.length) {
419416
revert WrongDisputeKitIndex();
420417
}
421418
_enableDisputeKit(_courtID, _disputeKitIDs[i], true);
@@ -1118,8 +1115,8 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
11181115
if (minJurors == 0) {
11191116
minJurors = DEFAULT_NB_OF_JURORS;
11201117
}
1121-
if (disputeKitID == NULL_DISPUTE_KIT || disputeKitID >= disputeKits.length) {
1122-
disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used.
1118+
if (disputeKitID >= disputeKits.length) {
1119+
disputeKitID = DISPUTE_KIT_CLASSIC;
11231120
}
11241121
} else {
11251122
courtID = GENERAL_COURT;

contracts/src/libraries/Constants.sol

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ uint96 constant FORKING_COURT = 0; // Index of the forking court.
99
uint96 constant GENERAL_COURT = 1; // Index of the default (general) court.
1010

1111
// Dispute Kits
12-
uint256 constant NULL_DISPUTE_KIT = 0; // Null pattern to indicate a top-level DK which has no parent. DEPRECATED, as its main purpose was to accommodate forest structure which is not used now.
13-
uint256 constant DISPUTE_KIT_CLASSIC = 1; // Index of the default DK. 0 index is skipped.
12+
uint256 constant DISPUTE_KIT_CLASSIC = 0; // Index of the default DK.
1413

1514
// Sortition Module
1615
uint256 constant MAX_STAKE_PATHS = 4; // The maximum number of stake paths a juror can have.

contracts/test/arbitration/draw.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("Draw Benchmark", async () => {
9797
256,
9898
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
9999
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K)
100-
[1]
100+
[0]
101101
)
102102
.then((tx) => tx.wait());
103103
});

contracts/test/arbitration/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("DisputeKitClassic", async () => {
1616
it("Kleros Core initialization", async () => {
1717
const events = await core.queryFilter(core.filters.DisputeKitCreated());
1818
expect(events.length).to.equal(1);
19-
expect(events[0].args._disputeKitID).to.equal(1);
19+
expect(events[0].args._disputeKitID).to.equal(0);
2020
expect(events[0].args._disputeKitAddress).to.equal(disputeKit.target);
2121

2222
// Reminder: the Forking court will be added which will break these expectations.
@@ -30,12 +30,12 @@ describe("DisputeKitClassic", async () => {
3030
expect(events2[0].args._feeForJuror).to.equal(ethers.parseUnits("0.1", 18));
3131
expect(events2[0].args._jurorsForCourtJump).to.equal(256);
3232
expect(events2[0].args._timesPerPeriod).to.deep.equal([0, 0, 0, 10]);
33-
expect(events2[0].args._supportedDisputeKits).to.deep.equal([1]);
33+
expect(events2[0].args._supportedDisputeKits).to.deep.equal([0]);
3434

3535
const events3 = await core.queryFilter(core.filters.DisputeKitEnabled());
3636
expect(events3.length).to.equal(1);
3737
expect(events3[0].args._courtID).to.equal(1);
38-
expect(events3[0].args._disputeKitID).to.equal(1);
38+
expect(events3[0].args._disputeKitID).to.equal(0);
3939
expect(events3[0].args._enable).to.equal(true);
4040
});
4141

contracts/test/arbitration/staking-neo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ describe("Staking", async () => {
399399
describe("When outside the Staking phase", async () => {
400400
const createSubcourtStakeAndCreateDispute = async () => {
401401
expect(await sortition.phase()).to.be.equal(0); // Staking
402-
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [1]); // Parent - general court, Classic dispute kit
402+
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [0]); // Parent - general court, Classic dispute kit
403403

404404
await pnk.approve(core.target, PNK(4000));
405405
await core.setStake(1, PNK(2000));
@@ -734,7 +734,7 @@ describe("Staking", async () => {
734734
});
735735

736736
it("Should unstake from all courts", async () => {
737-
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [1]); // Parent - general court, Classic dispute kit
737+
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [0]); // Parent - general court, Classic dispute kit
738738

739739
await pnk.approve(core.target, PNK(4000));
740740
await core.setStake(1, PNK(2000));

contracts/test/arbitration/staking.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe("Staking", async () => {
4040
const reachDrawingPhase = async () => {
4141
expect(await sortition.phase()).to.be.equal(0); // Staking
4242
const arbitrationCost = ETH(0.1) * 3n;
43-
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [1]); // Parent - general court, Classic dispute kit
43+
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [0]); // Parent - general court, Classic dispute kit
4444

4545
await pnk.approve(core.target, PNK(4000));
4646
await core.setStake(1, PNK(2000));
@@ -386,7 +386,7 @@ describe("Staking", async () => {
386386

387387
it("Should unstake from all courts", async () => {
388388
const arbitrationCost = ETH(0.1) * 3n;
389-
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [1]); // Parent - general court, Classic dispute kit
389+
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [0]); // Parent - general court, Classic dispute kit
390390

391391
await pnk.approve(core.target, PNK(4000));
392392
await core.setStake(1, PNK(2000));

contracts/test/foundry/KlerosCore.t.sol

+14-37
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {TestERC20} from "../../src/token/TestERC20.sol";
1717
import {ArbitrableExample, IArbitrableV2} from "../../src/arbitration/arbitrables/ArbitrableExample.sol";
1818
import {DisputeTemplateRegistry} from "../../src/arbitration/DisputeTemplateRegistry.sol";
1919
import "../../src/libraries/Constants.sol";
20-
import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/snapshot-proxy/KlerosCoreSnapshotProxy.sol";
20+
import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/arbitration/view/KlerosCoreSnapshotProxy.sol";
2121

2222
contract KlerosCoreTest is Test {
2323
event Initialized(uint64 version);
@@ -156,7 +156,7 @@ contract KlerosCoreTest is Test {
156156
assertEq(address(core.pinakion()), address(pinakion), "Wrong pinakion address");
157157
assertEq(core.jurorProsecutionModule(), jurorProsecutionModule, "Wrong jurorProsecutionModule address");
158158
assertEq(address(core.sortitionModule()), address(sortitionModule), "Wrong sortitionModule address");
159-
assertEq(core.getDisputeKitsLength(), 2, "Wrong DK array length");
159+
assertEq(core.getDisputeKitsLength(), 1, "Wrong DK array length");
160160
(
161161
uint96 courtParent,
162162
bool courtHiddenVotes,
@@ -197,19 +197,16 @@ contract KlerosCoreTest is Test {
197197
assertEq(courtTimesPerPeriod[i], timesPerPeriod[i], "Wrong times per period");
198198
}
199199

200-
assertEq(address(core.disputeKits(NULL_DISPUTE_KIT)), address(0), "Wrong address NULL_DISPUTE_KIT");
201200
assertEq(
202201
address(core.disputeKits(DISPUTE_KIT_CLASSIC)),
203202
address(disputeKit),
204203
"Wrong address DISPUTE_KIT_CLASSIC"
205204
);
206-
assertEq(core.isSupported(FORKING_COURT, NULL_DISPUTE_KIT), false, "Forking court null dk should be false");
207205
assertEq(
208206
core.isSupported(FORKING_COURT, DISPUTE_KIT_CLASSIC),
209207
false,
210208
"Forking court classic dk should be false"
211209
);
212-
assertEq(core.isSupported(GENERAL_COURT, NULL_DISPUTE_KIT), false, "General court null dk should be false");
213210
assertEq(core.isSupported(GENERAL_COURT, DISPUTE_KIT_CLASSIC), true, "General court classic dk should be true");
214211
assertEq(core.paused(), false, "Wrong paused value");
215212

@@ -438,18 +435,18 @@ contract KlerosCoreTest is Test {
438435
core.addNewDisputeKit(newDK);
439436
vm.prank(governor);
440437
vm.expectEmit(true, true, true, true);
441-
emit KlerosCoreBase.DisputeKitCreated(2, newDK);
438+
emit KlerosCoreBase.DisputeKitCreated(1, newDK);
442439
core.addNewDisputeKit(newDK);
443-
assertEq(address(core.disputeKits(2)), address(newDK), "Wrong address of new DK");
444-
assertEq(core.getDisputeKitsLength(), 3, "Wrong DK array length");
440+
assertEq(address(core.disputeKits(1)), address(newDK), "Wrong address of new DK");
441+
assertEq(core.getDisputeKitsLength(), 2, "Wrong DK array length");
445442
}
446443

447444
function test_createCourt() public {
448445
vm.expectRevert(KlerosCoreBase.GovernorOnly.selector);
449446
vm.prank(other);
450447
uint256[] memory supportedDK = new uint256[](2);
451448
supportedDK[0] = DISPUTE_KIT_CLASSIC;
452-
supportedDK[1] = 2; // New DK is added below.
449+
supportedDK[1] = 1; // New DK is added below.
453450
core.createCourt(
454451
GENERAL_COURT,
455452
true, // Hidden votes
@@ -506,21 +503,6 @@ contract KlerosCoreTest is Test {
506503
);
507504

508505
uint256[] memory badSupportedDK = new uint256[](2);
509-
badSupportedDK[0] = NULL_DISPUTE_KIT; // Include NULL_DK to check that it reverts
510-
badSupportedDK[1] = DISPUTE_KIT_CLASSIC;
511-
vm.expectRevert(KlerosCoreBase.WrongDisputeKitIndex.selector);
512-
vm.prank(governor);
513-
core.createCourt(
514-
GENERAL_COURT,
515-
true, // Hidden votes
516-
2000, // min stake
517-
10000, // alpha
518-
0.03 ether, // fee for juror
519-
50, // jurors for jump
520-
[uint256(10), uint256(20), uint256(30), uint256(40)], // Times per period
521-
abi.encode(uint256(4)), // Sortition extra data
522-
badSupportedDK
523-
);
524506

525507
badSupportedDK[0] = DISPUTE_KIT_CLASSIC;
526508
badSupportedDK[1] = 2; // Check out of bounds index
@@ -543,7 +525,7 @@ contract KlerosCoreTest is Test {
543525
vm.prank(governor);
544526
core.addNewDisputeKit(newDK);
545527
badSupportedDK = new uint256[](1);
546-
badSupportedDK[0] = 2; // Include only sybil resistant dk
528+
badSupportedDK[0] = 1; // Include only sybil resistant dk
547529
vm.expectRevert(KlerosCoreBase.MustSupportDisputeKitClassic.selector);
548530
vm.prank(governor);
549531
core.createCourt(
@@ -562,7 +544,7 @@ contract KlerosCoreTest is Test {
562544
vm.expectEmit(true, true, true, true);
563545
emit KlerosCoreBase.DisputeKitEnabled(2, DISPUTE_KIT_CLASSIC, true);
564546
vm.expectEmit(true, true, true, true);
565-
emit KlerosCoreBase.DisputeKitEnabled(2, 2, true);
547+
emit KlerosCoreBase.DisputeKitEnabled(2, 1, true);
566548
vm.expectEmit(true, true, true, true);
567549
emit KlerosCoreBase.CourtCreated(
568550
2,
@@ -721,7 +703,7 @@ contract KlerosCoreTest is Test {
721703

722704
function test_enableDisputeKits() public {
723705
DisputeKitSybilResistant newDK = new DisputeKitSybilResistant();
724-
uint256 newDkID = 2;
706+
uint256 newDkID = 1;
725707
vm.prank(governor);
726708
core.addNewDisputeKit(newDK);
727709

@@ -733,12 +715,7 @@ contract KlerosCoreTest is Test {
733715

734716
vm.expectRevert(KlerosCoreBase.WrongDisputeKitIndex.selector);
735717
vm.prank(governor);
736-
supportedDK[0] = NULL_DISPUTE_KIT;
737-
core.enableDisputeKits(GENERAL_COURT, supportedDK, true);
738-
739-
vm.expectRevert(KlerosCoreBase.WrongDisputeKitIndex.selector);
740-
vm.prank(governor);
741-
supportedDK[0] = 3; // Out of bounds
718+
supportedDK[0] = 2; // Out of bounds
742719
core.enableDisputeKits(GENERAL_COURT, supportedDK, true);
743720

744721
vm.expectRevert(KlerosCoreBase.CannotDisableClassicDK.selector);
@@ -821,12 +798,12 @@ contract KlerosCoreTest is Test {
821798
core.addNewDisputeKit(disputeKit);
822799
core.addNewDisputeKit(disputeKit);
823800
core.addNewDisputeKit(disputeKit);
824-
extraData = abi.encodePacked(uint256(50), uint256(41), uint256(6));
801+
extraData = abi.encodePacked(uint256(50), uint256(41), uint256(5));
825802

826803
(courtID, minJurors, disputeKitID) = core.extraDataToCourtIDMinJurorsDisputeKit(extraData);
827804
assertEq(courtID, GENERAL_COURT, "Wrong courtID"); // Value in extra data is out of scope so fall back
828805
assertEq(minJurors, 41, "Wrong minJurors");
829-
assertEq(disputeKitID, 6, "Wrong disputeKitID");
806+
assertEq(disputeKitID, 5, "Wrong disputeKitID");
830807
}
831808

832809
// *************************************** //
@@ -1316,7 +1293,7 @@ contract KlerosCoreTest is Test {
13161293
uint256 newFee = 0.01 ether;
13171294
uint96 newCourtID = 2;
13181295
uint256 newNbJurors = 4;
1319-
uint256 newDkID = 2;
1296+
uint256 newDkID = 1;
13201297
uint256[] memory supportedDK = new uint256[](1);
13211298
supportedDK[0] = DISPUTE_KIT_CLASSIC;
13221299
bytes memory newExtraData = abi.encodePacked(uint256(newCourtID), newNbJurors, newDkID);
@@ -2082,7 +2059,7 @@ contract KlerosCoreTest is Test {
20822059
DisputeKitClassic newDisputeKit = DisputeKitClassic(address(proxyDk));
20832060

20842061
uint96 newCourtID = 2;
2085-
uint256 newDkID = 2;
2062+
uint256 newDkID = 1;
20862063
uint256[] memory supportedDK = new uint256[](1);
20872064
supportedDK[0] = DISPUTE_KIT_CLASSIC;
20882065
bytes memory newExtraData = abi.encodePacked(uint256(newCourtID), DEFAULT_NB_OF_JURORS, newDkID);

0 commit comments

Comments
 (0)