Skip to content

Commit 3a5b98a

Browse files
committed
refactor(KlerosCore): introduced the NULL_DISPUTE_KIT constant
1 parent 7a448b4 commit 3a5b98a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

contracts/src/arbitration/KlerosCore.sol

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ contract KlerosCore is IArbitrator {
8181
// ************************************* //
8282

8383
uint256 public constant FORKING_COURT = 0; // Index of the default court.
84+
uint256 public constant NULL_DISPUTE_KIT = 0; // Null pattern to indicate a top-level DK which has no parent.
8485
uint256 public constant DISPUTE_KIT_CLASSIC_INDEX = 1; // Index of the default DK. 0 index is skipped.
8586
uint256 public constant MAX_STAKE_PATHS = 4; // The maximum number of stake paths a juror can have.
8687
uint256 public constant MIN_JURORS = 3; // The global default minimum number of jurors in a dispute.
@@ -164,8 +165,8 @@ contract KlerosCore is IArbitrator {
164165
pinakion = _pinakion;
165166
jurorProsecutionModule = _jurorProsecutionModule;
166167

167-
// Create an empty element so 0 index is not used.
168-
disputeKitNodes.push();
168+
disputeKitNodes.push(); // NULL_DISPUTE_KIT: an empty element at index 0 to indicate when a node has no parent.
169+
disputeKitNodes.push(DisputeKitNode({parent: 0, disputeKit: _disputeKit}));
169170

170171
// Create the Forking court.
171172
Court storage court = courts.push();
@@ -177,10 +178,8 @@ contract KlerosCore is IArbitrator {
177178
court.feeForJuror = _feeForJuror;
178179
court.jurorsForCourtJump = _jurorsForCourtJump;
179180
court.timesPerPeriod = _timesPerPeriod;
180-
181-
disputeKitNodes.push(DisputeKitNode({parent: 0, disputeKit: _disputeKit}));
182-
183181
court.supportedDisputeKits[DISPUTE_KIT_CLASSIC_INDEX] = true;
182+
184183
sortitionSumTrees.createTree(bytes32(0), _sortitionSumTreeK);
185184
}
186185

@@ -232,7 +231,7 @@ contract KlerosCore is IArbitrator {
232231
require(_parent < disputeKitNodes.length, "Parent doesn't exist");
233232

234233
// Create new tree, which root should be supported by Forking court.
235-
if (_parent == 0) {
234+
if (_parent == NULL_DISPUTE_KIT) {
236235
courts[FORKING_COURT].supportedDisputeKits[disputeKitNodes.length] = true;
237236
}
238237
disputeKitNodes.push(DisputeKitNode({parent: _parent, disputeKit: _disputeKitAddress}));
@@ -249,7 +248,7 @@ contract KlerosCore is IArbitrator {
249248
require(_newParent != _disputeKitID, "Invalid Parent");
250249

251250
// Create new tree, which root should be supported by Forking court.
252-
if (_newParent == 0) {
251+
if (_newParent == NULL_DISPUTE_KIT) {
253252
courts[FORKING_COURT].supportedDisputeKits[_disputeKitID] = true;
254253
}
255254
disputeKitNodes[_disputeKitID].parent = _newParent;
@@ -372,7 +371,7 @@ contract KlerosCore is IArbitrator {
372371
subcourt.supportedDisputeKits[_disputeKitIDs[i]] = true;
373372
} else {
374373
require(
375-
!(_subcourtID == FORKING_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == 0),
374+
!(_subcourtID == FORKING_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT),
376375
"Can't remove root DK support from the forking court"
377376
);
378377
subcourt.supportedDisputeKits[_disputeKitIDs[i]] = false;
@@ -977,9 +976,15 @@ contract KlerosCore is IArbitrator {
977976
minJurors := mload(add(_extraData, 0x40))
978977
disputeKitID := mload(add(_extraData, 0x60))
979978
}
980-
if (subcourtID >= courts.length) subcourtID = uint96(FORKING_COURT);
981-
if (minJurors == 0) minJurors = MIN_JURORS;
982-
if (disputeKitID == 0 || disputeKitID >= disputeKitNodes.length) disputeKitID = DISPUTE_KIT_CLASSIC_INDEX; // 0 index is not used.
979+
if (subcourtID >= courts.length) {
980+
subcourtID = uint96(FORKING_COURT);
981+
}
982+
if (minJurors == 0) {
983+
minJurors = MIN_JURORS;
984+
}
985+
if (disputeKitID == NULL_DISPUTE_KIT || disputeKitID >= disputeKitNodes.length) {
986+
disputeKitID = DISPUTE_KIT_CLASSIC_INDEX; // 0 index is not used.
987+
}
983988
} else {
984989
subcourtID = uint96(FORKING_COURT);
985990
minJurors = MIN_JURORS;

0 commit comments

Comments
 (0)