From cb2ae4a1abce7ded3e1499365f8f0111243d9f61 Mon Sep 17 00:00:00 2001 From: alcercu Date: Fri, 16 Dec 2022 17:12:03 +0100 Subject: [PATCH 1/6] fix(contracts): remove court and subcourt naming inconsistencies --- contracts/scripts/populateCourts.ts | 52 +-- contracts/src/arbitration/KlerosCore.sol | 352 +++++++++--------- contracts/src/arbitration/PolicyRegistry.sol | 16 +- .../dispute-kits/DisputeKitClassic.sol | 16 +- .../dispute-kits/DisputeKitSybilResistant.sol | 16 +- contracts/src/gateway/ForeignGateway.sol | 42 +-- .../ForeignGatewayOnEthereum.sol | 34 +- contracts/test/arbitration/index.ts | 6 +- contracts/test/arbitration/unstake.ts | 8 +- 9 files changed, 261 insertions(+), 281 deletions(-) diff --git a/contracts/scripts/populateCourts.ts b/contracts/scripts/populateCourts.ts index 286c03531..ab97c4c2e 100644 --- a/contracts/scripts/populateCourts.ts +++ b/contracts/scripts/populateCourts.ts @@ -41,61 +41,61 @@ async function main() { const core = (await ethers.getContractAt("KlerosCore", klerosCoreDeployment.address)) as KlerosCore; for (const court of courtsV2) { - const subcourtPresent = await core.courts(court.id).catch(() => {}); - if (subcourtPresent) { - console.log("Subcourt %d found: %O", court.id, subcourtPresent); + const courtPresent = await core.courts(court.id).catch(() => {}); + if (courtPresent) { + console.log("Court %d found: %O", court.id, courtPresent); - // Subcourt.parent and sortitionSumTreeK cannot be changed. + // Court.parent and sortitionSumTreeK cannot be changed. - if (subcourtPresent.hiddenVotes !== court.hiddenVotes) { + if (courtPresent.hiddenVotes !== court.hiddenVotes) { console.log( - "Subcourt %d: changing hiddenVotes from %d to %d", + "Court %d: changing hiddenVotes from %d to %d", court.id, - subcourtPresent.hiddenVotes, + courtPresent.hiddenVotes, court.hiddenVotes ); - await core.changeSubcourtHiddenVotes(court.id, court.hiddenVotes); + await core.changeCourtHiddenVotes(court.id, court.hiddenVotes); } - if (!subcourtPresent.minStake.eq(court.minStake)) { - console.log("Subcourt %d: changing minStake from %d to %d", court.id, subcourtPresent.minStake, court.minStake); - await core.changeSubcourtMinStake(court.id, court.minStake); + if (!courtPresent.minStake.eq(court.minStake)) { + console.log("Court %d: changing minStake from %d to %d", court.id, courtPresent.minStake, court.minStake); + await core.changeCourtMinStake(court.id, court.minStake); } - if (!subcourtPresent.alpha.eq(court.alpha)) { - console.log("Subcourt %d: changing alpha from %d to %d", court.id, subcourtPresent.alpha, court.alpha); - await core.changeSubcourtAlpha(court.id, court.alpha); + if (!courtPresent.alpha.eq(court.alpha)) { + console.log("Court %d: changing alpha from %d to %d", court.id, courtPresent.alpha, court.alpha); + await core.changeCourtAlpha(court.id, court.alpha); } - if (!subcourtPresent.feeForJuror.eq(court.feeForJuror)) { + if (!courtPresent.feeForJuror.eq(court.feeForJuror)) { console.log( - "Subcourt %d: changing feeForJuror from %d to %d", + "Court %d: changing feeForJuror from %d to %d", court.id, - subcourtPresent.feeForJuror, + courtPresent.feeForJuror, court.feeForJuror ); - await core.changeSubcourtJurorFee(court.id, court.feeForJuror); + await core.changeCourtJurorFee(court.id, court.feeForJuror); } - if (!subcourtPresent.jurorsForCourtJump.eq(court.jurorsForCourtJump)) { + if (!courtPresent.jurorsForCourtJump.eq(court.jurorsForCourtJump)) { console.log( - "Subcourt %d: changing jurorsForCourtJump from %d to %d", + "Court %d: changing jurorsForCourtJump from %d to %d", court.id, - subcourtPresent.jurorsForCourtJump, + courtPresent.jurorsForCourtJump, court.jurorsForCourtJump ); - await core.changeSubcourtJurorsForJump(court.id, court.jurorsForCourtJump); + await core.changeCourtJurorsForJump(court.id, court.jurorsForCourtJump); } const timesPerPeriodPresent = (await core.getTimesPerPeriod(court.id)).map((bn) => bn.toNumber()); if (!timesPerPeriodPresent.every((val, index) => val === court.timesPerPeriod[index])) { console.log( - "Subcourt %d: changing timesPerPeriod from %O to %O", + "Court %d: changing timesPerPeriod from %O to %O", court.id, timesPerPeriodPresent, court.timesPerPeriod ); - await core.changeSubcourtTimesPerPeriod(court.id, [ + await core.changeCourtTimesPerPeriod(court.id, [ court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], @@ -103,8 +103,8 @@ async function main() { ]); } } else { - console.log("Subcourt %d not found, creating it with", court.id, court); - await core.createSubcourt( + console.log("Court %d not found, creating it with", court.id, court); + await core.createCourt( court.parent, court.hiddenVotes, court.minStake, diff --git a/contracts/src/arbitration/KlerosCore.sol b/contracts/src/arbitration/KlerosCore.sol index aec7eccd0..747235db4 100644 --- a/contracts/src/arbitration/KlerosCore.sol +++ b/contracts/src/arbitration/KlerosCore.sol @@ -53,7 +53,7 @@ contract KlerosCore is IArbitrator { } struct Dispute { - uint96 subcourtID; // The ID of the subcourt the dispute is in. + uint96 courtID; // The ID of the court the dispute is in. IArbitrable arbitrated; // The arbitrable contract. Period period; // The current period of the dispute. bool ruled; // True if the ruling has been executed, false otherwise. @@ -72,9 +72,9 @@ contract KlerosCore is IArbitrator { } struct Juror { - uint96[] subcourtIDs; // The IDs of subcourts where the juror's stake path ends. A stake path is a path from the general court to a court the juror directly staked in using `_setStake`. - mapping(uint96 => uint256) stakedTokens; // The number of tokens the juror has staked in the subcourt in the form `stakedTokens[subcourtID]`. - mapping(uint96 => uint256) lockedTokens; // The number of tokens the juror has locked in the subcourt in the form `lockedTokens[subcourtID]`. + uint96[] courtIDs; // The IDs of courts where the juror's stake path ends. A stake path is a path from the general court to a court the juror directly staked in using `_setStake`. + mapping(uint96 => uint256) stakedTokens; // The number of tokens the juror has staked in the court in the form `stakedTokens[courtID]`. + mapping(uint96 => uint256) lockedTokens; // The number of tokens the juror has locked in the court in the form `lockedTokens[courtID]`. } struct DisputeKitNode { @@ -87,7 +87,7 @@ contract KlerosCore is IArbitrator { struct DelayedStake { address account; // The address of the juror. - uint96 subcourtID; // The ID of the subcourt. + uint96 courtID; // The ID of the court. uint256 stake; // The new stake. uint256 penalty; // Penalty value, in case the stake was set during execution. } @@ -115,7 +115,7 @@ contract KlerosCore is IArbitrator { uint256 public maxFreezingTime; // The time after which the phase can be switched back to Staking. uint256 public lastPhaseChange; // The last time the phase was changed. uint256 public freezeBlock; // Number of the block when Core was frozen. - Court[] public courts; // The subcourts. + Court[] public courts; // The courts. DisputeKitNode[] public disputeKitNodes; // The list of DisputeKitNode, indexed by DisputeKitID. uint256[] public disputesKitIDsThatNeedFreezing; // The disputeKitIDs that need switching to Freezing phase. Dispute[] public disputes; // The disputes. @@ -132,12 +132,12 @@ contract KlerosCore is IArbitrator { event NewPhase(Phase _phase); event NewPeriod(uint256 indexed _disputeID, Period _period); - event StakeSet(address indexed _address, uint256 _subcourtID, uint256 _amount, uint256 _newTotalStake); + event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _newTotalStake); event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable); event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable); event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _roundID, uint256 _voteID); - event SubcourtCreated( - uint256 indexed _subcourtID, + event CourtCreated( + uint256 indexed _courtID, uint96 indexed _parent, bool _hiddenVotes, uint256 _minStake, @@ -148,18 +148,18 @@ contract KlerosCore is IArbitrator { uint256 _sortitionSumTreeK, uint256[] _supportedDisputeKits ); - event SubcourtModified(uint96 indexed _subcourtID, string _param); + event CourtModified(uint96 indexed _courtID, string _param); event DisputeKitCreated( uint256 indexed _disputeKitID, IDisputeKit indexed _disputeKitAddress, uint256 indexed _parent ); - event DisputeKitEnabled(uint96 indexed _subcourtID, uint256 indexed _disputeKitID, bool indexed _enable); + event DisputeKitEnabled(uint96 indexed _courtID, uint256 indexed _disputeKitID, bool indexed _enable); event CourtJump( uint256 indexed _disputeID, uint256 indexed _roundID, - uint96 indexed _fromSubcourtID, - uint96 _toSubcourtID + uint96 indexed _fromCourtID, + uint96 _toCourtID ); event DisputeKitJump( uint256 indexed _disputeID, @@ -228,7 +228,7 @@ contract KlerosCore is IArbitrator { emit DisputeKitCreated(DISPUTE_KIT_CLASSIC, _disputeKit, NULL_DISPUTE_KIT); // FORKING_COURT - // TODO: Fill the properties for the Forking court, emit SubcourtCreated. + // TODO: Fill the properties for the Forking court, emit CourtCreated. courts.push(); sortitionSumTrees.createTree(bytes32(uint256(FORKING_COURT)), _sortitionSumTreeK); @@ -243,7 +243,7 @@ contract KlerosCore is IArbitrator { court.jurorsForCourtJump = _courtParameters[3]; court.timesPerPeriod = _timesPerPeriod; sortitionSumTrees.createTree(bytes32(uint256(GENERAL_COURT)), _sortitionSumTreeK); - emit SubcourtCreated( + emit CourtCreated( 1, court.parent, _hiddenVotes, @@ -342,18 +342,18 @@ contract KlerosCore is IArbitrator { } } - /** @dev Creates a subcourt under a specified parent court. - * @param _parent The `parent` property value of the subcourt. - * @param _hiddenVotes The `hiddenVotes` property value of the subcourt. - * @param _minStake The `minStake` property value of the subcourt. - * @param _alpha The `alpha` property value of the subcourt. - * @param _feeForJuror The `feeForJuror` property value of the subcourt. - * @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the subcourt. - * @param _timesPerPeriod The `timesPerPeriod` property value of the subcourt. - * @param _sortitionSumTreeK The number of children per node of the subcourt's sortition sum tree. - * @param _supportedDisputeKits Indexes of dispute kits that this subcourt will support. + /** @dev Creates a court under a specified parent court. + * @param _parent The `parent` property value of the court. + * @param _hiddenVotes The `hiddenVotes` property value of the court. + * @param _minStake The `minStake` property value of the court. + * @param _alpha The `alpha` property value of the court. + * @param _feeForJuror The `feeForJuror` property value of the court. + * @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the court. + * @param _timesPerPeriod The `timesPerPeriod` property value of the court. + * @param _sortitionSumTreeK The number of children per node of the court's sortition sum tree. + * @param _supportedDisputeKits Indexes of dispute kits that this court will support. */ - function createSubcourt( + function createCourt( uint96 _parent, bool _hiddenVotes, uint256 _minStake, @@ -368,7 +368,7 @@ contract KlerosCore is IArbitrator { require(_supportedDisputeKits.length > 0, "!Supported DK"); require(_parent != FORKING_COURT, "Invalid: Forking court as parent"); - uint256 subcourtID = courts.length; + uint256 courtID = courts.length; Court storage court = courts.push(); for (uint256 i = 0; i < _supportedDisputeKits.length; i++) { @@ -388,11 +388,11 @@ contract KlerosCore is IArbitrator { court.jurorsForCourtJump = _jurorsForCourtJump; court.timesPerPeriod = _timesPerPeriod; - sortitionSumTrees.createTree(bytes32(subcourtID), _sortitionSumTreeK); + sortitionSumTrees.createTree(bytes32(courtID), _sortitionSumTreeK); // Update the parent. - courts[_parent].children.push(subcourtID); - emit SubcourtCreated( - subcourtID, + courts[_parent].children.push(courtID); + emit CourtCreated( + courtID, _parent, _hiddenVotes, _minStake, @@ -405,92 +405,85 @@ contract KlerosCore is IArbitrator { ); } - /** @dev Changes the `minStake` property value of a specified subcourt. Don't set to a value lower than its parent's `minStake` property value. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `minStake` property value of a specified court. Don't set to a value lower than its parent's `minStake` property value. + * @param _courtID The ID of the court. * @param _minStake The new value for the `minStake` property value. */ - function changeSubcourtMinStake(uint96 _subcourtID, uint256 _minStake) external onlyByGovernor { + function changeCourtMinStake(uint96 _courtID, uint256 _minStake) external onlyByGovernor { require( - _subcourtID == GENERAL_COURT || courts[courts[_subcourtID].parent].minStake <= _minStake, + _courtID == GENERAL_COURT || courts[courts[_courtID].parent].minStake <= _minStake, "MinStake lower than parent court" ); - for (uint256 i = 0; i < courts[_subcourtID].children.length; i++) { - require(courts[courts[_subcourtID].children[i]].minStake >= _minStake, "MinStake lower than parent court"); + for (uint256 i = 0; i < courts[_courtID].children.length; i++) { + require(courts[courts[_courtID].children[i]].minStake >= _minStake, "MinStake lower than parent court"); } - courts[_subcourtID].minStake = _minStake; - emit SubcourtModified(_subcourtID, "minStake"); + courts[_courtID].minStake = _minStake; + emit CourtModified(_courtID, "minStake"); } - /** @dev Changes the `alpha` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `alpha` property value of a specified court. + * @param _courtID The ID of the court. * @param _alpha The new value for the `alpha` property value. */ - function changeSubcourtAlpha(uint96 _subcourtID, uint256 _alpha) external onlyByGovernor { - courts[_subcourtID].alpha = _alpha; - emit SubcourtModified(_subcourtID, "alpha"); + function changeCourtAlpha(uint96 _courtID, uint256 _alpha) external onlyByGovernor { + courts[_courtID].alpha = _alpha; + emit CourtModified(_courtID, "alpha"); } - /** @dev Changes the `feeForJuror` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `feeForJuror` property value of a specified court. + * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { - courts[_subcourtID].feeForJuror = _feeForJuror; - emit SubcourtModified(_subcourtID, "feeForJuror"); + function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + courts[_courtID].feeForJuror = _feeForJuror; + emit CourtModified(_courtID, "feeForJuror"); } - /** @dev Changes the `jurorsForCourtJump` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `jurorsForCourtJump` property value of a specified court. + * @param _courtID The ID of the court. * @param _jurorsForCourtJump The new value for the `jurorsForCourtJump` property value. */ - function changeSubcourtJurorsForJump(uint96 _subcourtID, uint256 _jurorsForCourtJump) external onlyByGovernor { - courts[_subcourtID].jurorsForCourtJump = _jurorsForCourtJump; - emit SubcourtModified(_subcourtID, "jurorsForCourtJump"); + function changeCourtJurorsForJump(uint96 _courtID, uint256 _jurorsForCourtJump) external onlyByGovernor { + courts[_courtID].jurorsForCourtJump = _jurorsForCourtJump; + emit CourtModified(_courtID, "jurorsForCourtJump"); } - /** @dev Changes the `hiddenVotes` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `hiddenVotes` property value of a specified court. + * @param _courtID The ID of the court. * @param _hiddenVotes The new value for the `hiddenVotes` property value. */ - function changeSubcourtHiddenVotes(uint96 _subcourtID, bool _hiddenVotes) external onlyByGovernor { - courts[_subcourtID].hiddenVotes = _hiddenVotes; - emit SubcourtModified(_subcourtID, "hiddenVotes"); + function changeCourtHiddenVotes(uint96 _courtID, bool _hiddenVotes) external onlyByGovernor { + courts[_courtID].hiddenVotes = _hiddenVotes; + emit CourtModified(_courtID, "hiddenVotes"); } - /** @dev Changes the `timesPerPeriod` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `timesPerPeriod` property value of a specified court. + * @param _courtID The ID of the court. * @param _timesPerPeriod The new value for the `timesPerPeriod` property value. */ - function changeSubcourtTimesPerPeriod( - uint96 _subcourtID, - uint256[4] memory _timesPerPeriod - ) external onlyByGovernor { - courts[_subcourtID].timesPerPeriod = _timesPerPeriod; - emit SubcourtModified(_subcourtID, "timesPerPeriod"); + function changeCourtTimesPerPeriod(uint96 _courtID, uint256[4] memory _timesPerPeriod) external onlyByGovernor { + courts[_courtID].timesPerPeriod = _timesPerPeriod; + emit CourtModified(_courtID, "timesPerPeriod"); } /** @dev Adds/removes court's support for specified dispute kits. - * @param _subcourtID The ID of the subcourt. + * @param _courtID The ID of the court. * @param _disputeKitIDs The IDs of dispute kits which support should be added/removed. - * @param _enable Whether add or remove the dispute kits from the subcourt. + * @param _enable Whether add or remove the dispute kits from the court. */ - function enableDisputeKits( - uint96 _subcourtID, - uint256[] memory _disputeKitIDs, - bool _enable - ) external onlyByGovernor { - Court storage subcourt = courts[_subcourtID]; + function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor { + Court storage court = courts[_courtID]; for (uint256 i = 0; i < _disputeKitIDs.length; i++) { if (_enable) { require(_disputeKitIDs[i] > 0 && _disputeKitIDs[i] < disputeKitNodes.length, "Wrong DK index"); - enableDisputeKit(_subcourtID, _disputeKitIDs[i], true); + enableDisputeKit(_courtID, _disputeKitIDs[i], true); } else { require( - !(_subcourtID == GENERAL_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT), + !(_courtID == GENERAL_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT), "Can't disable Root DK in General" ); - enableDisputeKit(_subcourtID, _disputeKitIDs[i], false); + enableDisputeKit(_courtID, _disputeKitIDs[i], false); } } } @@ -499,12 +492,12 @@ contract KlerosCore is IArbitrator { // * State Modifiers * // // ************************************* // - /** @dev Sets the caller's stake in a subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Sets the caller's stake in a court. + * @param _courtID The ID of the court. * @param _stake The new stake. */ - function setStake(uint96 _subcourtID, uint256 _stake) external { - require(setStakeForAccount(msg.sender, _subcourtID, _stake, 0), "Staking failed"); + function setStake(uint96 _courtID, uint256 _stake) external { + require(setStakeForAccount(msg.sender, _courtID, _stake, 0), "Staking failed"); } /** @dev Executes the next delayed stakes. @@ -520,7 +513,7 @@ contract KlerosCore is IArbitrator { for (uint256 i = delayedStakeReadIndex; i < newDelayedStakeReadIndex; i++) { DelayedStake storage delayedStake = delayedStakes[i]; - setStakeForAccount(delayedStake.account, delayedStake.subcourtID, delayedStake.stake, delayedStake.penalty); + setStakeForAccount(delayedStake.account, delayedStake.courtID, delayedStake.stake, delayedStake.penalty); delete delayedStakes[i]; } delayedStakeReadIndex = newDelayedStakeReadIndex; @@ -528,7 +521,7 @@ contract KlerosCore is IArbitrator { /** @dev Creates a dispute. Must be called by the arbitrable contract. * @param _numberOfChoices Number of choices for the jurors to choose from. - * @param _extraData Additional info about the dispute. We use it to pass the ID of the dispute's subcourt (first 32 bytes), + * @param _extraData Additional 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). * @return disputeID The ID of the created dispute. */ @@ -538,17 +531,17 @@ contract KlerosCore is IArbitrator { ) external payable override returns (uint256 disputeID) { require(msg.value >= arbitrationCost(_extraData), "ETH too low for arbitration cost"); - (uint96 subcourtID, , uint256 disputeKitID) = extraDataToSubcourtIDMinJurorsDisputeKit(_extraData); - require(courts[subcourtID].supportedDisputeKits[disputeKitID], "DK unsupported by subcourt"); + (uint96 courtID, , uint256 disputeKitID) = extraDataToCourtIDMinJurorsDisputeKit(_extraData); + require(courts[courtID].supportedDisputeKits[disputeKitID], "DK unsupported by court"); disputeID = disputes.length; Dispute storage dispute = disputes.push(); - dispute.subcourtID = subcourtID; + dispute.courtID = courtID; dispute.arbitrated = IArbitrable(msg.sender); dispute.lastPeriodChange = block.timestamp; IDisputeKit disputeKit = disputeKitNodes[disputeKitID].disputeKit; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; Round storage round = dispute.rounds.push(); round.nbVotes = msg.value / court.feeForJuror; round.disputeKitID = disputeKitID; @@ -611,7 +604,7 @@ contract KlerosCore is IArbitrator { */ function passPeriod(uint256 _disputeID) external { Dispute storage dispute = disputes[_disputeID]; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; uint256 currentRound = dispute.rounds.length - 1; Round storage round = dispute.rounds[currentRound]; @@ -672,7 +665,7 @@ contract KlerosCore is IArbitrator { address drawnAddress = disputeKit.draw(_disputeID); if (drawnAddress != address(0)) { // In case no one has staked at the court yet. - jurors[drawnAddress].lockedTokens[dispute.subcourtID] += round.tokensAtStakePerJuror; + jurors[drawnAddress].lockedTokens[dispute.courtID] += round.tokensAtStakePerJuror; emit Draw(drawnAddress, _disputeID, currentRound, round.drawnJurors.length); round.drawnJurors.push(drawnAddress); } @@ -694,18 +687,18 @@ contract KlerosCore is IArbitrator { Round storage round = dispute.rounds[dispute.rounds.length - 1]; require(msg.sender == address(disputeKitNodes[round.disputeKitID].disputeKit), "Dispute Kit only"); - uint96 newSubcourtID = dispute.subcourtID; + uint96 newCourtID = dispute.courtID; uint256 newDisputeKitID = round.disputeKitID; // Warning: the extra round must be created before calling disputeKit.createDispute() Round storage extraRound = dispute.rounds.push(); - if (round.nbVotes >= courts[newSubcourtID].jurorsForCourtJump) { - // Jump to parent subcourt. - newSubcourtID = courts[newSubcourtID].parent; + if (round.nbVotes >= courts[newCourtID].jurorsForCourtJump) { + // Jump to parent court. + newCourtID = courts[newCourtID].parent; for (uint256 i = 0; i < SEARCH_ITERATIONS; i++) { - if (courts[newSubcourtID].supportedDisputeKits[newDisputeKitID]) { + if (courts[newCourtID].supportedDisputeKits[newDisputeKitID]) { break; } else if (disputeKitNodes[newDisputeKitID].parent != NULL_DISPUTE_KIT) { newDisputeKitID = disputeKitNodes[newDisputeKitID].parent; @@ -713,25 +706,25 @@ contract KlerosCore is IArbitrator { // DK's parent has 0 index, that means we reached the root DK (0 depth level). // Jump to the next parent court if the current court doesn't support any DK from this tree. // Note that we don't reset newDisputeKitID in this case as, a precaution. - newSubcourtID = courts[newSubcourtID].parent; + newCourtID = courts[newCourtID].parent; } } // We didn't find a court that is compatible with DK from this tree, so we jump directly to the top court. // Note that this can only happen when disputeKitID is at its root, and each root DK is supported by the top court by default. - if (!courts[newSubcourtID].supportedDisputeKits[newDisputeKitID]) { - newSubcourtID = GENERAL_COURT; + if (!courts[newCourtID].supportedDisputeKits[newDisputeKitID]) { + newCourtID = GENERAL_COURT; } - if (newSubcourtID != dispute.subcourtID) { - emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.subcourtID, newSubcourtID); + if (newCourtID != dispute.courtID) { + emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.courtID, newCourtID); } } - dispute.subcourtID = newSubcourtID; + dispute.courtID = newCourtID; dispute.period = Period.evidence; dispute.lastPeriodChange = block.timestamp; - Court storage court = courts[newSubcourtID]; + Court storage court = courts[newCourtID]; extraRound.nbVotes = msg.value / court.feeForJuror; // As many votes that can be afforded by the provided funds. extraRound.tokensAtStakePerJuror = (court.minStake * court.alpha) / ALPHA_DIVISOR; extraRound.totalFeesForJurors = msg.value; @@ -801,21 +794,21 @@ contract KlerosCore is IArbitrator { penaltiesInRoundCache += penalty; account = round.drawnJurors[i]; - jurors[account].lockedTokens[dispute.subcourtID] -= penalty; // Release this part of locked tokens. + jurors[account].lockedTokens[dispute.courtID] -= penalty; // Release this part of locked tokens. // Can only update the stake if it is able to cover the minStake and penalty, otherwise unstake from the court. - if (jurors[account].stakedTokens[dispute.subcourtID] >= courts[dispute.subcourtID].minStake + penalty) { - uint256 newStake = jurors[account].stakedTokens[dispute.subcourtID] - penalty; - setStakeForAccount(account, dispute.subcourtID, newStake, penalty); - } else if (jurors[account].stakedTokens[dispute.subcourtID] != 0) { - setStakeForAccount(account, dispute.subcourtID, 0, penalty); + if (jurors[account].stakedTokens[dispute.courtID] >= courts[dispute.courtID].minStake + penalty) { + uint256 newStake = jurors[account].stakedTokens[dispute.courtID] - penalty; + setStakeForAccount(account, dispute.courtID, newStake, penalty); + } else if (jurors[account].stakedTokens[dispute.courtID] != 0) { + setStakeForAccount(account, dispute.courtID, 0, penalty); } // Unstake the juror if he lost due to inactivity. if (!disputeKit.isVoteActive(_disputeID, _round, i)) { - uint96[] memory subcourtIDs = getJurorSubcourtIDs(account); - for (uint256 j = 0; j < subcourtIDs.length; j++) { - setStakeForAccount(account, subcourtIDs[j], 0, 0); + uint96[] memory courtIDs = getJurorCourtIDs(account); + for (uint256 j = 0; j < courtIDs.length; j++) { + setStakeForAccount(account, courtIDs[j], 0, 0); } } emit TokenAndETHShift(account, _disputeID, -int256(penalty), 0); @@ -839,12 +832,12 @@ contract KlerosCore is IArbitrator { account = round.drawnJurors[i % numberOfVotesInRound]; // Release the rest of the tokens of the juror for this round. - jurors[account].lockedTokens[dispute.subcourtID] -= + jurors[account].lockedTokens[dispute.courtID] -= (round.tokensAtStakePerJuror * degreeOfCoherence) / ALPHA_DIVISOR; // Give back the locked tokens in case the juror fully unstaked earlier. - if (jurors[account].stakedTokens[dispute.subcourtID] == 0) { + if (jurors[account].stakedTokens[dispute.courtID] == 0) { uint256 tokenLocked = (round.tokensAtStakePerJuror * degreeOfCoherence) / ALPHA_DIVISOR; safeTransfer(account, tokenLocked); } @@ -880,14 +873,14 @@ contract KlerosCore is IArbitrator { // * Public Views * // // ************************************* // - /** @dev Gets the cost of arbitration in a specified subcourt. - * @param _extraData Additional info about the dispute. We use it to pass the ID of the subcourt to create the dispute in (first 32 bytes) + /** @dev Gets the cost of arbitration in a specified court. + * @param _extraData Additional 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). * @return cost The arbitration cost. */ function arbitrationCost(bytes memory _extraData) public view override returns (uint256 cost) { - (uint96 subcourtID, uint256 minJurors, ) = extraDataToSubcourtIDMinJurorsDisputeKit(_extraData); - cost = courts[subcourtID].feeForJuror * minJurors; + (uint96 courtID, uint256 minJurors, ) = extraDataToCourtIDMinJurorsDisputeKit(_extraData); + cost = courts[courtID].feeForJuror * minJurors; } /** @dev Gets the cost of appealing a specified dispute. @@ -897,17 +890,17 @@ contract KlerosCore is IArbitrator { function appealCost(uint256 _disputeID) public view returns (uint256 cost) { Dispute storage dispute = disputes[_disputeID]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; if (round.nbVotes >= court.jurorsForCourtJump) { - // Jump to parent subcourt. - if (dispute.subcourtID == GENERAL_COURT) { + // Jump to parent court. + if (dispute.courtID == GENERAL_COURT) { // TODO: Handle the forking when appealed in General court. - cost = NON_PAYABLE_AMOUNT; // Get the cost of the parent subcourt. + cost = NON_PAYABLE_AMOUNT; // Get the cost of the parent court. } else { cost = courts[court.parent].feeForJuror * ((round.nbVotes * 2) + 1); } } else { - // Stay in current subcourt. + // Stay in current court. cost = court.feeForJuror * ((round.nbVotes * 2) + 1); } } @@ -921,7 +914,7 @@ contract KlerosCore is IArbitrator { Dispute storage dispute = disputes[_disputeID]; if (dispute.period == Period.appeal) { start = dispute.lastPeriodChange; - end = dispute.lastPeriodChange + courts[dispute.subcourtID].timesPerPeriod[uint256(Period.appeal)]; + end = dispute.lastPeriodChange + courts[dispute.courtID].timesPerPeriod[uint256(Period.appeal)]; } else { start = 0; end = 0; @@ -971,16 +964,13 @@ contract KlerosCore is IArbitrator { return disputes[_disputeID].rounds.length; } - function getJurorBalance( - address _juror, - uint96 _subcourtID - ) external view returns (uint256 staked, uint256 locked) { - staked = jurors[_juror].stakedTokens[_subcourtID]; - locked = jurors[_juror].lockedTokens[_subcourtID]; + function getJurorBalance(address _juror, uint96 _courtID) external view returns (uint256 staked, uint256 locked) { + staked = jurors[_juror].stakedTokens[_courtID]; + locked = jurors[_juror].lockedTokens[_courtID]; } - function isSupported(uint96 _subcourtID, uint256 _disputeKitID) external view returns (bool) { - return courts[_subcourtID].supportedDisputeKits[_disputeKitID]; + function isSupported(uint96 _courtID, uint256 _disputeKitID) external view returns (bool) { + return courts[_courtID].supportedDisputeKits[_disputeKitID]; } /** @dev Gets non-primitive properties of a specified dispute kit node. @@ -992,11 +982,11 @@ contract KlerosCore is IArbitrator { } /** @dev Gets the timesPerPeriod array for a given court. - * @param _subcourtID The ID of the court to get the times from. + * @param _courtID The ID of the court to get the times from. * @return timesPerPeriod The timesPerPeriod array for the given court. */ - function getTimesPerPeriod(uint96 _subcourtID) external view returns (uint256[4] memory timesPerPeriod) { - Court storage court = courts[_subcourtID]; + function getTimesPerPeriod(uint96 _courtID) external view returns (uint256[4] memory timesPerPeriod) { + Court storage court = courts[_courtID]; timesPerPeriod = court.timesPerPeriod; } @@ -1034,7 +1024,7 @@ contract KlerosCore is IArbitrator { function isDisputeKitJumping(uint256 _disputeID) external view returns (bool) { Dispute storage dispute = disputes[_disputeID]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; if (round.nbVotes < court.jurorsForCourtJump) { return false; @@ -1048,54 +1038,54 @@ contract KlerosCore is IArbitrator { return disputesKitIDsThatNeedFreezing; } - function getJurorSubcourtIDs(address _juror) public view returns (uint96[] memory) { - return jurors[_juror].subcourtIDs; + function getJurorCourtIDs(address _juror) public view returns (uint96[] memory) { + return jurors[_juror].courtIDs; } // ************************************* // // * Internal * // // ************************************* // - function enableDisputeKit(uint96 _subcourtID, uint256 _disputeKitID, bool _enable) internal { - courts[_subcourtID].supportedDisputeKits[_disputeKitID] = _enable; - emit DisputeKitEnabled(_subcourtID, _disputeKitID, _enable); + function enableDisputeKit(uint96 _courtID, uint256 _disputeKitID, bool _enable) internal { + courts[_courtID].supportedDisputeKits[_disputeKitID] = _enable; + emit DisputeKitEnabled(_courtID, _disputeKitID, _enable); } - /** @dev Sets the specified juror's stake in a subcourt. + /** @dev Sets the specified juror's stake in a court. * `O(n + p * log_k(j))` where - * `n` is the number of subcourts the juror has staked in, - * `p` is the depth of the subcourt tree, - * `k` is the minimum number of children per node of one of these subcourts' sortition sum tree, - * and `j` is the maximum number of jurors that ever staked in one of these subcourts simultaneously. + * `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. * @param _account The address of the juror. - * @param _subcourtID The ID of the subcourt. + * @param _courtID The ID of the court. * @param _stake The new stake. * @param _penalty Penalized amount won't be transferred back to juror when the stake is lowered. * @return succeeded True if the call succeeded, false otherwise. */ function setStakeForAccount( address _account, - uint96 _subcourtID, + uint96 _courtID, uint256 _stake, uint256 _penalty ) internal returns (bool succeeded) { - if (_subcourtID == FORKING_COURT || _subcourtID > courts.length) return false; + if (_courtID == FORKING_COURT || _courtID > courts.length) return false; Juror storage juror = jurors[_account]; - bytes32 stakePathID = accountAndSubcourtIDToStakePathID(_account, _subcourtID); - uint256 currentStake = sortitionSumTrees.stakeOf(bytes32(uint256(_subcourtID)), stakePathID); + bytes32 stakePathID = accountAndCourtIDToStakePathID(_account, _courtID); + uint256 currentStake = sortitionSumTrees.stakeOf(bytes32(uint256(_courtID)), stakePathID); if (_stake != 0) { // Check against locked tokens in case the min stake was lowered. - if (_stake < courts[_subcourtID].minStake || _stake < juror.lockedTokens[_subcourtID]) return false; - if (currentStake == 0 && juror.subcourtIDs.length >= MAX_STAKE_PATHS) return false; + if (_stake < courts[_courtID].minStake || _stake < juror.lockedTokens[_courtID]) return false; + if (currentStake == 0 && juror.courtIDs.length >= MAX_STAKE_PATHS) return false; } // Delayed action logic. if (phase != Phase.staking) { delayedStakes[++delayedStakeWriteIndex] = DelayedStake({ account: _account, - subcourtID: _subcourtID, + courtID: _courtID, stake: _stake, penalty: _penalty }); @@ -1108,7 +1098,7 @@ contract KlerosCore is IArbitrator { if (transferredAmount > 0) { if (safeTransferFrom(_account, address(this), transferredAmount)) { if (currentStake == 0) { - juror.subcourtIDs.push(_subcourtID); + juror.courtIDs.push(_courtID); } } else { return false; @@ -1116,13 +1106,13 @@ contract KlerosCore is IArbitrator { } } else if (_stake == 0) { // Keep locked tokens in the contract and release them after dispute is executed. - transferredAmount = currentStake - juror.lockedTokens[_subcourtID] - _penalty; + transferredAmount = currentStake - juror.lockedTokens[_courtID] - _penalty; if (transferredAmount > 0) { if (safeTransfer(_account, transferredAmount)) { - for (uint256 i = 0; i < juror.subcourtIDs.length; i++) { - if (juror.subcourtIDs[i] == _subcourtID) { - juror.subcourtIDs[i] = juror.subcourtIDs[juror.subcourtIDs.length - 1]; - juror.subcourtIDs.pop(); + for (uint256 i = 0; i < juror.courtIDs.length; i++) { + if (juror.courtIDs[i] == _courtID) { + juror.courtIDs[i] = juror.courtIDs[juror.courtIDs.length - 1]; + juror.courtIDs.pop(); break; } } @@ -1140,43 +1130,43 @@ contract KlerosCore is IArbitrator { } // Update juror's records. - uint256 newTotalStake = juror.stakedTokens[_subcourtID] - currentStake + _stake; - juror.stakedTokens[_subcourtID] = newTotalStake; + uint256 newTotalStake = juror.stakedTokens[_courtID] - currentStake + _stake; + juror.stakedTokens[_courtID] = newTotalStake; - // Update subcourt parents. + // Update court parents. bool finished = false; - uint256 currentSubcourtID = _subcourtID; + uint256 currentCourtID = _courtID; while (!finished) { - sortitionSumTrees.set(bytes32(currentSubcourtID), _stake, stakePathID); - if (currentSubcourtID == GENERAL_COURT) finished = true; - else currentSubcourtID = courts[currentSubcourtID].parent; + sortitionSumTrees.set(bytes32(currentCourtID), _stake, stakePathID); + if (currentCourtID == GENERAL_COURT) finished = true; + else currentCourtID = courts[currentCourtID].parent; } - emit StakeSet(_account, _subcourtID, _stake, newTotalStake); + emit StakeSet(_account, _courtID, _stake, newTotalStake); return true; } - /** @dev Gets a subcourt ID, the minimum number of jurors and an ID of a dispute kit from a specified extra data bytes array. + /** @dev 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. - * @param _extraData The extra data bytes array. The first 32 bytes are the subcourt ID, the next are the minimum number of jurors and the last are the dispute kit ID. - * @return subcourtID The subcourt ID. + * @param _extraData The 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. + * @return courtID The court ID. * @return minJurors The minimum number of jurors required. * @return disputeKitID The ID of the dispute kit. */ - function extraDataToSubcourtIDMinJurorsDisputeKit( + function extraDataToCourtIDMinJurorsDisputeKit( bytes memory _extraData - ) internal view returns (uint96 subcourtID, uint256 minJurors, uint256 disputeKitID) { + ) internal view returns (uint96 courtID, uint256 minJurors, uint256 disputeKitID) { // Note that if the extradata doesn't contain 32 bytes for the dispute kit ID it'll return the default 0 index. if (_extraData.length >= 64) { assembly { // solium-disable-line security/no-inline-assembly - subcourtID := mload(add(_extraData, 0x20)) + courtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) disputeKitID := mload(add(_extraData, 0x60)) } - if (subcourtID == FORKING_COURT || subcourtID >= courts.length) { - subcourtID = GENERAL_COURT; + if (courtID == FORKING_COURT || courtID >= courts.length) { + courtID = GENERAL_COURT; } if (minJurors == 0) { minJurors = MIN_JURORS; @@ -1185,20 +1175,20 @@ contract KlerosCore is IArbitrator { disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used. } } else { - subcourtID = GENERAL_COURT; + courtID = GENERAL_COURT; minJurors = MIN_JURORS; disputeKitID = DISPUTE_KIT_CLASSIC; } } - /** @dev Packs an account and a subcourt ID into a stake path ID. + /** @dev Packs an account and a court ID into a stake path ID. * @param _account The address of the juror to pack. - * @param _subcourtID The subcourt ID to pack. + * @param _courtID The court ID to pack. * @return stakePathID The stake path ID. */ - function accountAndSubcourtIDToStakePathID( + function accountAndCourtIDToStakePathID( address _account, - uint96 _subcourtID + uint96 _courtID ) internal pure returns (bytes32 stakePathID) { assembly { // solium-disable-line security/no-inline-assembly @@ -1215,7 +1205,7 @@ contract KlerosCore is IArbitrator { } lt(i, 0x20) { i := add(i, 0x01) } { - mstore8(add(ptr, i), byte(i, _subcourtID)) + mstore8(add(ptr, i), byte(i, _courtID)) } stakePathID := mload(ptr) } diff --git a/contracts/src/arbitration/PolicyRegistry.sol b/contracts/src/arbitration/PolicyRegistry.sol index a03873dca..ef7fcefd2 100644 --- a/contracts/src/arbitration/PolicyRegistry.sol +++ b/contracts/src/arbitration/PolicyRegistry.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8; /** * @title PolicyRegistry * @author Enrique Piqueras - - * @dev A contract to maintain a policy for each subcourt. + * @dev A contract to maintain a policy for each court. */ contract PolicyRegistry { // ************************************* // @@ -13,10 +13,10 @@ contract PolicyRegistry { /** * @dev Emitted when a policy is updated. - * @param _subcourtID The ID of the policy's subcourt. + * @param _courtID The ID of the policy's court. * @param _policy The URI of the policy JSON. */ - event PolicyUpdate(uint256 indexed _subcourtID, string _policy); + event PolicyUpdate(uint256 indexed _courtID, string _policy); // ************************************* // // * Storage * // @@ -65,12 +65,12 @@ contract PolicyRegistry { // ************************************* // /** - * @dev Sets the policy for the specified subcourt. - * @param _subcourtID The ID of the specified subcourt. + * @dev Sets the policy for the specified court. + * @param _courtID The ID of the specified court. * @param _policy The URI of the policy JSON. */ - function setPolicy(uint256 _subcourtID, string calldata _policy) external onlyByGovernor { - policies[_subcourtID] = _policy; - emit PolicyUpdate(_subcourtID, policies[_subcourtID]); + function setPolicy(uint256 _courtID, string calldata _policy) external onlyByGovernor { + policies[_courtID] = _policy; + emit PolicyUpdate(_courtID, policies[_courtID]); } } diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol b/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol index 98a411d19..ff6ff098e 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol @@ -226,8 +226,8 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - bytes32 key = bytes32(uint256(subcourtID)); // Get the ID of the tree. + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + bytes32 key = bytes32(uint256(courtID)); // Get the ID of the tree. (uint256 K, uint256 nodesLength, ) = core.getSortitionSumTree(key, 0); uint256 treeIndex = 0; @@ -319,8 +319,8 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { require(_choice <= dispute.numberOfChoices, "Choice out of bounds"); Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - (, bool hiddenVotes, , , , ) = core.courts(subcourtID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + (, bool hiddenVotes, , , , ) = core.courts(courtID); // Save the votes. for (uint256 i = 0; i < _voteIDs.length; i++) { @@ -328,7 +328,7 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { require( !hiddenVotes || round.votes[_voteIDs[i]].commit == keccak256(abi.encodePacked(_choice, _justification, _salt)), - "The commit must match the choice in subcourts with hidden votes." + "The commit must match the choice in courts with hidden votes." ); require(!round.votes[_voteIDs[i]].voted, "Vote already cast."); round.votes[_voteIDs[i]].choice = _choice; @@ -645,13 +645,13 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { * @return Whether the address can be drawn or not. */ function postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) { - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); (uint256 lockedAmountPerJuror, , , , , ) = core.getRoundInfo( _coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1 ); - (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, subcourtID); - (, , uint256 minStake, , , ) = core.courts(subcourtID); + (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, courtID); + (, , uint256 minStake, , , ) = core.courts(courtID); return stakedTokens >= lockedTokens + lockedAmountPerJuror && stakedTokens >= minStake; } diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol index 03a7e63d6..d845d92fa 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol @@ -251,8 +251,8 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - bytes32 key = bytes32(uint256(subcourtID)); // Get the ID of the tree. + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + bytes32 key = bytes32(uint256(courtID)); // Get the ID of the tree. (uint256 K, uint256 nodesLength, ) = core.getSortitionSumTree(key, 0); uint256 treeIndex = 0; @@ -345,8 +345,8 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { require(_choice <= dispute.numberOfChoices, "Choice out of bounds"); Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - (, bool hiddenVotes, , , , ) = core.courts(subcourtID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + (, bool hiddenVotes, , , , ) = core.courts(courtID); // Save the votes. for (uint256 i = 0; i < _voteIDs.length; i++) { @@ -354,7 +354,7 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { require( !hiddenVotes || round.votes[_voteIDs[i]].commit == keccak256(abi.encodePacked(_choice, _justification, _salt)), - "The commit must match the choice in subcourts with hidden votes." + "The commit must match the choice in courts with hidden votes." ); require(!round.votes[_voteIDs[i]].voted, "Vote already cast."); round.votes[_voteIDs[i]].choice = _choice; @@ -671,13 +671,13 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { * @return Whether the address can be drawn or not. */ function postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) { - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); (uint256 lockedAmountPerJuror, , , , , ) = core.getRoundInfo( _coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1 ); - (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, subcourtID); - (, , uint256 minStake, , , ) = core.courts(subcourtID); + (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, courtID); + (, , uint256 minStake, , , ) = core.courts(courtID); if (stakedTokens < lockedTokens + lockedAmountPerJuror || stakedTokens < minStake) { return false; } else { diff --git a/contracts/src/gateway/ForeignGateway.sol b/contracts/src/gateway/ForeignGateway.sol index 8d0f8ac62..506bd0bcb 100644 --- a/contracts/src/gateway/ForeignGateway.sol +++ b/contracts/src/gateway/ForeignGateway.sol @@ -51,7 +51,7 @@ contract ForeignGateway is IForeignGateway { uint256 public immutable override senderChainID; address public immutable override senderGateway; uint256 internal localDisputeID = 1; // The disputeID must start from 1 as the KlerosV1 proxy governor depends on this implementation. We now also depend on localDisputeID not ever being zero. - uint256[] internal feeForJuror; // feeForJuror[subcourtID] + uint256[] internal feeForJuror; // feeForJuror[courtID] address public governor; IFastBridgeReceiver public fastBridgeReceiver; IFastBridgeReceiver public depreciatedFastbridge; @@ -107,19 +107,19 @@ contract ForeignGateway is IForeignGateway { } /** - * @dev Changes the `feeForJuror` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + * @dev Changes the `feeForJuror` property value of a specified court. + * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { - feeForJuror[_subcourtID] = _feeForJuror; + function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + feeForJuror[_courtID] = _feeForJuror; } /** - * @dev Creates the `feeForJuror` property value for a new subcourt. + * @dev Creates the `feeForJuror` property value for a new court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function createSubcourtJurorFee(uint256 _feeForJuror) external onlyByGovernor { + function createCourtJurorFee(uint256 _feeForJuror) external onlyByGovernor { feeForJuror.push(_feeForJuror); } @@ -127,12 +127,10 @@ contract ForeignGateway is IForeignGateway { // * State Modifiers * // // ************************************* // - function createDispute(uint256 _choices, bytes calldata _extraData) - external - payable - override - returns (uint256 disputeID) - { + function createDispute( + uint256 _choices, + bytes calldata _extraData + ) external payable override returns (uint256 disputeID) { require(msg.value >= arbitrationCost(_extraData), "Not paid enough for arbitration"); disputeID = localDisputeID++; @@ -165,9 +163,9 @@ contract ForeignGateway is IForeignGateway { } function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) { - (uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); + (uint96 courtID, uint256 minJurors) = extraDataToCourtIDMinJurors(_extraData); - cost = feeForJuror[subcourtID] * minJurors; + cost = feeForJuror[courtID] * minJurors; } /** @@ -214,22 +212,20 @@ contract ForeignGateway is IForeignGateway { // * Internal * // // ************************ // - function extraDataToSubcourtIDMinJurors(bytes memory _extraData) - internal - view - returns (uint96 subcourtID, uint256 minJurors) - { + function extraDataToCourtIDMinJurors( + bytes memory _extraData + ) internal view returns (uint96 courtID, uint256 minJurors) { // Note that here we ignore DisputeKitID if (_extraData.length >= 64) { assembly { // solium-disable-line security/no-inline-assembly - subcourtID := mload(add(_extraData, 0x20)) + courtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) } - if (subcourtID >= feeForJuror.length) subcourtID = 0; + if (courtID >= feeForJuror.length) courtID = 0; if (minJurors == 0) minJurors = MIN_JURORS; } else { - subcourtID = 0; + courtID = 0; minJurors = MIN_JURORS; } } diff --git a/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol b/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol index 096d8c34b..2ded1ad40 100644 --- a/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol +++ b/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol @@ -29,7 +29,7 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { // at any point. uint256 internal localDisputeID = 1; - // feeForJuror by subcourtID + // feeForJuror by courtID uint256[] internal feeForJuror; uint256 public chainID; uint256 public homeChainID; @@ -84,12 +84,12 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { } } - /** @dev Changes the `feeForJuror` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `feeForJuror` property value of a specified court. + * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { - feeForJuror[_subcourtID] = _feeForJuror; + function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + feeForJuror[_courtID] = _feeForJuror; } function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID) { @@ -121,19 +121,15 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { } function arbitrationCost(bytes calldata _extraData) public view returns (uint256 cost) { - (uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); + (uint96 courtID, uint256 minJurors) = extraDataToCourtIDMinJurors(_extraData); - cost = feeForJuror[subcourtID] * minJurors; + cost = feeForJuror[courtID] * minJurors; } /** * Relay the rule call from the home gateway to the arbitrable. */ - function relayRule( - bytes32 _disputeHash, - uint256 _ruling, - address _relayer - ) external onlyFromFastBridge { + function relayRule(bytes32 _disputeHash, uint256 _ruling, address _relayer) external onlyFromFastBridge { DisputeData storage dispute = disputeHashtoDisputeData[_disputeHash]; require(dispute.id != 0, "Dispute does not exist"); @@ -160,22 +156,20 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { return disputeHashtoDisputeData[_disputeHash].id; } - function extraDataToSubcourtIDMinJurors(bytes memory _extraData) - internal - view - returns (uint96 subcourtID, uint256 minJurors) - { + function extraDataToCourtIDMinJurors( + bytes memory _extraData + ) internal view returns (uint96 courtID, uint256 minJurors) { // Note that here we ignore DisputeKitID if (_extraData.length >= 64) { assembly { // solium-disable-line security/no-inline-assembly - subcourtID := mload(add(_extraData, 0x20)) + courtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) } - if (subcourtID >= feeForJuror.length) subcourtID = 0; + if (courtID >= feeForJuror.length) courtID = 0; if (minJurors == 0) minJurors = MIN_JURORS; } else { - subcourtID = 0; + courtID = 0; minJurors = MIN_JURORS; } } diff --git a/contracts/test/arbitration/index.ts b/contracts/test/arbitration/index.ts index bf1ffe762..4d1ffdbb6 100644 --- a/contracts/test/arbitration/index.ts +++ b/contracts/test/arbitration/index.ts @@ -27,9 +27,9 @@ describe("DisputeKitClassic", async () => { expect(events[0].args._parent).to.equal(0); // Reminder: the Forking court will be added which will break these expectations. - events = await core.queryFilter(core.filters.SubcourtCreated()); + events = await core.queryFilter(core.filters.CourtCreated()); expect(events.length).to.equal(1); - expect(events[0].args._subcourtID).to.equal(1); + expect(events[0].args._courtID).to.equal(1); expect(events[0].args._parent).to.equal(0); expect(events[0].args._hiddenVotes).to.equal(false); expect(events[0].args._minStake).to.equal(200); @@ -47,7 +47,7 @@ describe("DisputeKitClassic", async () => { events = await core.queryFilter(core.filters.DisputeKitEnabled()); expect(events.length).to.equal(1); - expect(events[0].args._subcourtID).to.equal(1); + expect(events[0].args._courtID).to.equal(1); expect(events[0].args._disputeKitID).to.equal(1); expect(events[0].args._enable).to.equal(true); }); diff --git a/contracts/test/arbitration/unstake.ts b/contracts/test/arbitration/unstake.ts index 0cb54205c..d6bd3c882 100644 --- a/contracts/test/arbitration/unstake.ts +++ b/contracts/test/arbitration/unstake.ts @@ -41,13 +41,13 @@ describe("Unstake juror", async () => { it("Unstake inactive juror", async () => { const arbitrationCost = ONE_TENTH_ETH.mul(3); - await core.createSubcourt(1, false, ONE_THOUSAND_PNK, 1000, ONE_TENTH_ETH, 3, [0, 0, 0, 0], 3, [1]); // Parent - general court, Classic dispute kit + await core.createCourt(1, false, ONE_THOUSAND_PNK, 1000, ONE_TENTH_ETH, 3, [0, 0, 0, 0], 3, [1]); // Parent - general court, Classic dispute kit await pnk.approve(core.address, ONE_THOUSAND_PNK.mul(4)); await core.setStake(1, ONE_THOUSAND_PNK.mul(2)); await core.setStake(2, ONE_THOUSAND_PNK.mul(2)); - expect(await core.getJurorSubcourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); + expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); await core.createDispute(2, extraData, { value: arbitrationCost }); @@ -76,10 +76,10 @@ describe("Unstake juror", async () => { await core.passPhase(); // Freezing -> Staking. Change so we don't deal with delayed stakes - expect(await core.getJurorSubcourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); + expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); await core.execute(0, 0, 1); // 1 iteration should unstake from both courts - expect(await core.getJurorSubcourtIDs(deployer)).to.be.deep.equal([]); + expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([]); }); }); From 1ee8762cf790d3f07df0be166f4f25d2d6be95a4 Mon Sep 17 00:00:00 2001 From: alcercu Date: Fri, 16 Dec 2022 17:12:03 +0100 Subject: [PATCH 2/6] fix(contracts): remove court and subcourt naming inconsistencies --- contracts/scripts/populateCourts.ts | 52 +-- contracts/src/arbitration/KlerosCore.sol | 352 +++++++++--------- contracts/src/arbitration/PolicyRegistry.sol | 16 +- .../dispute-kits/DisputeKitClassic.sol | 16 +- .../dispute-kits/DisputeKitSybilResistant.sol | 16 +- contracts/src/gateway/ForeignGateway.sol | 26 +- .../ForeignGatewayOnEthereum.sol | 34 +- contracts/test/arbitration/index.ts | 6 +- contracts/test/arbitration/unstake.ts | 8 +- 9 files changed, 255 insertions(+), 271 deletions(-) diff --git a/contracts/scripts/populateCourts.ts b/contracts/scripts/populateCourts.ts index 286c03531..ab97c4c2e 100644 --- a/contracts/scripts/populateCourts.ts +++ b/contracts/scripts/populateCourts.ts @@ -41,61 +41,61 @@ async function main() { const core = (await ethers.getContractAt("KlerosCore", klerosCoreDeployment.address)) as KlerosCore; for (const court of courtsV2) { - const subcourtPresent = await core.courts(court.id).catch(() => {}); - if (subcourtPresent) { - console.log("Subcourt %d found: %O", court.id, subcourtPresent); + const courtPresent = await core.courts(court.id).catch(() => {}); + if (courtPresent) { + console.log("Court %d found: %O", court.id, courtPresent); - // Subcourt.parent and sortitionSumTreeK cannot be changed. + // Court.parent and sortitionSumTreeK cannot be changed. - if (subcourtPresent.hiddenVotes !== court.hiddenVotes) { + if (courtPresent.hiddenVotes !== court.hiddenVotes) { console.log( - "Subcourt %d: changing hiddenVotes from %d to %d", + "Court %d: changing hiddenVotes from %d to %d", court.id, - subcourtPresent.hiddenVotes, + courtPresent.hiddenVotes, court.hiddenVotes ); - await core.changeSubcourtHiddenVotes(court.id, court.hiddenVotes); + await core.changeCourtHiddenVotes(court.id, court.hiddenVotes); } - if (!subcourtPresent.minStake.eq(court.minStake)) { - console.log("Subcourt %d: changing minStake from %d to %d", court.id, subcourtPresent.minStake, court.minStake); - await core.changeSubcourtMinStake(court.id, court.minStake); + if (!courtPresent.minStake.eq(court.minStake)) { + console.log("Court %d: changing minStake from %d to %d", court.id, courtPresent.minStake, court.minStake); + await core.changeCourtMinStake(court.id, court.minStake); } - if (!subcourtPresent.alpha.eq(court.alpha)) { - console.log("Subcourt %d: changing alpha from %d to %d", court.id, subcourtPresent.alpha, court.alpha); - await core.changeSubcourtAlpha(court.id, court.alpha); + if (!courtPresent.alpha.eq(court.alpha)) { + console.log("Court %d: changing alpha from %d to %d", court.id, courtPresent.alpha, court.alpha); + await core.changeCourtAlpha(court.id, court.alpha); } - if (!subcourtPresent.feeForJuror.eq(court.feeForJuror)) { + if (!courtPresent.feeForJuror.eq(court.feeForJuror)) { console.log( - "Subcourt %d: changing feeForJuror from %d to %d", + "Court %d: changing feeForJuror from %d to %d", court.id, - subcourtPresent.feeForJuror, + courtPresent.feeForJuror, court.feeForJuror ); - await core.changeSubcourtJurorFee(court.id, court.feeForJuror); + await core.changeCourtJurorFee(court.id, court.feeForJuror); } - if (!subcourtPresent.jurorsForCourtJump.eq(court.jurorsForCourtJump)) { + if (!courtPresent.jurorsForCourtJump.eq(court.jurorsForCourtJump)) { console.log( - "Subcourt %d: changing jurorsForCourtJump from %d to %d", + "Court %d: changing jurorsForCourtJump from %d to %d", court.id, - subcourtPresent.jurorsForCourtJump, + courtPresent.jurorsForCourtJump, court.jurorsForCourtJump ); - await core.changeSubcourtJurorsForJump(court.id, court.jurorsForCourtJump); + await core.changeCourtJurorsForJump(court.id, court.jurorsForCourtJump); } const timesPerPeriodPresent = (await core.getTimesPerPeriod(court.id)).map((bn) => bn.toNumber()); if (!timesPerPeriodPresent.every((val, index) => val === court.timesPerPeriod[index])) { console.log( - "Subcourt %d: changing timesPerPeriod from %O to %O", + "Court %d: changing timesPerPeriod from %O to %O", court.id, timesPerPeriodPresent, court.timesPerPeriod ); - await core.changeSubcourtTimesPerPeriod(court.id, [ + await core.changeCourtTimesPerPeriod(court.id, [ court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], @@ -103,8 +103,8 @@ async function main() { ]); } } else { - console.log("Subcourt %d not found, creating it with", court.id, court); - await core.createSubcourt( + console.log("Court %d not found, creating it with", court.id, court); + await core.createCourt( court.parent, court.hiddenVotes, court.minStake, diff --git a/contracts/src/arbitration/KlerosCore.sol b/contracts/src/arbitration/KlerosCore.sol index aec7eccd0..747235db4 100644 --- a/contracts/src/arbitration/KlerosCore.sol +++ b/contracts/src/arbitration/KlerosCore.sol @@ -53,7 +53,7 @@ contract KlerosCore is IArbitrator { } struct Dispute { - uint96 subcourtID; // The ID of the subcourt the dispute is in. + uint96 courtID; // The ID of the court the dispute is in. IArbitrable arbitrated; // The arbitrable contract. Period period; // The current period of the dispute. bool ruled; // True if the ruling has been executed, false otherwise. @@ -72,9 +72,9 @@ contract KlerosCore is IArbitrator { } struct Juror { - uint96[] subcourtIDs; // The IDs of subcourts where the juror's stake path ends. A stake path is a path from the general court to a court the juror directly staked in using `_setStake`. - mapping(uint96 => uint256) stakedTokens; // The number of tokens the juror has staked in the subcourt in the form `stakedTokens[subcourtID]`. - mapping(uint96 => uint256) lockedTokens; // The number of tokens the juror has locked in the subcourt in the form `lockedTokens[subcourtID]`. + uint96[] courtIDs; // The IDs of courts where the juror's stake path ends. A stake path is a path from the general court to a court the juror directly staked in using `_setStake`. + mapping(uint96 => uint256) stakedTokens; // The number of tokens the juror has staked in the court in the form `stakedTokens[courtID]`. + mapping(uint96 => uint256) lockedTokens; // The number of tokens the juror has locked in the court in the form `lockedTokens[courtID]`. } struct DisputeKitNode { @@ -87,7 +87,7 @@ contract KlerosCore is IArbitrator { struct DelayedStake { address account; // The address of the juror. - uint96 subcourtID; // The ID of the subcourt. + uint96 courtID; // The ID of the court. uint256 stake; // The new stake. uint256 penalty; // Penalty value, in case the stake was set during execution. } @@ -115,7 +115,7 @@ contract KlerosCore is IArbitrator { uint256 public maxFreezingTime; // The time after which the phase can be switched back to Staking. uint256 public lastPhaseChange; // The last time the phase was changed. uint256 public freezeBlock; // Number of the block when Core was frozen. - Court[] public courts; // The subcourts. + Court[] public courts; // The courts. DisputeKitNode[] public disputeKitNodes; // The list of DisputeKitNode, indexed by DisputeKitID. uint256[] public disputesKitIDsThatNeedFreezing; // The disputeKitIDs that need switching to Freezing phase. Dispute[] public disputes; // The disputes. @@ -132,12 +132,12 @@ contract KlerosCore is IArbitrator { event NewPhase(Phase _phase); event NewPeriod(uint256 indexed _disputeID, Period _period); - event StakeSet(address indexed _address, uint256 _subcourtID, uint256 _amount, uint256 _newTotalStake); + event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _newTotalStake); event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable); event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable); event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _roundID, uint256 _voteID); - event SubcourtCreated( - uint256 indexed _subcourtID, + event CourtCreated( + uint256 indexed _courtID, uint96 indexed _parent, bool _hiddenVotes, uint256 _minStake, @@ -148,18 +148,18 @@ contract KlerosCore is IArbitrator { uint256 _sortitionSumTreeK, uint256[] _supportedDisputeKits ); - event SubcourtModified(uint96 indexed _subcourtID, string _param); + event CourtModified(uint96 indexed _courtID, string _param); event DisputeKitCreated( uint256 indexed _disputeKitID, IDisputeKit indexed _disputeKitAddress, uint256 indexed _parent ); - event DisputeKitEnabled(uint96 indexed _subcourtID, uint256 indexed _disputeKitID, bool indexed _enable); + event DisputeKitEnabled(uint96 indexed _courtID, uint256 indexed _disputeKitID, bool indexed _enable); event CourtJump( uint256 indexed _disputeID, uint256 indexed _roundID, - uint96 indexed _fromSubcourtID, - uint96 _toSubcourtID + uint96 indexed _fromCourtID, + uint96 _toCourtID ); event DisputeKitJump( uint256 indexed _disputeID, @@ -228,7 +228,7 @@ contract KlerosCore is IArbitrator { emit DisputeKitCreated(DISPUTE_KIT_CLASSIC, _disputeKit, NULL_DISPUTE_KIT); // FORKING_COURT - // TODO: Fill the properties for the Forking court, emit SubcourtCreated. + // TODO: Fill the properties for the Forking court, emit CourtCreated. courts.push(); sortitionSumTrees.createTree(bytes32(uint256(FORKING_COURT)), _sortitionSumTreeK); @@ -243,7 +243,7 @@ contract KlerosCore is IArbitrator { court.jurorsForCourtJump = _courtParameters[3]; court.timesPerPeriod = _timesPerPeriod; sortitionSumTrees.createTree(bytes32(uint256(GENERAL_COURT)), _sortitionSumTreeK); - emit SubcourtCreated( + emit CourtCreated( 1, court.parent, _hiddenVotes, @@ -342,18 +342,18 @@ contract KlerosCore is IArbitrator { } } - /** @dev Creates a subcourt under a specified parent court. - * @param _parent The `parent` property value of the subcourt. - * @param _hiddenVotes The `hiddenVotes` property value of the subcourt. - * @param _minStake The `minStake` property value of the subcourt. - * @param _alpha The `alpha` property value of the subcourt. - * @param _feeForJuror The `feeForJuror` property value of the subcourt. - * @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the subcourt. - * @param _timesPerPeriod The `timesPerPeriod` property value of the subcourt. - * @param _sortitionSumTreeK The number of children per node of the subcourt's sortition sum tree. - * @param _supportedDisputeKits Indexes of dispute kits that this subcourt will support. + /** @dev Creates a court under a specified parent court. + * @param _parent The `parent` property value of the court. + * @param _hiddenVotes The `hiddenVotes` property value of the court. + * @param _minStake The `minStake` property value of the court. + * @param _alpha The `alpha` property value of the court. + * @param _feeForJuror The `feeForJuror` property value of the court. + * @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the court. + * @param _timesPerPeriod The `timesPerPeriod` property value of the court. + * @param _sortitionSumTreeK The number of children per node of the court's sortition sum tree. + * @param _supportedDisputeKits Indexes of dispute kits that this court will support. */ - function createSubcourt( + function createCourt( uint96 _parent, bool _hiddenVotes, uint256 _minStake, @@ -368,7 +368,7 @@ contract KlerosCore is IArbitrator { require(_supportedDisputeKits.length > 0, "!Supported DK"); require(_parent != FORKING_COURT, "Invalid: Forking court as parent"); - uint256 subcourtID = courts.length; + uint256 courtID = courts.length; Court storage court = courts.push(); for (uint256 i = 0; i < _supportedDisputeKits.length; i++) { @@ -388,11 +388,11 @@ contract KlerosCore is IArbitrator { court.jurorsForCourtJump = _jurorsForCourtJump; court.timesPerPeriod = _timesPerPeriod; - sortitionSumTrees.createTree(bytes32(subcourtID), _sortitionSumTreeK); + sortitionSumTrees.createTree(bytes32(courtID), _sortitionSumTreeK); // Update the parent. - courts[_parent].children.push(subcourtID); - emit SubcourtCreated( - subcourtID, + courts[_parent].children.push(courtID); + emit CourtCreated( + courtID, _parent, _hiddenVotes, _minStake, @@ -405,92 +405,85 @@ contract KlerosCore is IArbitrator { ); } - /** @dev Changes the `minStake` property value of a specified subcourt. Don't set to a value lower than its parent's `minStake` property value. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `minStake` property value of a specified court. Don't set to a value lower than its parent's `minStake` property value. + * @param _courtID The ID of the court. * @param _minStake The new value for the `minStake` property value. */ - function changeSubcourtMinStake(uint96 _subcourtID, uint256 _minStake) external onlyByGovernor { + function changeCourtMinStake(uint96 _courtID, uint256 _minStake) external onlyByGovernor { require( - _subcourtID == GENERAL_COURT || courts[courts[_subcourtID].parent].minStake <= _minStake, + _courtID == GENERAL_COURT || courts[courts[_courtID].parent].minStake <= _minStake, "MinStake lower than parent court" ); - for (uint256 i = 0; i < courts[_subcourtID].children.length; i++) { - require(courts[courts[_subcourtID].children[i]].minStake >= _minStake, "MinStake lower than parent court"); + for (uint256 i = 0; i < courts[_courtID].children.length; i++) { + require(courts[courts[_courtID].children[i]].minStake >= _minStake, "MinStake lower than parent court"); } - courts[_subcourtID].minStake = _minStake; - emit SubcourtModified(_subcourtID, "minStake"); + courts[_courtID].minStake = _minStake; + emit CourtModified(_courtID, "minStake"); } - /** @dev Changes the `alpha` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `alpha` property value of a specified court. + * @param _courtID The ID of the court. * @param _alpha The new value for the `alpha` property value. */ - function changeSubcourtAlpha(uint96 _subcourtID, uint256 _alpha) external onlyByGovernor { - courts[_subcourtID].alpha = _alpha; - emit SubcourtModified(_subcourtID, "alpha"); + function changeCourtAlpha(uint96 _courtID, uint256 _alpha) external onlyByGovernor { + courts[_courtID].alpha = _alpha; + emit CourtModified(_courtID, "alpha"); } - /** @dev Changes the `feeForJuror` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `feeForJuror` property value of a specified court. + * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { - courts[_subcourtID].feeForJuror = _feeForJuror; - emit SubcourtModified(_subcourtID, "feeForJuror"); + function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + courts[_courtID].feeForJuror = _feeForJuror; + emit CourtModified(_courtID, "feeForJuror"); } - /** @dev Changes the `jurorsForCourtJump` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `jurorsForCourtJump` property value of a specified court. + * @param _courtID The ID of the court. * @param _jurorsForCourtJump The new value for the `jurorsForCourtJump` property value. */ - function changeSubcourtJurorsForJump(uint96 _subcourtID, uint256 _jurorsForCourtJump) external onlyByGovernor { - courts[_subcourtID].jurorsForCourtJump = _jurorsForCourtJump; - emit SubcourtModified(_subcourtID, "jurorsForCourtJump"); + function changeCourtJurorsForJump(uint96 _courtID, uint256 _jurorsForCourtJump) external onlyByGovernor { + courts[_courtID].jurorsForCourtJump = _jurorsForCourtJump; + emit CourtModified(_courtID, "jurorsForCourtJump"); } - /** @dev Changes the `hiddenVotes` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `hiddenVotes` property value of a specified court. + * @param _courtID The ID of the court. * @param _hiddenVotes The new value for the `hiddenVotes` property value. */ - function changeSubcourtHiddenVotes(uint96 _subcourtID, bool _hiddenVotes) external onlyByGovernor { - courts[_subcourtID].hiddenVotes = _hiddenVotes; - emit SubcourtModified(_subcourtID, "hiddenVotes"); + function changeCourtHiddenVotes(uint96 _courtID, bool _hiddenVotes) external onlyByGovernor { + courts[_courtID].hiddenVotes = _hiddenVotes; + emit CourtModified(_courtID, "hiddenVotes"); } - /** @dev Changes the `timesPerPeriod` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `timesPerPeriod` property value of a specified court. + * @param _courtID The ID of the court. * @param _timesPerPeriod The new value for the `timesPerPeriod` property value. */ - function changeSubcourtTimesPerPeriod( - uint96 _subcourtID, - uint256[4] memory _timesPerPeriod - ) external onlyByGovernor { - courts[_subcourtID].timesPerPeriod = _timesPerPeriod; - emit SubcourtModified(_subcourtID, "timesPerPeriod"); + function changeCourtTimesPerPeriod(uint96 _courtID, uint256[4] memory _timesPerPeriod) external onlyByGovernor { + courts[_courtID].timesPerPeriod = _timesPerPeriod; + emit CourtModified(_courtID, "timesPerPeriod"); } /** @dev Adds/removes court's support for specified dispute kits. - * @param _subcourtID The ID of the subcourt. + * @param _courtID The ID of the court. * @param _disputeKitIDs The IDs of dispute kits which support should be added/removed. - * @param _enable Whether add or remove the dispute kits from the subcourt. + * @param _enable Whether add or remove the dispute kits from the court. */ - function enableDisputeKits( - uint96 _subcourtID, - uint256[] memory _disputeKitIDs, - bool _enable - ) external onlyByGovernor { - Court storage subcourt = courts[_subcourtID]; + function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor { + Court storage court = courts[_courtID]; for (uint256 i = 0; i < _disputeKitIDs.length; i++) { if (_enable) { require(_disputeKitIDs[i] > 0 && _disputeKitIDs[i] < disputeKitNodes.length, "Wrong DK index"); - enableDisputeKit(_subcourtID, _disputeKitIDs[i], true); + enableDisputeKit(_courtID, _disputeKitIDs[i], true); } else { require( - !(_subcourtID == GENERAL_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT), + !(_courtID == GENERAL_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT), "Can't disable Root DK in General" ); - enableDisputeKit(_subcourtID, _disputeKitIDs[i], false); + enableDisputeKit(_courtID, _disputeKitIDs[i], false); } } } @@ -499,12 +492,12 @@ contract KlerosCore is IArbitrator { // * State Modifiers * // // ************************************* // - /** @dev Sets the caller's stake in a subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Sets the caller's stake in a court. + * @param _courtID The ID of the court. * @param _stake The new stake. */ - function setStake(uint96 _subcourtID, uint256 _stake) external { - require(setStakeForAccount(msg.sender, _subcourtID, _stake, 0), "Staking failed"); + function setStake(uint96 _courtID, uint256 _stake) external { + require(setStakeForAccount(msg.sender, _courtID, _stake, 0), "Staking failed"); } /** @dev Executes the next delayed stakes. @@ -520,7 +513,7 @@ contract KlerosCore is IArbitrator { for (uint256 i = delayedStakeReadIndex; i < newDelayedStakeReadIndex; i++) { DelayedStake storage delayedStake = delayedStakes[i]; - setStakeForAccount(delayedStake.account, delayedStake.subcourtID, delayedStake.stake, delayedStake.penalty); + setStakeForAccount(delayedStake.account, delayedStake.courtID, delayedStake.stake, delayedStake.penalty); delete delayedStakes[i]; } delayedStakeReadIndex = newDelayedStakeReadIndex; @@ -528,7 +521,7 @@ contract KlerosCore is IArbitrator { /** @dev Creates a dispute. Must be called by the arbitrable contract. * @param _numberOfChoices Number of choices for the jurors to choose from. - * @param _extraData Additional info about the dispute. We use it to pass the ID of the dispute's subcourt (first 32 bytes), + * @param _extraData Additional 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). * @return disputeID The ID of the created dispute. */ @@ -538,17 +531,17 @@ contract KlerosCore is IArbitrator { ) external payable override returns (uint256 disputeID) { require(msg.value >= arbitrationCost(_extraData), "ETH too low for arbitration cost"); - (uint96 subcourtID, , uint256 disputeKitID) = extraDataToSubcourtIDMinJurorsDisputeKit(_extraData); - require(courts[subcourtID].supportedDisputeKits[disputeKitID], "DK unsupported by subcourt"); + (uint96 courtID, , uint256 disputeKitID) = extraDataToCourtIDMinJurorsDisputeKit(_extraData); + require(courts[courtID].supportedDisputeKits[disputeKitID], "DK unsupported by court"); disputeID = disputes.length; Dispute storage dispute = disputes.push(); - dispute.subcourtID = subcourtID; + dispute.courtID = courtID; dispute.arbitrated = IArbitrable(msg.sender); dispute.lastPeriodChange = block.timestamp; IDisputeKit disputeKit = disputeKitNodes[disputeKitID].disputeKit; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; Round storage round = dispute.rounds.push(); round.nbVotes = msg.value / court.feeForJuror; round.disputeKitID = disputeKitID; @@ -611,7 +604,7 @@ contract KlerosCore is IArbitrator { */ function passPeriod(uint256 _disputeID) external { Dispute storage dispute = disputes[_disputeID]; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; uint256 currentRound = dispute.rounds.length - 1; Round storage round = dispute.rounds[currentRound]; @@ -672,7 +665,7 @@ contract KlerosCore is IArbitrator { address drawnAddress = disputeKit.draw(_disputeID); if (drawnAddress != address(0)) { // In case no one has staked at the court yet. - jurors[drawnAddress].lockedTokens[dispute.subcourtID] += round.tokensAtStakePerJuror; + jurors[drawnAddress].lockedTokens[dispute.courtID] += round.tokensAtStakePerJuror; emit Draw(drawnAddress, _disputeID, currentRound, round.drawnJurors.length); round.drawnJurors.push(drawnAddress); } @@ -694,18 +687,18 @@ contract KlerosCore is IArbitrator { Round storage round = dispute.rounds[dispute.rounds.length - 1]; require(msg.sender == address(disputeKitNodes[round.disputeKitID].disputeKit), "Dispute Kit only"); - uint96 newSubcourtID = dispute.subcourtID; + uint96 newCourtID = dispute.courtID; uint256 newDisputeKitID = round.disputeKitID; // Warning: the extra round must be created before calling disputeKit.createDispute() Round storage extraRound = dispute.rounds.push(); - if (round.nbVotes >= courts[newSubcourtID].jurorsForCourtJump) { - // Jump to parent subcourt. - newSubcourtID = courts[newSubcourtID].parent; + if (round.nbVotes >= courts[newCourtID].jurorsForCourtJump) { + // Jump to parent court. + newCourtID = courts[newCourtID].parent; for (uint256 i = 0; i < SEARCH_ITERATIONS; i++) { - if (courts[newSubcourtID].supportedDisputeKits[newDisputeKitID]) { + if (courts[newCourtID].supportedDisputeKits[newDisputeKitID]) { break; } else if (disputeKitNodes[newDisputeKitID].parent != NULL_DISPUTE_KIT) { newDisputeKitID = disputeKitNodes[newDisputeKitID].parent; @@ -713,25 +706,25 @@ contract KlerosCore is IArbitrator { // DK's parent has 0 index, that means we reached the root DK (0 depth level). // Jump to the next parent court if the current court doesn't support any DK from this tree. // Note that we don't reset newDisputeKitID in this case as, a precaution. - newSubcourtID = courts[newSubcourtID].parent; + newCourtID = courts[newCourtID].parent; } } // We didn't find a court that is compatible with DK from this tree, so we jump directly to the top court. // Note that this can only happen when disputeKitID is at its root, and each root DK is supported by the top court by default. - if (!courts[newSubcourtID].supportedDisputeKits[newDisputeKitID]) { - newSubcourtID = GENERAL_COURT; + if (!courts[newCourtID].supportedDisputeKits[newDisputeKitID]) { + newCourtID = GENERAL_COURT; } - if (newSubcourtID != dispute.subcourtID) { - emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.subcourtID, newSubcourtID); + if (newCourtID != dispute.courtID) { + emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.courtID, newCourtID); } } - dispute.subcourtID = newSubcourtID; + dispute.courtID = newCourtID; dispute.period = Period.evidence; dispute.lastPeriodChange = block.timestamp; - Court storage court = courts[newSubcourtID]; + Court storage court = courts[newCourtID]; extraRound.nbVotes = msg.value / court.feeForJuror; // As many votes that can be afforded by the provided funds. extraRound.tokensAtStakePerJuror = (court.minStake * court.alpha) / ALPHA_DIVISOR; extraRound.totalFeesForJurors = msg.value; @@ -801,21 +794,21 @@ contract KlerosCore is IArbitrator { penaltiesInRoundCache += penalty; account = round.drawnJurors[i]; - jurors[account].lockedTokens[dispute.subcourtID] -= penalty; // Release this part of locked tokens. + jurors[account].lockedTokens[dispute.courtID] -= penalty; // Release this part of locked tokens. // Can only update the stake if it is able to cover the minStake and penalty, otherwise unstake from the court. - if (jurors[account].stakedTokens[dispute.subcourtID] >= courts[dispute.subcourtID].minStake + penalty) { - uint256 newStake = jurors[account].stakedTokens[dispute.subcourtID] - penalty; - setStakeForAccount(account, dispute.subcourtID, newStake, penalty); - } else if (jurors[account].stakedTokens[dispute.subcourtID] != 0) { - setStakeForAccount(account, dispute.subcourtID, 0, penalty); + if (jurors[account].stakedTokens[dispute.courtID] >= courts[dispute.courtID].minStake + penalty) { + uint256 newStake = jurors[account].stakedTokens[dispute.courtID] - penalty; + setStakeForAccount(account, dispute.courtID, newStake, penalty); + } else if (jurors[account].stakedTokens[dispute.courtID] != 0) { + setStakeForAccount(account, dispute.courtID, 0, penalty); } // Unstake the juror if he lost due to inactivity. if (!disputeKit.isVoteActive(_disputeID, _round, i)) { - uint96[] memory subcourtIDs = getJurorSubcourtIDs(account); - for (uint256 j = 0; j < subcourtIDs.length; j++) { - setStakeForAccount(account, subcourtIDs[j], 0, 0); + uint96[] memory courtIDs = getJurorCourtIDs(account); + for (uint256 j = 0; j < courtIDs.length; j++) { + setStakeForAccount(account, courtIDs[j], 0, 0); } } emit TokenAndETHShift(account, _disputeID, -int256(penalty), 0); @@ -839,12 +832,12 @@ contract KlerosCore is IArbitrator { account = round.drawnJurors[i % numberOfVotesInRound]; // Release the rest of the tokens of the juror for this round. - jurors[account].lockedTokens[dispute.subcourtID] -= + jurors[account].lockedTokens[dispute.courtID] -= (round.tokensAtStakePerJuror * degreeOfCoherence) / ALPHA_DIVISOR; // Give back the locked tokens in case the juror fully unstaked earlier. - if (jurors[account].stakedTokens[dispute.subcourtID] == 0) { + if (jurors[account].stakedTokens[dispute.courtID] == 0) { uint256 tokenLocked = (round.tokensAtStakePerJuror * degreeOfCoherence) / ALPHA_DIVISOR; safeTransfer(account, tokenLocked); } @@ -880,14 +873,14 @@ contract KlerosCore is IArbitrator { // * Public Views * // // ************************************* // - /** @dev Gets the cost of arbitration in a specified subcourt. - * @param _extraData Additional info about the dispute. We use it to pass the ID of the subcourt to create the dispute in (first 32 bytes) + /** @dev Gets the cost of arbitration in a specified court. + * @param _extraData Additional 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). * @return cost The arbitration cost. */ function arbitrationCost(bytes memory _extraData) public view override returns (uint256 cost) { - (uint96 subcourtID, uint256 minJurors, ) = extraDataToSubcourtIDMinJurorsDisputeKit(_extraData); - cost = courts[subcourtID].feeForJuror * minJurors; + (uint96 courtID, uint256 minJurors, ) = extraDataToCourtIDMinJurorsDisputeKit(_extraData); + cost = courts[courtID].feeForJuror * minJurors; } /** @dev Gets the cost of appealing a specified dispute. @@ -897,17 +890,17 @@ contract KlerosCore is IArbitrator { function appealCost(uint256 _disputeID) public view returns (uint256 cost) { Dispute storage dispute = disputes[_disputeID]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; if (round.nbVotes >= court.jurorsForCourtJump) { - // Jump to parent subcourt. - if (dispute.subcourtID == GENERAL_COURT) { + // Jump to parent court. + if (dispute.courtID == GENERAL_COURT) { // TODO: Handle the forking when appealed in General court. - cost = NON_PAYABLE_AMOUNT; // Get the cost of the parent subcourt. + cost = NON_PAYABLE_AMOUNT; // Get the cost of the parent court. } else { cost = courts[court.parent].feeForJuror * ((round.nbVotes * 2) + 1); } } else { - // Stay in current subcourt. + // Stay in current court. cost = court.feeForJuror * ((round.nbVotes * 2) + 1); } } @@ -921,7 +914,7 @@ contract KlerosCore is IArbitrator { Dispute storage dispute = disputes[_disputeID]; if (dispute.period == Period.appeal) { start = dispute.lastPeriodChange; - end = dispute.lastPeriodChange + courts[dispute.subcourtID].timesPerPeriod[uint256(Period.appeal)]; + end = dispute.lastPeriodChange + courts[dispute.courtID].timesPerPeriod[uint256(Period.appeal)]; } else { start = 0; end = 0; @@ -971,16 +964,13 @@ contract KlerosCore is IArbitrator { return disputes[_disputeID].rounds.length; } - function getJurorBalance( - address _juror, - uint96 _subcourtID - ) external view returns (uint256 staked, uint256 locked) { - staked = jurors[_juror].stakedTokens[_subcourtID]; - locked = jurors[_juror].lockedTokens[_subcourtID]; + function getJurorBalance(address _juror, uint96 _courtID) external view returns (uint256 staked, uint256 locked) { + staked = jurors[_juror].stakedTokens[_courtID]; + locked = jurors[_juror].lockedTokens[_courtID]; } - function isSupported(uint96 _subcourtID, uint256 _disputeKitID) external view returns (bool) { - return courts[_subcourtID].supportedDisputeKits[_disputeKitID]; + function isSupported(uint96 _courtID, uint256 _disputeKitID) external view returns (bool) { + return courts[_courtID].supportedDisputeKits[_disputeKitID]; } /** @dev Gets non-primitive properties of a specified dispute kit node. @@ -992,11 +982,11 @@ contract KlerosCore is IArbitrator { } /** @dev Gets the timesPerPeriod array for a given court. - * @param _subcourtID The ID of the court to get the times from. + * @param _courtID The ID of the court to get the times from. * @return timesPerPeriod The timesPerPeriod array for the given court. */ - function getTimesPerPeriod(uint96 _subcourtID) external view returns (uint256[4] memory timesPerPeriod) { - Court storage court = courts[_subcourtID]; + function getTimesPerPeriod(uint96 _courtID) external view returns (uint256[4] memory timesPerPeriod) { + Court storage court = courts[_courtID]; timesPerPeriod = court.timesPerPeriod; } @@ -1034,7 +1024,7 @@ contract KlerosCore is IArbitrator { function isDisputeKitJumping(uint256 _disputeID) external view returns (bool) { Dispute storage dispute = disputes[_disputeID]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - Court storage court = courts[dispute.subcourtID]; + Court storage court = courts[dispute.courtID]; if (round.nbVotes < court.jurorsForCourtJump) { return false; @@ -1048,54 +1038,54 @@ contract KlerosCore is IArbitrator { return disputesKitIDsThatNeedFreezing; } - function getJurorSubcourtIDs(address _juror) public view returns (uint96[] memory) { - return jurors[_juror].subcourtIDs; + function getJurorCourtIDs(address _juror) public view returns (uint96[] memory) { + return jurors[_juror].courtIDs; } // ************************************* // // * Internal * // // ************************************* // - function enableDisputeKit(uint96 _subcourtID, uint256 _disputeKitID, bool _enable) internal { - courts[_subcourtID].supportedDisputeKits[_disputeKitID] = _enable; - emit DisputeKitEnabled(_subcourtID, _disputeKitID, _enable); + function enableDisputeKit(uint96 _courtID, uint256 _disputeKitID, bool _enable) internal { + courts[_courtID].supportedDisputeKits[_disputeKitID] = _enable; + emit DisputeKitEnabled(_courtID, _disputeKitID, _enable); } - /** @dev Sets the specified juror's stake in a subcourt. + /** @dev Sets the specified juror's stake in a court. * `O(n + p * log_k(j))` where - * `n` is the number of subcourts the juror has staked in, - * `p` is the depth of the subcourt tree, - * `k` is the minimum number of children per node of one of these subcourts' sortition sum tree, - * and `j` is the maximum number of jurors that ever staked in one of these subcourts simultaneously. + * `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. * @param _account The address of the juror. - * @param _subcourtID The ID of the subcourt. + * @param _courtID The ID of the court. * @param _stake The new stake. * @param _penalty Penalized amount won't be transferred back to juror when the stake is lowered. * @return succeeded True if the call succeeded, false otherwise. */ function setStakeForAccount( address _account, - uint96 _subcourtID, + uint96 _courtID, uint256 _stake, uint256 _penalty ) internal returns (bool succeeded) { - if (_subcourtID == FORKING_COURT || _subcourtID > courts.length) return false; + if (_courtID == FORKING_COURT || _courtID > courts.length) return false; Juror storage juror = jurors[_account]; - bytes32 stakePathID = accountAndSubcourtIDToStakePathID(_account, _subcourtID); - uint256 currentStake = sortitionSumTrees.stakeOf(bytes32(uint256(_subcourtID)), stakePathID); + bytes32 stakePathID = accountAndCourtIDToStakePathID(_account, _courtID); + uint256 currentStake = sortitionSumTrees.stakeOf(bytes32(uint256(_courtID)), stakePathID); if (_stake != 0) { // Check against locked tokens in case the min stake was lowered. - if (_stake < courts[_subcourtID].minStake || _stake < juror.lockedTokens[_subcourtID]) return false; - if (currentStake == 0 && juror.subcourtIDs.length >= MAX_STAKE_PATHS) return false; + if (_stake < courts[_courtID].minStake || _stake < juror.lockedTokens[_courtID]) return false; + if (currentStake == 0 && juror.courtIDs.length >= MAX_STAKE_PATHS) return false; } // Delayed action logic. if (phase != Phase.staking) { delayedStakes[++delayedStakeWriteIndex] = DelayedStake({ account: _account, - subcourtID: _subcourtID, + courtID: _courtID, stake: _stake, penalty: _penalty }); @@ -1108,7 +1098,7 @@ contract KlerosCore is IArbitrator { if (transferredAmount > 0) { if (safeTransferFrom(_account, address(this), transferredAmount)) { if (currentStake == 0) { - juror.subcourtIDs.push(_subcourtID); + juror.courtIDs.push(_courtID); } } else { return false; @@ -1116,13 +1106,13 @@ contract KlerosCore is IArbitrator { } } else if (_stake == 0) { // Keep locked tokens in the contract and release them after dispute is executed. - transferredAmount = currentStake - juror.lockedTokens[_subcourtID] - _penalty; + transferredAmount = currentStake - juror.lockedTokens[_courtID] - _penalty; if (transferredAmount > 0) { if (safeTransfer(_account, transferredAmount)) { - for (uint256 i = 0; i < juror.subcourtIDs.length; i++) { - if (juror.subcourtIDs[i] == _subcourtID) { - juror.subcourtIDs[i] = juror.subcourtIDs[juror.subcourtIDs.length - 1]; - juror.subcourtIDs.pop(); + for (uint256 i = 0; i < juror.courtIDs.length; i++) { + if (juror.courtIDs[i] == _courtID) { + juror.courtIDs[i] = juror.courtIDs[juror.courtIDs.length - 1]; + juror.courtIDs.pop(); break; } } @@ -1140,43 +1130,43 @@ contract KlerosCore is IArbitrator { } // Update juror's records. - uint256 newTotalStake = juror.stakedTokens[_subcourtID] - currentStake + _stake; - juror.stakedTokens[_subcourtID] = newTotalStake; + uint256 newTotalStake = juror.stakedTokens[_courtID] - currentStake + _stake; + juror.stakedTokens[_courtID] = newTotalStake; - // Update subcourt parents. + // Update court parents. bool finished = false; - uint256 currentSubcourtID = _subcourtID; + uint256 currentCourtID = _courtID; while (!finished) { - sortitionSumTrees.set(bytes32(currentSubcourtID), _stake, stakePathID); - if (currentSubcourtID == GENERAL_COURT) finished = true; - else currentSubcourtID = courts[currentSubcourtID].parent; + sortitionSumTrees.set(bytes32(currentCourtID), _stake, stakePathID); + if (currentCourtID == GENERAL_COURT) finished = true; + else currentCourtID = courts[currentCourtID].parent; } - emit StakeSet(_account, _subcourtID, _stake, newTotalStake); + emit StakeSet(_account, _courtID, _stake, newTotalStake); return true; } - /** @dev Gets a subcourt ID, the minimum number of jurors and an ID of a dispute kit from a specified extra data bytes array. + /** @dev 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. - * @param _extraData The extra data bytes array. The first 32 bytes are the subcourt ID, the next are the minimum number of jurors and the last are the dispute kit ID. - * @return subcourtID The subcourt ID. + * @param _extraData The 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. + * @return courtID The court ID. * @return minJurors The minimum number of jurors required. * @return disputeKitID The ID of the dispute kit. */ - function extraDataToSubcourtIDMinJurorsDisputeKit( + function extraDataToCourtIDMinJurorsDisputeKit( bytes memory _extraData - ) internal view returns (uint96 subcourtID, uint256 minJurors, uint256 disputeKitID) { + ) internal view returns (uint96 courtID, uint256 minJurors, uint256 disputeKitID) { // Note that if the extradata doesn't contain 32 bytes for the dispute kit ID it'll return the default 0 index. if (_extraData.length >= 64) { assembly { // solium-disable-line security/no-inline-assembly - subcourtID := mload(add(_extraData, 0x20)) + courtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) disputeKitID := mload(add(_extraData, 0x60)) } - if (subcourtID == FORKING_COURT || subcourtID >= courts.length) { - subcourtID = GENERAL_COURT; + if (courtID == FORKING_COURT || courtID >= courts.length) { + courtID = GENERAL_COURT; } if (minJurors == 0) { minJurors = MIN_JURORS; @@ -1185,20 +1175,20 @@ contract KlerosCore is IArbitrator { disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used. } } else { - subcourtID = GENERAL_COURT; + courtID = GENERAL_COURT; minJurors = MIN_JURORS; disputeKitID = DISPUTE_KIT_CLASSIC; } } - /** @dev Packs an account and a subcourt ID into a stake path ID. + /** @dev Packs an account and a court ID into a stake path ID. * @param _account The address of the juror to pack. - * @param _subcourtID The subcourt ID to pack. + * @param _courtID The court ID to pack. * @return stakePathID The stake path ID. */ - function accountAndSubcourtIDToStakePathID( + function accountAndCourtIDToStakePathID( address _account, - uint96 _subcourtID + uint96 _courtID ) internal pure returns (bytes32 stakePathID) { assembly { // solium-disable-line security/no-inline-assembly @@ -1215,7 +1205,7 @@ contract KlerosCore is IArbitrator { } lt(i, 0x20) { i := add(i, 0x01) } { - mstore8(add(ptr, i), byte(i, _subcourtID)) + mstore8(add(ptr, i), byte(i, _courtID)) } stakePathID := mload(ptr) } diff --git a/contracts/src/arbitration/PolicyRegistry.sol b/contracts/src/arbitration/PolicyRegistry.sol index a03873dca..ef7fcefd2 100644 --- a/contracts/src/arbitration/PolicyRegistry.sol +++ b/contracts/src/arbitration/PolicyRegistry.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8; /** * @title PolicyRegistry * @author Enrique Piqueras - - * @dev A contract to maintain a policy for each subcourt. + * @dev A contract to maintain a policy for each court. */ contract PolicyRegistry { // ************************************* // @@ -13,10 +13,10 @@ contract PolicyRegistry { /** * @dev Emitted when a policy is updated. - * @param _subcourtID The ID of the policy's subcourt. + * @param _courtID The ID of the policy's court. * @param _policy The URI of the policy JSON. */ - event PolicyUpdate(uint256 indexed _subcourtID, string _policy); + event PolicyUpdate(uint256 indexed _courtID, string _policy); // ************************************* // // * Storage * // @@ -65,12 +65,12 @@ contract PolicyRegistry { // ************************************* // /** - * @dev Sets the policy for the specified subcourt. - * @param _subcourtID The ID of the specified subcourt. + * @dev Sets the policy for the specified court. + * @param _courtID The ID of the specified court. * @param _policy The URI of the policy JSON. */ - function setPolicy(uint256 _subcourtID, string calldata _policy) external onlyByGovernor { - policies[_subcourtID] = _policy; - emit PolicyUpdate(_subcourtID, policies[_subcourtID]); + function setPolicy(uint256 _courtID, string calldata _policy) external onlyByGovernor { + policies[_courtID] = _policy; + emit PolicyUpdate(_courtID, policies[_courtID]); } } diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol b/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol index 98a411d19..ff6ff098e 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol @@ -226,8 +226,8 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - bytes32 key = bytes32(uint256(subcourtID)); // Get the ID of the tree. + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + bytes32 key = bytes32(uint256(courtID)); // Get the ID of the tree. (uint256 K, uint256 nodesLength, ) = core.getSortitionSumTree(key, 0); uint256 treeIndex = 0; @@ -319,8 +319,8 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { require(_choice <= dispute.numberOfChoices, "Choice out of bounds"); Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - (, bool hiddenVotes, , , , ) = core.courts(subcourtID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + (, bool hiddenVotes, , , , ) = core.courts(courtID); // Save the votes. for (uint256 i = 0; i < _voteIDs.length; i++) { @@ -328,7 +328,7 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { require( !hiddenVotes || round.votes[_voteIDs[i]].commit == keccak256(abi.encodePacked(_choice, _justification, _salt)), - "The commit must match the choice in subcourts with hidden votes." + "The commit must match the choice in courts with hidden votes." ); require(!round.votes[_voteIDs[i]].voted, "Vote already cast."); round.votes[_voteIDs[i]].choice = _choice; @@ -645,13 +645,13 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { * @return Whether the address can be drawn or not. */ function postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) { - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); (uint256 lockedAmountPerJuror, , , , , ) = core.getRoundInfo( _coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1 ); - (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, subcourtID); - (, , uint256 minStake, , , ) = core.courts(subcourtID); + (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, courtID); + (, , uint256 minStake, , , ) = core.courts(courtID); return stakedTokens >= lockedTokens + lockedAmountPerJuror && stakedTokens >= minStake; } diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol index 03a7e63d6..d845d92fa 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol @@ -251,8 +251,8 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]]; Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - bytes32 key = bytes32(uint256(subcourtID)); // Get the ID of the tree. + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + bytes32 key = bytes32(uint256(courtID)); // Get the ID of the tree. (uint256 K, uint256 nodesLength, ) = core.getSortitionSumTree(key, 0); uint256 treeIndex = 0; @@ -345,8 +345,8 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { require(_choice <= dispute.numberOfChoices, "Choice out of bounds"); Round storage round = dispute.rounds[dispute.rounds.length - 1]; - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); - (, bool hiddenVotes, , , , ) = core.courts(subcourtID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); + (, bool hiddenVotes, , , , ) = core.courts(courtID); // Save the votes. for (uint256 i = 0; i < _voteIDs.length; i++) { @@ -354,7 +354,7 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { require( !hiddenVotes || round.votes[_voteIDs[i]].commit == keccak256(abi.encodePacked(_choice, _justification, _salt)), - "The commit must match the choice in subcourts with hidden votes." + "The commit must match the choice in courts with hidden votes." ); require(!round.votes[_voteIDs[i]].voted, "Vote already cast."); round.votes[_voteIDs[i]].choice = _choice; @@ -671,13 +671,13 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { * @return Whether the address can be drawn or not. */ function postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) { - (uint96 subcourtID, , , , ) = core.disputes(_coreDisputeID); + (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); (uint256 lockedAmountPerJuror, , , , , ) = core.getRoundInfo( _coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1 ); - (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, subcourtID); - (, , uint256 minStake, , , ) = core.courts(subcourtID); + (uint256 stakedTokens, uint256 lockedTokens) = core.getJurorBalance(_juror, courtID); + (, , uint256 minStake, , , ) = core.courts(courtID); if (stakedTokens < lockedTokens + lockedAmountPerJuror || stakedTokens < minStake) { return false; } else { diff --git a/contracts/src/gateway/ForeignGateway.sol b/contracts/src/gateway/ForeignGateway.sol index b4d8caf2c..5d47fea1f 100644 --- a/contracts/src/gateway/ForeignGateway.sol +++ b/contracts/src/gateway/ForeignGateway.sol @@ -43,7 +43,7 @@ contract ForeignGateway is IForeignGateway { address arbitrable ); - event ArbitrationCostModified(uint96 indexed _subcourtID, uint256 _feeForJuror); + event ArbitrationCostModified(uint96 indexed _courtID, uint256 _feeForJuror); // ************************************* // // * Storage * // @@ -53,7 +53,7 @@ contract ForeignGateway is IForeignGateway { uint256 public immutable override senderChainID; address public immutable override senderGateway; uint256 internal localDisputeID = 1; // The disputeID must start from 1 as the KlerosV1 proxy governor depends on this implementation. We now also depend on localDisputeID not ever being zero. - mapping(uint96 => uint256) public feeForJuror; // feeForJuror[subcourtID], it mirrors the value on KlerosCore. + mapping(uint96 => uint256) public feeForJuror; // feeForJuror[courtID], it mirrors the value on KlerosCore. address public governor; IFastBridgeReceiver public fastBridgeReceiver; IFastBridgeReceiver public depreciatedFastbridge; @@ -107,13 +107,13 @@ contract ForeignGateway is IForeignGateway { } /** - * @dev Changes the `feeForJuror` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + * @dev Changes the `feeForJuror` property value of a specified court. + * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { - feeForJuror[_subcourtID] = _feeForJuror; - emit ArbitrationCostModified(_subcourtID, _feeForJuror); + function changeSubcourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + feeForJuror[_courtID] = _feeForJuror; + emit ArbitrationCostModified(_courtID, _feeForJuror); } // ************************************* // @@ -156,8 +156,8 @@ contract ForeignGateway is IForeignGateway { } function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) { - (uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); - cost = feeForJuror[subcourtID] * minJurors; + (uint96 courtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); + cost = feeForJuror[courtID] * minJurors; } /** @@ -206,18 +206,18 @@ contract ForeignGateway is IForeignGateway { function extraDataToSubcourtIDMinJurors( bytes memory _extraData - ) internal view returns (uint96 subcourtID, uint256 minJurors) { + ) internal view returns (uint96 courtID, uint256 minJurors) { // Note that here we ignore DisputeKitID if (_extraData.length >= 64) { assembly { // solium-disable-line security/no-inline-assembly - subcourtID := mload(add(_extraData, 0x20)) + courtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) } - if (feeForJuror[subcourtID] == 0) subcourtID = 0; + if (feeForJuror[courtID] == 0) courtID = 0; if (minJurors == 0) minJurors = MIN_JURORS; } else { - subcourtID = 0; + courtID = 0; minJurors = MIN_JURORS; } } diff --git a/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol b/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol index 096d8c34b..2ded1ad40 100644 --- a/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol +++ b/contracts/src/gateway/single-message/ForeignGatewayOnEthereum.sol @@ -29,7 +29,7 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { // at any point. uint256 internal localDisputeID = 1; - // feeForJuror by subcourtID + // feeForJuror by courtID uint256[] internal feeForJuror; uint256 public chainID; uint256 public homeChainID; @@ -84,12 +84,12 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { } } - /** @dev Changes the `feeForJuror` property value of a specified subcourt. - * @param _subcourtID The ID of the subcourt. + /** @dev Changes the `feeForJuror` property value of a specified court. + * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { - feeForJuror[_subcourtID] = _feeForJuror; + function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + feeForJuror[_courtID] = _feeForJuror; } function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID) { @@ -121,19 +121,15 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { } function arbitrationCost(bytes calldata _extraData) public view returns (uint256 cost) { - (uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); + (uint96 courtID, uint256 minJurors) = extraDataToCourtIDMinJurors(_extraData); - cost = feeForJuror[subcourtID] * minJurors; + cost = feeForJuror[courtID] * minJurors; } /** * Relay the rule call from the home gateway to the arbitrable. */ - function relayRule( - bytes32 _disputeHash, - uint256 _ruling, - address _relayer - ) external onlyFromFastBridge { + function relayRule(bytes32 _disputeHash, uint256 _ruling, address _relayer) external onlyFromFastBridge { DisputeData storage dispute = disputeHashtoDisputeData[_disputeHash]; require(dispute.id != 0, "Dispute does not exist"); @@ -160,22 +156,20 @@ contract ForeignGatewayOnEthereum is IForeignGatewaySingleMessage { return disputeHashtoDisputeData[_disputeHash].id; } - function extraDataToSubcourtIDMinJurors(bytes memory _extraData) - internal - view - returns (uint96 subcourtID, uint256 minJurors) - { + function extraDataToCourtIDMinJurors( + bytes memory _extraData + ) internal view returns (uint96 courtID, uint256 minJurors) { // Note that here we ignore DisputeKitID if (_extraData.length >= 64) { assembly { // solium-disable-line security/no-inline-assembly - subcourtID := mload(add(_extraData, 0x20)) + courtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) } - if (subcourtID >= feeForJuror.length) subcourtID = 0; + if (courtID >= feeForJuror.length) courtID = 0; if (minJurors == 0) minJurors = MIN_JURORS; } else { - subcourtID = 0; + courtID = 0; minJurors = MIN_JURORS; } } diff --git a/contracts/test/arbitration/index.ts b/contracts/test/arbitration/index.ts index bf1ffe762..4d1ffdbb6 100644 --- a/contracts/test/arbitration/index.ts +++ b/contracts/test/arbitration/index.ts @@ -27,9 +27,9 @@ describe("DisputeKitClassic", async () => { expect(events[0].args._parent).to.equal(0); // Reminder: the Forking court will be added which will break these expectations. - events = await core.queryFilter(core.filters.SubcourtCreated()); + events = await core.queryFilter(core.filters.CourtCreated()); expect(events.length).to.equal(1); - expect(events[0].args._subcourtID).to.equal(1); + expect(events[0].args._courtID).to.equal(1); expect(events[0].args._parent).to.equal(0); expect(events[0].args._hiddenVotes).to.equal(false); expect(events[0].args._minStake).to.equal(200); @@ -47,7 +47,7 @@ describe("DisputeKitClassic", async () => { events = await core.queryFilter(core.filters.DisputeKitEnabled()); expect(events.length).to.equal(1); - expect(events[0].args._subcourtID).to.equal(1); + expect(events[0].args._courtID).to.equal(1); expect(events[0].args._disputeKitID).to.equal(1); expect(events[0].args._enable).to.equal(true); }); diff --git a/contracts/test/arbitration/unstake.ts b/contracts/test/arbitration/unstake.ts index 0cb54205c..d6bd3c882 100644 --- a/contracts/test/arbitration/unstake.ts +++ b/contracts/test/arbitration/unstake.ts @@ -41,13 +41,13 @@ describe("Unstake juror", async () => { it("Unstake inactive juror", async () => { const arbitrationCost = ONE_TENTH_ETH.mul(3); - await core.createSubcourt(1, false, ONE_THOUSAND_PNK, 1000, ONE_TENTH_ETH, 3, [0, 0, 0, 0], 3, [1]); // Parent - general court, Classic dispute kit + await core.createCourt(1, false, ONE_THOUSAND_PNK, 1000, ONE_TENTH_ETH, 3, [0, 0, 0, 0], 3, [1]); // Parent - general court, Classic dispute kit await pnk.approve(core.address, ONE_THOUSAND_PNK.mul(4)); await core.setStake(1, ONE_THOUSAND_PNK.mul(2)); await core.setStake(2, ONE_THOUSAND_PNK.mul(2)); - expect(await core.getJurorSubcourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); + expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); await core.createDispute(2, extraData, { value: arbitrationCost }); @@ -76,10 +76,10 @@ describe("Unstake juror", async () => { await core.passPhase(); // Freezing -> Staking. Change so we don't deal with delayed stakes - expect(await core.getJurorSubcourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); + expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]); await core.execute(0, 0, 1); // 1 iteration should unstake from both courts - expect(await core.getJurorSubcourtIDs(deployer)).to.be.deep.equal([]); + expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([]); }); }); From 2e3508fca7813cee7b3f7a6fe20360ec3549fc2e Mon Sep 17 00:00:00 2001 From: alcercu Date: Mon, 19 Dec 2022 11:06:38 +0100 Subject: [PATCH 3/6] fix(contracts): remove court and subcourt naming inconsistencies --- contracts/src/gateway/ForeignGateway.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/src/gateway/ForeignGateway.sol b/contracts/src/gateway/ForeignGateway.sol index 5d47fea1f..6aaa93145 100644 --- a/contracts/src/gateway/ForeignGateway.sol +++ b/contracts/src/gateway/ForeignGateway.sol @@ -111,7 +111,7 @@ contract ForeignGateway is IForeignGateway { * @param _courtID The ID of the court. * @param _feeForJuror The new value for the `feeForJuror` property value. */ - function changeSubcourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { + function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor { feeForJuror[_courtID] = _feeForJuror; emit ArbitrationCostModified(_courtID, _feeForJuror); } @@ -156,7 +156,7 @@ contract ForeignGateway is IForeignGateway { } function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) { - (uint96 courtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); + (uint96 courtID, uint256 minJurors) = extraDataToCourtIDMinJurors(_extraData); cost = feeForJuror[courtID] * minJurors; } @@ -204,7 +204,7 @@ contract ForeignGateway is IForeignGateway { // * Internal * // // ************************ // - function extraDataToSubcourtIDMinJurors( + function extraDataToCourtIDMinJurors( bytes memory _extraData ) internal view returns (uint96 courtID, uint256 minJurors) { // Note that here we ignore DisputeKitID From fb66c4711a01f9bbec1af3d7d0dde676e39adc66 Mon Sep 17 00:00:00 2001 From: alcercu Date: Mon, 19 Dec 2022 11:15:36 +0100 Subject: [PATCH 4/6] fix(subgraph): court and subcourt naming inconsistency --- subgraph/schema.graphql | 14 ++-- subgraph/src/KlerosCore.ts | 115 ++++++++++++++++----------------- subgraph/src/PolicyRegistry.ts | 2 +- subgraph/subgraph.yaml | 10 +-- 4 files changed, 69 insertions(+), 72 deletions(-) diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 43d8af7a1..9c339bac4 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -18,11 +18,11 @@ type Court @entity { jurorsForCourtJump: BigInt! timesPerPeriod: [BigInt!]! supportedDisputeKits: [DisputeKit!]! - disputes: [Dispute!]! @derivedFrom(field: "subcourtID") + disputes: [Dispute!]! @derivedFrom(field: "courtID") numberDisputes: BigInt! - stakedJurors: [JurorTokensPerSubcourt!]! @derivedFrom(field: "subcourt") + stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court") numberStakedJurors: BigInt! - tokens: [JurorTokensPerSubcourt!]! @derivedFrom(field: "subcourt") + tokens: [JurorTokensPerCourt!]! @derivedFrom(field: "court") stake: BigInt! paidETH: BigInt! paidPNK: BigInt! @@ -30,7 +30,7 @@ type Court @entity { type Juror @entity { id: ID! # Set to address - tokens: [JurorTokensPerSubcourt!]! @derivedFrom(field: "juror") + tokens: [JurorTokensPerCourt!]! @derivedFrom(field: "juror") totalStake: BigInt! shifts: [TokenAndETHShift!]! @derivedFrom(field: "juror") draws: [Draw!]! @derivedFrom(field: "juror") @@ -45,10 +45,10 @@ type TokenAndETHShift @entity { ethAmount: BigInt! } -type JurorTokensPerSubcourt @entity { +type JurorTokensPerCourt @entity { id: ID! # Set to `${juror.id}-${court.id}` juror: Juror! - subcourt: Court! + court: Court! staked: BigInt! locked: BigInt! } @@ -100,7 +100,7 @@ type Draw @entity { type Dispute @entity { id: ID! - subcourtID: Court! + courtID: Court! arbitrated: Bytes! period: Period! ruled: Boolean! diff --git a/subgraph/src/KlerosCore.ts b/subgraph/src/KlerosCore.ts index 25cc42e11..64e1185a3 100644 --- a/subgraph/src/KlerosCore.ts +++ b/subgraph/src/KlerosCore.ts @@ -6,8 +6,8 @@ import { DisputeCreation, DisputeKitCreated, DisputeKitEnabled, - SubcourtCreated, - SubcourtModified, + CourtCreated, + CourtModified, Draw as DrawEvent, NewPeriod, StakeSet, @@ -16,7 +16,7 @@ import { import { Juror, TokenAndETHShift, - JurorTokensPerSubcourt, + JurorTokensPerCourt, Round, Draw, Dispute, @@ -39,38 +39,37 @@ function getPeriodName(index: i32): string { return periodArray.at(index) || "None"; } -export function handleSubcourtCreated(event: SubcourtCreated): void { - const subcourt = new Court(event.params._subcourtID.toString()); - subcourt.hiddenVotes = event.params._hiddenVotes; - subcourt.parent = event.params._parent.toString(); - subcourt.minStake = event.params._minStake; - subcourt.alpha = event.params._alpha; - subcourt.feeForJuror = event.params._feeForJuror; - subcourt.jurorsForCourtJump = event.params._jurorsForCourtJump; - subcourt.timesPerPeriod = event.params._timesPerPeriod; - subcourt.supportedDisputeKits = - event.params._supportedDisputeKits.map((disputeKitID: BigInt) => - disputeKitID.toString() - ); - subcourt.numberDisputes = ZERO; - subcourt.numberStakedJurors = ZERO; - subcourt.stake = ZERO; - subcourt.paidETH = ZERO; - subcourt.paidPNK = ZERO; - subcourt.save(); +export function handleCourtCreated(event: CourtCreated): void { + const court = new Court(event.params._courtID.toString()); + court.hiddenVotes = event.params._hiddenVotes; + court.parent = event.params._parent.toString(); + court.minStake = event.params._minStake; + court.alpha = event.params._alpha; + court.feeForJuror = event.params._feeForJuror; + court.jurorsForCourtJump = event.params._jurorsForCourtJump; + court.timesPerPeriod = event.params._timesPerPeriod; + court.supportedDisputeKits = event.params._supportedDisputeKits.map( + (disputeKitID: BigInt) => disputeKitID.toString() + ); + court.numberDisputes = ZERO; + court.numberStakedJurors = ZERO; + court.stake = ZERO; + court.paidETH = ZERO; + court.paidPNK = ZERO; + court.save(); } -export function handleSubcourtModified(event: SubcourtModified): void { - const court = Court.load(event.params._subcourtID.toString()); +export function handleCourtModified(event: CourtModified): void { + const court = Court.load(event.params._courtID.toString()); if (court) { const contract = KlerosCore.bind(event.address); - const courtContractState = contract.courts(event.params._subcourtID); + const courtContractState = contract.courts(event.params._courtID); court.hiddenVotes = courtContractState.value1; court.minStake = courtContractState.value2; court.alpha = courtContractState.value3; court.feeForJuror = courtContractState.value4; court.jurorsForCourtJump = courtContractState.value5; - court.timesPerPeriod = contract.getTimesPerPeriod(event.params._subcourtID); + court.timesPerPeriod = contract.getTimesPerPeriod(event.params._courtID); court.save(); } } @@ -88,7 +87,7 @@ export function handleDisputeKitCreated(event: DisputeKitCreated): void { } export function handleDisputeKitEnabled(event: DisputeKitEnabled): void { - const court = Court.load(event.params._subcourtID.toString()); + const court = Court.load(event.params._courtID.toString()); if (court) { const isEnable = event.params._enable; const disputeKitID = event.params._disputeKitID.toString(); @@ -123,12 +122,12 @@ export function handleAppealDecision(event: AppealDecision): void { disputeID, BigInt.fromI64(newRoundIndex) ); - const subcourtID = dispute.subcourtID; - const subcourtStorage = contract.courts(BigInt.fromString(subcourtID)); + const courtID = dispute.courtID; + const courtStorage = contract.courts(BigInt.fromString(courtID)); round.dispute = disputeID.toString(); round.tokensAtStakePerJuror = roundInfo.value0; round.totalFeesForJurors = roundInfo.value1; - round.nbVotes = roundInfo.value1.div(subcourtStorage.value4); + round.nbVotes = roundInfo.value1.div(courtStorage.value4); round.totalVoted = BigInt.fromI32(0); round.repartitions = roundInfo.value2; round.penalties = roundInfo.value3; @@ -144,10 +143,10 @@ export function handleDisputeCreation(event: DisputeCreation): void { const disputeID = event.params._disputeID; const dispute = new Dispute(disputeID.toString()); const disputeStorage = contract.disputes(disputeID); - const subcourtID = disputeStorage.value0; - const subcourt = Court.load(subcourtID.toString()); + const courtID = disputeStorage.value0; + const court = Court.load(courtID.toString()); dispute.arbitrated = event.params._arbitrable; - dispute.subcourtID = subcourtID.toString(); + dispute.courtID = courtID.toString(); dispute.period = "Evidence"; dispute.ruled = false; dispute.lastPeriodChange = disputeStorage.value4; @@ -157,13 +156,13 @@ export function handleDisputeCreation(event: DisputeCreation): void { round.dispute = disputeID.toString(); round.tokensAtStakePerJuror = roundInfo.value0; round.totalFeesForJurors = roundInfo.value1; - round.nbVotes = subcourt ? roundInfo.value1.div(subcourt.feeForJuror) : ZERO; + round.nbVotes = court ? roundInfo.value1.div(court.feeForJuror) : ZERO; round.totalVoted = BigInt.fromI32(0); round.repartitions = roundInfo.value2; round.penalties = roundInfo.value3; round.disputeKitID = roundInfo.value5.toString(); - if (subcourt) { - subcourt.numberDisputes = subcourt.numberDisputes.plus(BigInt.fromI32(1)); + if (court) { + court.numberDisputes = court.numberDisputes.plus(BigInt.fromI32(1)); } dispute.save(); round.save(); @@ -181,19 +180,17 @@ export function handleNewPeriod(event: NewPeriod): void { function updateJurorStake( jurorAddress: string, - subcourtID: string, + courtID: string, contract: KlerosCore, timestamp: BigInt ): void { const juror = Juror.load(jurorAddress); - const subcourt = Court.load(subcourtID); - const jurorTokens = JurorTokensPerSubcourt.load( - `${jurorAddress}-${subcourtID}` - ); - if (juror && subcourt && jurorTokens) { + const court = Court.load(courtID); + const jurorTokens = JurorTokensPerCourt.load(`${jurorAddress}-${courtID}`); + if (juror && court && jurorTokens) { const jurorBalance = contract.getJurorBalance( Address.fromString(jurorAddress), - BigInt.fromString(subcourtID) + BigInt.fromString(courtID) ); const previousStake = jurorTokens.staked; jurorTokens.staked = jurorBalance.value0; @@ -202,7 +199,7 @@ function updateJurorStake( const stakeDelta = jurorTokens.staked.minus(previousStake); const previousTotalStake = juror.totalStake; juror.totalStake = juror.totalStake.plus(stakeDelta); - subcourt.stake = subcourt.stake.plus(stakeDelta); + court.stake = court.stake.plus(stakeDelta); let activeJurorsDelta: BigInt; let numberStakedJurorsDelta: BigInt; if (previousTotalStake.equals(ZERO)) { @@ -215,12 +212,12 @@ function updateJurorStake( activeJurorsDelta = ZERO; numberStakedJurorsDelta = ZERO; } - subcourt.numberStakedJurors = subcourt.numberStakedJurors.plus( + court.numberStakedJurors = court.numberStakedJurors.plus( numberStakedJurorsDelta ); updateActiveJurors(activeJurorsDelta, timestamp); juror.save(); - subcourt.save(); + court.save(); } } @@ -241,7 +238,7 @@ export function handleDraw(event: DrawEvent): void { const contract = KlerosCore.bind(event.address); updateJurorStake( drawnAddress.toHexString(), - dispute.subcourtID.toString(), + dispute.courtID.toString(), contract, event.block.timestamp ); @@ -256,14 +253,14 @@ export function handleStakeSet(event: StakeSet): void { updateActiveJurors(BigInt.fromI32(1), event.block.timestamp); } juror.save(); - const subcourtID = event.params._subcourtID; - const jurorTokensID = `${jurorAddress}-${subcourtID.toString()}`; - let jurorTokens = JurorTokensPerSubcourt.load(jurorTokensID); + const courtID = event.params._courtID; + const jurorTokensID = `${jurorAddress}-${courtID.toString()}`; + let jurorTokens = JurorTokensPerCourt.load(jurorTokensID); let previousStake: BigInt; if (!jurorTokens) { - jurorTokens = new JurorTokensPerSubcourt(jurorTokensID); + jurorTokens = new JurorTokensPerCourt(jurorTokensID); jurorTokens.juror = jurorAddress; - jurorTokens.subcourt = subcourtID.toString(); + jurorTokens.court = courtID.toString(); jurorTokens.staked = ZERO; jurorTokens.locked = ZERO; jurorTokens.save(); @@ -271,7 +268,7 @@ export function handleStakeSet(event: StakeSet): void { } else previousStake = jurorTokens.staked; updateJurorStake( jurorAddress, - subcourtID.toString(), + courtID.toString(), KlerosCore.bind(event.address), event.block.timestamp ); @@ -297,17 +294,17 @@ export function handleTokenAndETHShift(event: TokenAndETHShiftEvent): void { shift.save(); const dispute = Dispute.load(disputeID.toString()); if (dispute) { - const subcourt = Court.load(dispute.subcourtID.toString()); - if (subcourt) { + const court = Court.load(dispute.courtID.toString()); + if (court) { updateJurorStake( jurorAddress, - subcourt.id, + court.id, KlerosCore.bind(event.address), event.block.timestamp ); - subcourt.paidETH = subcourt.paidETH.plus(ethAmount); - subcourt.paidPNK = subcourt.paidETH.plus(tokenAmount); - subcourt.save(); + court.paidETH = court.paidETH.plus(ethAmount); + court.paidPNK = court.paidETH.plus(tokenAmount); + court.save(); } } } diff --git a/subgraph/src/PolicyRegistry.ts b/subgraph/src/PolicyRegistry.ts index 177ba9919..d1b65be21 100644 --- a/subgraph/src/PolicyRegistry.ts +++ b/subgraph/src/PolicyRegistry.ts @@ -2,7 +2,7 @@ import { PolicyUpdate } from "../generated/PolicyRegistry/PolicyRegistry"; import { Court } from "../generated/schema"; export function handlePolicyUpdate(event: PolicyUpdate): void { - const courtID = event.params._subcourtID.toString(); + const courtID = event.params._courtID.toString(); const court = Court.load(courtID); if (court) { court.policy = event.params._policy; diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index 0c00722cf..5e78d85ae 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -17,7 +17,7 @@ dataSources: - Court - Juror - TokenAndETHShift - - JurorTokensPerSubcourt + - JurorTokensPerCourt - Round - Draw - Dispute @@ -39,10 +39,10 @@ dataSources: handler: handleDraw - event: NewPeriod(indexed uint256,uint8) handler: handleNewPeriod - - event: SubcourtCreated(indexed uint256,indexed uint96,bool,uint256,uint256,uint256,uint256,uint256[4],uint256,uint256[]) - handler: handleSubcourtCreated - - event: SubcourtModified(indexed uint96,string) - handler: handleSubcourtModified + - event: CourtCreated(indexed uint256,indexed uint96,bool,uint256,uint256,uint256,uint256,uint256[4],uint256,uint256[]) + handler: handleCourtCreated + - event: CourtModified(indexed uint96,string) + handler: handleCourtModified - event: DisputeKitCreated(indexed uint256,indexed address,indexed uint256) handler: handleDisputeKitCreated - event: DisputeKitEnabled(indexed uint96,indexed uint256,indexed bool) From 67211c4f46330a2fc4c1a71b0c16391abbb3d1e8 Mon Sep 17 00:00:00 2001 From: alcercu Date: Mon, 19 Dec 2022 11:21:55 +0100 Subject: [PATCH 5/6] fix(web): court and subcourt naming inconsistency --- web/src/components/DisputeCard/index.tsx | 8 ++++---- web/src/hooks/queries/useCasesQuery.ts | 2 +- web/src/hooks/queries/useDisputeDetailsQuery.ts | 2 +- web/src/pages/Cases/CaseDetails/Overview.tsx | 6 ++---- web/src/pages/Cases/CaseDetails/Timeline.tsx | 6 ++---- web/src/pages/Cases/CaseDetails/index.tsx | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/web/src/components/DisputeCard/index.tsx b/web/src/components/DisputeCard/index.tsx index 4cb47bfc6..5d0cfd234 100644 --- a/web/src/components/DisputeCard/index.tsx +++ b/web/src/components/DisputeCard/index.tsx @@ -44,21 +44,21 @@ const DisputeCard: React.FC = ({ arbitrated, period, lastPeriodChange, - subcourtID, + courtID, }) => { const currentPeriodIndex = Periods[period]; - const rewards = `≥ ${utils.formatEther(subcourtID.feeForJuror)} ETH`; + const rewards = `≥ ${utils.formatEther(courtID.feeForJuror)} ETH`; const date = currentPeriodIndex === 4 ? lastPeriodChange : getTimeLeft( lastPeriodChange, currentPeriodIndex, - subcourtID.timesPerPeriod + courtID.timesPerPeriod ); const { data: metaEvidence } = useGetMetaEvidence(id, arbitrated); const title = metaEvidence ? metaEvidence.title : ; - const { data: courtPolicyPath } = useCourtPolicy(parseInt(subcourtID.id)); + const { data: courtPolicyPath } = useCourtPolicy(parseInt(courtID.id)); const { data: courtPolicy } = useIPFSQuery(courtPolicyPath?.args._policy); const courtName = courtPolicy?.name; const category = metaEvidence ? metaEvidence.category : undefined; diff --git a/web/src/hooks/queries/useCasesQuery.ts b/web/src/hooks/queries/useCasesQuery.ts index bcd2970e3..81e779584 100644 --- a/web/src/hooks/queries/useCasesQuery.ts +++ b/web/src/hooks/queries/useCasesQuery.ts @@ -13,7 +13,7 @@ const casesQuery = gql` ) { id arbitrated - subcourtID { + courtID { id policy feeForJuror diff --git a/web/src/hooks/queries/useDisputeDetailsQuery.ts b/web/src/hooks/queries/useDisputeDetailsQuery.ts index 8a05245b6..779378ebc 100644 --- a/web/src/hooks/queries/useDisputeDetailsQuery.ts +++ b/web/src/hooks/queries/useDisputeDetailsQuery.ts @@ -6,7 +6,7 @@ export type { DisputeDetailsQuery }; const disputeDetailsQuery = gql` query DisputeDetails($disputeID: ID!) { dispute(id: $disputeID) { - subcourtID { + courtID { id timesPerPeriod hiddenVotes diff --git a/web/src/pages/Cases/CaseDetails/Overview.tsx b/web/src/pages/Cases/CaseDetails/Overview.tsx index 58d2f56e4..3045053ad 100644 --- a/web/src/pages/Cases/CaseDetails/Overview.tsx +++ b/web/src/pages/Cases/CaseDetails/Overview.tsx @@ -24,10 +24,8 @@ const Overview: React.FC<{ arbitrable: string; courtID?: string }> = ({ const courtPolicyPath = courtPolicyEvent?.args._policy; const { data: courtPolicy } = useIPFSQuery(courtPolicyPath); const courtName = courtPolicy?.name; - const rewards = disputeDetails?.dispute?.subcourtID - ? `≥ ${utils.formatEther( - disputeDetails?.dispute?.subcourtID.feeForJuror - )} ETH` + const rewards = disputeDetails?.dispute?.courtID + ? `≥ ${utils.formatEther(disputeDetails?.dispute?.courtID.feeForJuror)} ETH` : undefined; const category = metaEvidence ? metaEvidence.category : undefined; return ( diff --git a/web/src/pages/Cases/CaseDetails/Timeline.tsx b/web/src/pages/Cases/CaseDetails/Timeline.tsx index 6662215f6..bec16615a 100644 --- a/web/src/pages/Cases/CaseDetails/Timeline.tsx +++ b/web/src/pages/Cases/CaseDetails/Timeline.tsx @@ -52,16 +52,14 @@ const getTimeline = ( secondsToDayHourMinute( getTimeLeft( parseInt(dispute?.lastPeriodChange, 10), - parseInt(dispute?.subcourtID.timesPerPeriod[index], 10) + parseInt(dispute?.courtID.timesPerPeriod[index], 10) ) ), ]; } else if (index === 3) { return []; } else { - return [ - secondsToDayHourMinute(dispute?.subcourtID.timesPerPeriod[index]), - ]; + return [secondsToDayHourMinute(dispute?.courtID.timesPerPeriod[index])]; } }; return titles.map((title, i) => ({ diff --git a/web/src/pages/Cases/CaseDetails/index.tsx b/web/src/pages/Cases/CaseDetails/index.tsx index 315e85034..e08b9ea12 100644 --- a/web/src/pages/Cases/CaseDetails/index.tsx +++ b/web/src/pages/Cases/CaseDetails/index.tsx @@ -27,7 +27,7 @@ const CaseDetails: React.FC = () => { element={ } /> From 74cc162cd4da0a5324e875584a63f8bc22bd00de Mon Sep 17 00:00:00 2001 From: jaybuidl Date: Mon, 19 Dec 2022 12:51:37 +0000 Subject: [PATCH 6/6] fix: deploy script --- contracts/deploy/01-foreign-gateway.ts | 2 +- contracts/deploy/03-vea-mock.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/deploy/01-foreign-gateway.ts b/contracts/deploy/01-foreign-gateway.ts index cb1c9f06f..a10f8b850 100644 --- a/contracts/deploy/01-foreign-gateway.ts +++ b/contracts/deploy/01-foreign-gateway.ts @@ -46,7 +46,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme await execute( "ForeignGatewayOnEthereum", { from: deployer, log: true }, - "changeSubcourtJurorFee", + "changeCourtJurorFee", 0, ethers.BigNumber.from(10).pow(17) ); diff --git a/contracts/deploy/03-vea-mock.ts b/contracts/deploy/03-vea-mock.ts index 557a5a9fd..82cf44030 100644 --- a/contracts/deploy/03-vea-mock.ts +++ b/contracts/deploy/03-vea-mock.ts @@ -47,7 +47,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) await execute( "ForeignGatewayOnEthereum", { from: deployer, log: true }, - "changeSubcourtJurorFee", + "changeCourtJurorFee", 0, ethers.BigNumber.from(10).pow(17) );