diff --git a/contracts/scripts/simulations/tasks.ts b/contracts/scripts/simulations/tasks.ts index 4340456fd..e8eb890dd 100644 --- a/contracts/scripts/simulations/tasks.ts +++ b/contracts/scripts/simulations/tasks.ts @@ -85,7 +85,7 @@ task("simulate:create-court", "callable by Governor only. Create a new Court") const hiddenVotes = false as boolean; const timesPerPeriod = [300, 300, 300, 300] as [BigNumberish, BigNumberish, BigNumberish, BigNumberish]; const sortitionSumTreeK = ethers.toBeHex(3); - const supportedDisputeKits = [1] as BigNumberish[]; // IDs of supported dispute kits + const supportedDisputeKits = [0] as BigNumberish[]; // IDs of supported dispute kits let courtID; try { const tx = await ( diff --git a/contracts/src/arbitration/KlerosCoreBase.sol b/contracts/src/arbitration/KlerosCoreBase.sol index ae743ea30..28115c272 100644 --- a/contracts/src/arbitration/KlerosCoreBase.sol +++ b/contracts/src/arbitration/KlerosCoreBase.sol @@ -207,9 +207,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable jurorProsecutionModule = _jurorProsecutionModule; sortitionModule = _sortitionModuleAddress; - // NULL_DISPUTE_KIT: an empty element at index 0 to indicate when a dispute kit is not supported. - disputeKits.push(); - // DISPUTE_KIT_CLASSIC disputeKits.push(_disputeKit); @@ -346,7 +343,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable Court storage court = courts.push(); for (uint256 i = 0; i < _supportedDisputeKits.length; i++) { - if (_supportedDisputeKits[i] == 0 || _supportedDisputeKits[i] >= disputeKits.length) { + if (_supportedDisputeKits[i] >= disputeKits.length) { revert WrongDisputeKitIndex(); } _enableDisputeKit(uint96(courtID), _supportedDisputeKits[i], true); @@ -422,7 +419,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor { for (uint256 i = 0; i < _disputeKitIDs.length; i++) { if (_enable) { - if (_disputeKitIDs[i] == 0 || _disputeKitIDs[i] >= disputeKits.length) { + if (_disputeKitIDs[i] >= disputeKits.length) { revert WrongDisputeKitIndex(); } _enableDisputeKit(_courtID, _disputeKitIDs[i], true); @@ -1126,8 +1123,8 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable if (minJurors == 0) { minJurors = DEFAULT_NB_OF_JURORS; } - if (disputeKitID == NULL_DISPUTE_KIT || disputeKitID >= disputeKits.length) { - disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used. + if (disputeKitID >= disputeKits.length) { + disputeKitID = DISPUTE_KIT_CLASSIC; } } else { courtID = GENERAL_COURT; @@ -1145,7 +1142,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable error DisputeKitOnly(); error SortitionModuleOnly(); error UnsuccessfulCall(); - error InvalidDisputKitParent(); error MinStakeLowerThanParentCourt(); error UnsupportedDisputeKit(); error InvalidForkingCourtAsParent(); diff --git a/contracts/src/arbitration/SortitionModuleBase.sol b/contracts/src/arbitration/SortitionModuleBase.sol index 2d6e3a9d8..4fa9b0736 100644 --- a/contracts/src/arbitration/SortitionModuleBase.sol +++ b/contracts/src/arbitration/SortitionModuleBase.sol @@ -507,7 +507,7 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr /// @return The stake of the juror in the court. function stakeOf(bytes32 _key, bytes32 _ID) public view returns (uint256) { SortitionSumTree storage tree = sortitionSumTrees[_key]; - uint treeIndex = tree.IDsToNodeIndexes[_ID]; + uint256 treeIndex = tree.IDsToNodeIndexes[_ID]; if (treeIndex == 0) { return 0; } diff --git a/contracts/src/arbitration/devtools/KlerosCoreRuler.sol b/contracts/src/arbitration/devtools/KlerosCoreRuler.sol index 2100ad1c3..8ec1a238b 100644 --- a/contracts/src/arbitration/devtools/KlerosCoreRuler.sol +++ b/contracts/src/arbitration/devtools/KlerosCoreRuler.sol @@ -657,9 +657,6 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { if (minJurors == 0) { minJurors = DEFAULT_NB_OF_JURORS; } - if (disputeKitID == NULL_DISPUTE_KIT) { - disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used. - } } else { courtID = GENERAL_COURT; minJurors = DEFAULT_NB_OF_JURORS; diff --git a/contracts/src/arbitration/university/KlerosCoreUniversity.sol b/contracts/src/arbitration/university/KlerosCoreUniversity.sol index 1f2e888e2..08004d062 100644 --- a/contracts/src/arbitration/university/KlerosCoreUniversity.sol +++ b/contracts/src/arbitration/university/KlerosCoreUniversity.sol @@ -214,9 +214,6 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable { jurorProsecutionModule = _jurorProsecutionModule; sortitionModule = _sortitionModuleAddress; - // NULL_DISPUTE_KIT: an empty element at index 0 to indicate when a dispute kit is not supported. - disputeKits.push(); - // DISPUTE_KIT_CLASSIC disputeKits.push(_disputeKit); @@ -341,7 +338,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable { Court storage court = courts.push(); for (uint256 i = 0; i < _supportedDisputeKits.length; i++) { - if (_supportedDisputeKits[i] == 0 || _supportedDisputeKits[i] >= disputeKits.length) { + if (_supportedDisputeKits[i] >= disputeKits.length) { revert WrongDisputeKitIndex(); } court.supportedDisputeKits[_supportedDisputeKits[i]] = true; @@ -415,7 +412,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable { function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor { for (uint256 i = 0; i < _disputeKitIDs.length; i++) { if (_enable) { - if (_disputeKitIDs[i] == 0 || _disputeKitIDs[i] >= disputeKits.length) { + if (_disputeKitIDs[i] >= disputeKits.length) { revert WrongDisputeKitIndex(); } _enableDisputeKit(_courtID, _disputeKitIDs[i], true); @@ -1118,8 +1115,8 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable { if (minJurors == 0) { minJurors = DEFAULT_NB_OF_JURORS; } - if (disputeKitID == NULL_DISPUTE_KIT || disputeKitID >= disputeKits.length) { - disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used. + if (disputeKitID >= disputeKits.length) { + disputeKitID = DISPUTE_KIT_CLASSIC; } } else { courtID = GENERAL_COURT; diff --git a/contracts/src/libraries/Constants.sol b/contracts/src/libraries/Constants.sol index f393b4792..73efaa97f 100644 --- a/contracts/src/libraries/Constants.sol +++ b/contracts/src/libraries/Constants.sol @@ -9,8 +9,7 @@ uint96 constant FORKING_COURT = 0; // Index of the forking court. uint96 constant GENERAL_COURT = 1; // Index of the default (general) court. // Dispute Kits -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. -uint256 constant DISPUTE_KIT_CLASSIC = 1; // Index of the default DK. 0 index is skipped. +uint256 constant DISPUTE_KIT_CLASSIC = 0; // Index of the default DK. // Sortition Module uint256 constant MAX_STAKE_PATHS = 4; // The maximum number of stake paths a juror can have. diff --git a/contracts/test/arbitration/draw.ts b/contracts/test/arbitration/draw.ts index 68317612b..99ee160a6 100644 --- a/contracts/test/arbitration/draw.ts +++ b/contracts/test/arbitration/draw.ts @@ -97,7 +97,7 @@ describe("Draw Benchmark", async () => { 256, [0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod ethers.toBeHex(5), // Extra data for sortition module will return the default value of K) - [1] + [0] ) .then((tx) => tx.wait()); }); diff --git a/contracts/test/arbitration/index.ts b/contracts/test/arbitration/index.ts index fa2bc24f3..825136e60 100644 --- a/contracts/test/arbitration/index.ts +++ b/contracts/test/arbitration/index.ts @@ -16,7 +16,7 @@ describe("DisputeKitClassic", async () => { it("Kleros Core initialization", async () => { const events = await core.queryFilter(core.filters.DisputeKitCreated()); expect(events.length).to.equal(1); - expect(events[0].args._disputeKitID).to.equal(1); + expect(events[0].args._disputeKitID).to.equal(0); expect(events[0].args._disputeKitAddress).to.equal(disputeKit.target); // Reminder: the Forking court will be added which will break these expectations. @@ -30,12 +30,12 @@ describe("DisputeKitClassic", async () => { expect(events2[0].args._feeForJuror).to.equal(ethers.parseUnits("0.1", 18)); expect(events2[0].args._jurorsForCourtJump).to.equal(256); expect(events2[0].args._timesPerPeriod).to.deep.equal([0, 0, 0, 10]); - expect(events2[0].args._supportedDisputeKits).to.deep.equal([1]); + expect(events2[0].args._supportedDisputeKits).to.deep.equal([0]); const events3 = await core.queryFilter(core.filters.DisputeKitEnabled()); expect(events3.length).to.equal(1); expect(events3[0].args._courtID).to.equal(1); - expect(events3[0].args._disputeKitID).to.equal(1); + expect(events3[0].args._disputeKitID).to.equal(0); expect(events3[0].args._enable).to.equal(true); }); diff --git a/contracts/test/arbitration/staking-neo.ts b/contracts/test/arbitration/staking-neo.ts index 28834d116..59f71290b 100644 --- a/contracts/test/arbitration/staking-neo.ts +++ b/contracts/test/arbitration/staking-neo.ts @@ -399,7 +399,7 @@ describe("Staking", async () => { describe("When outside the Staking phase", async () => { const createSubcourtStakeAndCreateDispute = async () => { expect(await sortition.phase()).to.be.equal(0); // Staking - 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 + 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 await pnk.approve(core.target, PNK(4000)); await core.setStake(1, PNK(2000)); @@ -734,7 +734,7 @@ describe("Staking", async () => { }); it("Should unstake from all courts", async () => { - 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 + 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 await pnk.approve(core.target, PNK(4000)); await core.setStake(1, PNK(2000)); diff --git a/contracts/test/arbitration/staking.ts b/contracts/test/arbitration/staking.ts index 09af78ba3..b9f3e0ac5 100644 --- a/contracts/test/arbitration/staking.ts +++ b/contracts/test/arbitration/staking.ts @@ -40,7 +40,7 @@ describe("Staking", async () => { const reachDrawingPhase = async () => { expect(await sortition.phase()).to.be.equal(0); // Staking const arbitrationCost = ETH(0.1) * 3n; - 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 + 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 await pnk.approve(core.target, PNK(4000)); await core.setStake(1, PNK(2000)); @@ -386,7 +386,7 @@ describe("Staking", async () => { it("Should unstake from all courts", async () => { const arbitrationCost = ETH(0.1) * 3n; - 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 + 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 await pnk.approve(core.target, PNK(4000)); await core.setStake(1, PNK(2000)); diff --git a/contracts/test/foundry/KlerosCore.t.sol b/contracts/test/foundry/KlerosCore.t.sol index 66d2f22cd..515740d92 100644 --- a/contracts/test/foundry/KlerosCore.t.sol +++ b/contracts/test/foundry/KlerosCore.t.sol @@ -17,7 +17,7 @@ import {TestERC20} from "../../src/token/TestERC20.sol"; import {ArbitrableExample, IArbitrableV2} from "../../src/arbitration/arbitrables/ArbitrableExample.sol"; import {DisputeTemplateRegistry} from "../../src/arbitration/DisputeTemplateRegistry.sol"; import "../../src/libraries/Constants.sol"; -import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/snapshot-proxy/KlerosCoreSnapshotProxy.sol"; +import {IKlerosCore, KlerosCoreSnapshotProxy} from "../../src/arbitration/view/KlerosCoreSnapshotProxy.sol"; contract KlerosCoreTest is Test { event Initialized(uint64 version); @@ -156,7 +156,7 @@ contract KlerosCoreTest is Test { assertEq(address(core.pinakion()), address(pinakion), "Wrong pinakion address"); assertEq(core.jurorProsecutionModule(), jurorProsecutionModule, "Wrong jurorProsecutionModule address"); assertEq(address(core.sortitionModule()), address(sortitionModule), "Wrong sortitionModule address"); - assertEq(core.getDisputeKitsLength(), 2, "Wrong DK array length"); + assertEq(core.getDisputeKitsLength(), 1, "Wrong DK array length"); ( uint96 courtParent, bool courtHiddenVotes, @@ -197,19 +197,16 @@ contract KlerosCoreTest is Test { assertEq(courtTimesPerPeriod[i], timesPerPeriod[i], "Wrong times per period"); } - assertEq(address(core.disputeKits(NULL_DISPUTE_KIT)), address(0), "Wrong address NULL_DISPUTE_KIT"); assertEq( address(core.disputeKits(DISPUTE_KIT_CLASSIC)), address(disputeKit), "Wrong address DISPUTE_KIT_CLASSIC" ); - assertEq(core.isSupported(FORKING_COURT, NULL_DISPUTE_KIT), false, "Forking court null dk should be false"); assertEq( core.isSupported(FORKING_COURT, DISPUTE_KIT_CLASSIC), false, "Forking court classic dk should be false" ); - assertEq(core.isSupported(GENERAL_COURT, NULL_DISPUTE_KIT), false, "General court null dk should be false"); assertEq(core.isSupported(GENERAL_COURT, DISPUTE_KIT_CLASSIC), true, "General court classic dk should be true"); assertEq(core.paused(), false, "Wrong paused value"); @@ -438,10 +435,10 @@ contract KlerosCoreTest is Test { core.addNewDisputeKit(newDK); vm.prank(governor); vm.expectEmit(true, true, true, true); - emit KlerosCoreBase.DisputeKitCreated(2, newDK); + emit KlerosCoreBase.DisputeKitCreated(1, newDK); core.addNewDisputeKit(newDK); - assertEq(address(core.disputeKits(2)), address(newDK), "Wrong address of new DK"); - assertEq(core.getDisputeKitsLength(), 3, "Wrong DK array length"); + assertEq(address(core.disputeKits(1)), address(newDK), "Wrong address of new DK"); + assertEq(core.getDisputeKitsLength(), 2, "Wrong DK array length"); } function test_createCourt() public { @@ -449,7 +446,7 @@ contract KlerosCoreTest is Test { vm.prank(other); uint256[] memory supportedDK = new uint256[](2); supportedDK[0] = DISPUTE_KIT_CLASSIC; - supportedDK[1] = 2; // New DK is added below. + supportedDK[1] = 1; // New DK is added below. core.createCourt( GENERAL_COURT, true, // Hidden votes @@ -506,21 +503,6 @@ contract KlerosCoreTest is Test { ); uint256[] memory badSupportedDK = new uint256[](2); - badSupportedDK[0] = NULL_DISPUTE_KIT; // Include NULL_DK to check that it reverts - badSupportedDK[1] = DISPUTE_KIT_CLASSIC; - vm.expectRevert(KlerosCoreBase.WrongDisputeKitIndex.selector); - vm.prank(governor); - core.createCourt( - GENERAL_COURT, - true, // Hidden votes - 2000, // min stake - 10000, // alpha - 0.03 ether, // fee for juror - 50, // jurors for jump - [uint256(10), uint256(20), uint256(30), uint256(40)], // Times per period - abi.encode(uint256(4)), // Sortition extra data - badSupportedDK - ); badSupportedDK[0] = DISPUTE_KIT_CLASSIC; badSupportedDK[1] = 2; // Check out of bounds index @@ -543,7 +525,7 @@ contract KlerosCoreTest is Test { vm.prank(governor); core.addNewDisputeKit(newDK); badSupportedDK = new uint256[](1); - badSupportedDK[0] = 2; // Include only sybil resistant dk + badSupportedDK[0] = 1; // Include only sybil resistant dk vm.expectRevert(KlerosCoreBase.MustSupportDisputeKitClassic.selector); vm.prank(governor); core.createCourt( @@ -562,7 +544,7 @@ contract KlerosCoreTest is Test { vm.expectEmit(true, true, true, true); emit KlerosCoreBase.DisputeKitEnabled(2, DISPUTE_KIT_CLASSIC, true); vm.expectEmit(true, true, true, true); - emit KlerosCoreBase.DisputeKitEnabled(2, 2, true); + emit KlerosCoreBase.DisputeKitEnabled(2, 1, true); vm.expectEmit(true, true, true, true); emit KlerosCoreBase.CourtCreated( 2, @@ -721,7 +703,7 @@ contract KlerosCoreTest is Test { function test_enableDisputeKits() public { DisputeKitSybilResistant newDK = new DisputeKitSybilResistant(); - uint256 newDkID = 2; + uint256 newDkID = 1; vm.prank(governor); core.addNewDisputeKit(newDK); @@ -733,12 +715,7 @@ contract KlerosCoreTest is Test { vm.expectRevert(KlerosCoreBase.WrongDisputeKitIndex.selector); vm.prank(governor); - supportedDK[0] = NULL_DISPUTE_KIT; - core.enableDisputeKits(GENERAL_COURT, supportedDK, true); - - vm.expectRevert(KlerosCoreBase.WrongDisputeKitIndex.selector); - vm.prank(governor); - supportedDK[0] = 3; // Out of bounds + supportedDK[0] = 2; // Out of bounds core.enableDisputeKits(GENERAL_COURT, supportedDK, true); vm.expectRevert(KlerosCoreBase.CannotDisableClassicDK.selector); @@ -821,12 +798,12 @@ contract KlerosCoreTest is Test { core.addNewDisputeKit(disputeKit); core.addNewDisputeKit(disputeKit); core.addNewDisputeKit(disputeKit); - extraData = abi.encodePacked(uint256(50), uint256(41), uint256(6)); + extraData = abi.encodePacked(uint256(50), uint256(41), uint256(5)); (courtID, minJurors, disputeKitID) = core.extraDataToCourtIDMinJurorsDisputeKit(extraData); assertEq(courtID, GENERAL_COURT, "Wrong courtID"); // Value in extra data is out of scope so fall back assertEq(minJurors, 41, "Wrong minJurors"); - assertEq(disputeKitID, 6, "Wrong disputeKitID"); + assertEq(disputeKitID, 5, "Wrong disputeKitID"); } // *************************************** // @@ -1316,7 +1293,7 @@ contract KlerosCoreTest is Test { uint256 newFee = 0.01 ether; uint96 newCourtID = 2; uint256 newNbJurors = 4; - uint256 newDkID = 2; + uint256 newDkID = 1; uint256[] memory supportedDK = new uint256[](1); supportedDK[0] = DISPUTE_KIT_CLASSIC; bytes memory newExtraData = abi.encodePacked(uint256(newCourtID), newNbJurors, newDkID); @@ -2082,7 +2059,7 @@ contract KlerosCoreTest is Test { DisputeKitClassic newDisputeKit = DisputeKitClassic(address(proxyDk)); uint96 newCourtID = 2; - uint256 newDkID = 2; + uint256 newDkID = 1; uint256[] memory supportedDK = new uint256[](1); supportedDK[0] = DISPUTE_KIT_CLASSIC; bytes memory newExtraData = abi.encodePacked(uint256(newCourtID), DEFAULT_NB_OF_JURORS, newDkID);