@@ -140,7 +140,15 @@ contract KlerosCore is IArbitrator {
140
140
uint256 [4 ] _timesPerPeriod ,
141
141
uint256 [] _supportedDisputeKits
142
142
);
143
- event CourtModified (uint96 indexed _courtID , string _param );
143
+ event CourtModified (
144
+ uint96 indexed _courtID ,
145
+ bool _hiddenVotes ,
146
+ uint256 _minStake ,
147
+ uint256 _alpha ,
148
+ uint256 _feeForJuror ,
149
+ uint256 _jurorsForCourtJump ,
150
+ uint256 [4 ] _timesPerPeriod
151
+ );
144
152
event DisputeKitCreated (
145
153
uint256 indexed _disputeKitID ,
146
154
IDisputeKit indexed _disputeKitAddress ,
@@ -181,7 +189,7 @@ contract KlerosCore is IArbitrator {
181
189
// ************************************* //
182
190
183
191
modifier onlyByGovernor () {
184
- require (governor == msg .sender , " Governor only " );
192
+ if (governor != msg .sender ) revert GovernorOnly ( );
185
193
_;
186
194
}
187
195
@@ -272,7 +280,7 @@ contract KlerosCore is IArbitrator {
272
280
bytes memory _data
273
281
) external onlyByGovernor {
274
282
(bool success , ) = _destination.call {value: _amount}(_data);
275
- require ( success, " Unsuccessful call " );
283
+ if ( ! success) revert UnsuccessfulCall ( );
276
284
}
277
285
278
286
/// @dev Changes the `governor` storage variable.
@@ -306,12 +314,12 @@ contract KlerosCore is IArbitrator {
306
314
/// Note that the root DK must be supported by the general court.
307
315
function addNewDisputeKit (IDisputeKit _disputeKitAddress , uint256 _parent ) external onlyByGovernor {
308
316
uint256 disputeKitID = disputeKitNodes.length ;
309
- require (_parent < disputeKitID, " !Parent " );
317
+ if (_parent >= disputeKitID) revert InvalidDisputKitParent ( );
310
318
uint256 depthLevel;
311
319
if (_parent != NULL_DISPUTE_KIT) {
312
320
depthLevel = disputeKitNodes[_parent].depthLevel + 1 ;
313
321
// It should be always possible to reach the root from the leaf with the defined number of search iterations.
314
- require (depthLevel < SEARCH_ITERATIONS, " Depth level max " );
322
+ if (depthLevel >= SEARCH_ITERATIONS) revert DepthLevelMax ( );
315
323
}
316
324
disputeKitNodes.push (
317
325
DisputeKitNode ({
@@ -352,18 +360,17 @@ contract KlerosCore is IArbitrator {
352
360
bytes memory _sortitionExtraData ,
353
361
uint256 [] memory _supportedDisputeKits
354
362
) external onlyByGovernor {
355
- require (courts[_parent].minStake <= _minStake, " MinStake lower than parent court " );
356
- require (_supportedDisputeKits.length > 0 , " !Supported DK " );
357
- require (_parent != FORKING_COURT, " Invalid: Forking court as parent " );
363
+ if (courts[_parent].minStake > _minStake) revert MinStakeLowerThanParentCourt ( );
364
+ if (_supportedDisputeKits.length == 0 ) revert UnsupportedDisputeKit ( );
365
+ if (_parent == FORKING_COURT) revert InvalidForkingCourtAsParent ( );
358
366
359
367
uint256 courtID = courts.length ;
360
368
Court storage court = courts.push ();
361
369
362
370
for (uint256 i = 0 ; i < _supportedDisputeKits.length ; i++ ) {
363
- require (
364
- _supportedDisputeKits[i] > 0 && _supportedDisputeKits[i] < disputeKitNodes.length ,
365
- "Wrong DK index "
366
- );
371
+ if (_supportedDisputeKits[i] == 0 || _supportedDisputeKits[i] >= disputeKitNodes.length ) {
372
+ revert WrongDisputeKitIndex ();
373
+ }
367
374
court.supportedDisputeKits[_supportedDisputeKits[i]] = true ;
368
375
}
369
376
@@ -393,60 +400,39 @@ contract KlerosCore is IArbitrator {
393
400
);
394
401
}
395
402
396
- /// @dev Changes the `minStake` property value of a specified court. Don't set to a value lower than its parent's `minStake` property value.
397
- /// @param _courtID The ID of the court.
398
- /// @param _minStake The new value for the `minStake` property value.
399
- function changeCourtMinStake (uint96 _courtID , uint256 _minStake ) external onlyByGovernor {
400
- require (
401
- _courtID == GENERAL_COURT || courts[courts[_courtID].parent].minStake <= _minStake,
402
- "MinStake lower than parent court "
403
- );
403
+ function changeCourtParameters (
404
+ uint96 _courtID ,
405
+ bool _hiddenVotes ,
406
+ uint256 _minStake ,
407
+ uint256 _alpha ,
408
+ uint256 _feeForJuror ,
409
+ uint256 _jurorsForCourtJump ,
410
+ uint256 [4 ] memory _timesPerPeriod
411
+ ) external onlyByGovernor {
412
+ Court storage court = courts[_courtID];
413
+ if (_courtID != GENERAL_COURT && courts[courts[_courtID].parent].minStake > _minStake) {
414
+ revert MinStakeLowerThanParentCourt ();
415
+ }
404
416
for (uint256 i = 0 ; i < courts[_courtID].children.length ; i++ ) {
405
- require (courts[courts[_courtID].children[i]].minStake >= _minStake, "MinStake lower than parent court " );
417
+ if (courts[courts[_courtID].children[i]].minStake < _minStake) {
418
+ revert MinStakeLowerThanParentCourt ();
419
+ }
406
420
}
407
-
408
421
courts[_courtID].minStake = _minStake;
409
- emit CourtModified (_courtID, "minStake " );
410
- }
411
-
412
- /// @dev Changes the `alpha` property value of a specified court.
413
- /// @param _courtID The ID of the court.
414
- /// @param _alpha The new value for the `alpha` property value.
415
- function changeCourtAlpha (uint96 _courtID , uint256 _alpha ) external onlyByGovernor {
422
+ courts[_courtID].hiddenVotes = _hiddenVotes;
416
423
courts[_courtID].alpha = _alpha;
417
- emit CourtModified (_courtID, "alpha " );
418
- }
419
-
420
- /// @dev Changes the `feeForJuror` property value of a specified court.
421
- /// @param _courtID The ID of the court.
422
- /// @param _feeForJuror The new value for the `feeForJuror` property value.
423
- function changeCourtJurorFee (uint96 _courtID , uint256 _feeForJuror ) external onlyByGovernor {
424
424
courts[_courtID].feeForJuror = _feeForJuror;
425
- emit CourtModified (_courtID, "feeForJuror " );
426
- }
427
-
428
- /// @dev Changes the `jurorsForCourtJump` property value of a specified court.
429
- /// @param _courtID The ID of the court.
430
- /// @param _jurorsForCourtJump The new value for the `jurorsForCourtJump` property value.
431
- function changeCourtJurorsForJump (uint96 _courtID , uint256 _jurorsForCourtJump ) external onlyByGovernor {
432
425
courts[_courtID].jurorsForCourtJump = _jurorsForCourtJump;
433
- emit CourtModified (_courtID, "jurorsForCourtJump " );
434
- }
435
-
436
- /// @dev Changes the `hiddenVotes` property value of a specified court.
437
- /// @param _courtID The ID of the court.
438
- /// @param _hiddenVotes The new value for the `hiddenVotes` property value.
439
- function changeCourtHiddenVotes (uint96 _courtID , bool _hiddenVotes ) external onlyByGovernor {
440
- courts[_courtID].hiddenVotes = _hiddenVotes;
441
- emit CourtModified (_courtID, "hiddenVotes " );
442
- }
443
-
444
- /// @dev Changes the `timesPerPeriod` property value of a specified court.
445
- /// @param _courtID The ID of the court.
446
- /// @param _timesPerPeriod The new value for the `timesPerPeriod` property value.
447
- function changeCourtTimesPerPeriod (uint96 _courtID , uint256 [4 ] memory _timesPerPeriod ) external onlyByGovernor {
448
426
courts[_courtID].timesPerPeriod = _timesPerPeriod;
449
- emit CourtModified (_courtID, "timesPerPeriod " );
427
+ emit CourtModified (
428
+ _courtID,
429
+ _hiddenVotes,
430
+ _minStake,
431
+ _alpha,
432
+ _feeForJuror,
433
+ _jurorsForCourtJump,
434
+ _timesPerPeriod
435
+ );
450
436
}
451
437
452
438
/// @dev Adds/removes court's support for specified dispute kits.
@@ -456,13 +442,14 @@ contract KlerosCore is IArbitrator {
456
442
function enableDisputeKits (uint96 _courtID , uint256 [] memory _disputeKitIDs , bool _enable ) external onlyByGovernor {
457
443
for (uint256 i = 0 ; i < _disputeKitIDs.length ; i++ ) {
458
444
if (_enable) {
459
- require (_disputeKitIDs[i] > 0 && _disputeKitIDs[i] < disputeKitNodes.length , "Wrong DK index " );
445
+ if (_disputeKitIDs[i] == 0 || _disputeKitIDs[i] >= disputeKitNodes.length ) {
446
+ revert WrongDisputeKitIndex ();
447
+ }
460
448
_enableDisputeKit (_courtID, _disputeKitIDs[i], true );
461
449
} else {
462
- require (
463
- ! (_courtID == GENERAL_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT),
464
- "Can't disable Root DK in General "
465
- );
450
+ if (_courtID == GENERAL_COURT && disputeKitNodes[_disputeKitIDs[i]].parent == NULL_DISPUTE_KIT) {
451
+ revert CannotDisableRootDKInGeneral ();
452
+ }
466
453
_enableDisputeKit (_courtID, _disputeKitIDs[i], false );
467
454
}
468
455
}
@@ -472,7 +459,7 @@ contract KlerosCore is IArbitrator {
472
459
/// @param _feeTokens The new value for the `supportedFeeTokens` storage variable.
473
460
/// @param _accepted Whether the token is supported or not as a method of fee payment.
474
461
function changeAcceptedFeeTokens (IERC20 [] calldata _feeTokens , bool [] calldata _accepted ) external onlyByGovernor {
475
- require (_feeTokens.length == _accepted.length , " Arrays length mismatch " );
462
+ if (_feeTokens.length != _accepted.length ) revert ArraysLengthMismatch ( );
476
463
for (uint256 i = 0 ; i < _feeTokens.length ; i++ ) {
477
464
currencyRates[address (_feeTokens[i])].feePaymentAccepted = _accepted[i];
478
465
emit AcceptedFeeToken (address (_feeTokens[i]), _accepted[i]);
@@ -484,8 +471,8 @@ contract KlerosCore is IArbitrator {
484
471
uint64 [] calldata _rateInEth ,
485
472
uint8 [] calldata _rateDecimals
486
473
) external onlyByGovernor {
487
- require (_feeTokens.length == _rateInEth.length , " Arrays length mismatch " );
488
- require (_feeTokens.length == _rateDecimals.length , " Arrays length mismatch " );
474
+ if (_feeTokens.length != _rateInEth.length ) revert ArraysLengthMismatch ( );
475
+ if (_feeTokens.length != _rateDecimals.length ) revert ArraysLengthMismatch ( );
489
476
for (uint256 i = 0 ; i < _feeTokens.length ; i++ ) {
490
477
CurrencyRate storage rate = currencyRates[address (_feeTokens[i])];
491
478
rate.rateInEth = _rateInEth[i];
@@ -501,11 +488,11 @@ contract KlerosCore is IArbitrator {
501
488
/// @param _courtID The ID of the court.
502
489
/// @param _stake The new stake.
503
490
function setStake (uint96 _courtID , uint256 _stake ) external {
504
- require ( _setStakeForAccount (msg .sender , _courtID, _stake, 0 ), " Staking failed " );
491
+ if ( ! _setStakeForAccount (msg .sender , _courtID, _stake, 0 )) revert StakingFailed ( );
505
492
}
506
493
507
494
function setStakeBySortitionModule (address _account , uint96 _courtID , uint256 _stake , uint256 _penalty ) external {
508
- require (msg .sender == address (sortitionModule), " Wrong caller " );
495
+ if (msg .sender != address (sortitionModule)) revert WrongCaller ( );
509
496
_setStakeForAccount (_account, _courtID, _stake, _penalty);
510
497
}
511
498
@@ -514,10 +501,10 @@ contract KlerosCore is IArbitrator {
514
501
uint256 _numberOfChoices ,
515
502
bytes memory _extraData
516
503
) external payable override returns (uint256 disputeID ) {
517
- require (msg .value >= arbitrationCost (_extraData), " Arbitration fees: not enough " );
504
+ if (msg .value < arbitrationCost (_extraData)) revert ArbitrationFeesNotEnough ( );
518
505
519
506
(uint96 courtID , , uint256 disputeKitID ) = _extraDataToCourtIDMinJurorsDisputeKit (_extraData);
520
- require ( courts[courtID].supportedDisputeKits[disputeKitID], " DK unsupported by court " );
507
+ if ( ! courts[courtID].supportedDisputeKits[disputeKitID]) revert DisputeKitNotSupportedByCourt ( );
521
508
522
509
disputeID = disputes.length ;
523
510
Dispute storage dispute = disputes.push ();
@@ -546,14 +533,12 @@ contract KlerosCore is IArbitrator {
546
533
address _feeToken ,
547
534
uint256 _feeAmount
548
535
) external override returns (uint256 disputeID ) {
549
- require (currencyRates[_feeToken].feePaymentAccepted, "Token not accepted " );
550
- require (
551
- _feeAmount >= convertEthToTokenAmount (_feeToken, arbitrationCost (_extraData)),
552
- "Arbitration fees: not enough "
553
- );
536
+ if (! currencyRates[_feeToken].feePaymentAccepted) revert TokenNotAccepted ();
537
+ if (_feeAmount < convertEthToTokenAmount (_feeToken, arbitrationCost (_extraData)))
538
+ revert ArbitrationFeesNotEnough ();
554
539
555
540
(uint96 courtID , , uint256 disputeKitID ) = _extraDataToCourtIDMinJurorsDisputeKit (_extraData);
556
- require ( courts[courtID].supportedDisputeKits[disputeKitID], " DK unsupported by court " );
541
+ if ( ! courts[courtID].supportedDisputeKits[disputeKitID]) revert DisputeKitNotSupportedByCourt ( );
557
542
558
543
disputeID = disputes.length ;
559
544
Dispute storage dispute = disputes.push ();
@@ -587,36 +572,38 @@ contract KlerosCore is IArbitrator {
587
572
uint256 currentRound = dispute.rounds.length - 1 ;
588
573
Round storage round = dispute.rounds[currentRound];
589
574
if (dispute.period == Period.evidence) {
590
- require (
591
- currentRound > 0 ||
592
- block .timestamp - dispute.lastPeriodChange >= court.timesPerPeriod[uint256 (dispute.period)],
593
- "Evidence not passed && !Appeal "
594
- );
595
- require (round.drawnJurors.length == round.nbVotes, "Dispute still drawing " );
575
+ if (
576
+ currentRound == 0 &&
577
+ block .timestamp - dispute.lastPeriodChange < court.timesPerPeriod[uint256 (dispute.period)]
578
+ ) {
579
+ revert EvidenceNotPassedAndNotAppeal ();
580
+ }
581
+ if (round.drawnJurors.length != round.nbVotes) revert DisputeStillDrawing ();
596
582
dispute.period = court.hiddenVotes ? Period.commit : Period.vote;
597
583
} else if (dispute.period == Period.commit) {
598
- require (
599
- block .timestamp - dispute.lastPeriodChange >= court.timesPerPeriod[uint256 (dispute.period)] ||
600
- disputeKitNodes[round.disputeKitID].disputeKit.areCommitsAllCast (_disputeID),
601
- "Commit period not passed "
602
- );
584
+ if (
585
+ block .timestamp - dispute.lastPeriodChange < court.timesPerPeriod[uint256 (dispute.period)] &&
586
+ ! disputeKitNodes[round.disputeKitID].disputeKit.areCommitsAllCast (_disputeID)
587
+ ) {
588
+ revert CommitPeriodNotPassed ();
589
+ }
603
590
dispute.period = Period.vote;
604
591
} else if (dispute.period == Period.vote) {
605
- require (
606
- block .timestamp - dispute.lastPeriodChange >= court.timesPerPeriod[uint256 (dispute.period)] ||
607
- disputeKitNodes[round.disputeKitID].disputeKit.areVotesAllCast (_disputeID),
608
- "Vote period not passed "
609
- );
592
+ if (
593
+ block .timestamp - dispute.lastPeriodChange < court.timesPerPeriod[uint256 (dispute.period)] &&
594
+ disputeKitNodes[round.disputeKitID].disputeKit.areVotesAllCast (_disputeID)
595
+ ) {
596
+ revert VotePeriodNotPassed ();
597
+ }
610
598
dispute.period = Period.appeal;
611
599
emit AppealPossible (_disputeID, dispute.arbitrated);
612
600
} else if (dispute.period == Period.appeal) {
613
- require (
614
- block .timestamp - dispute.lastPeriodChange >= court.timesPerPeriod[uint256 (dispute.period)],
615
- "Appeal period not passed "
616
- );
601
+ if (block .timestamp - dispute.lastPeriodChange < court.timesPerPeriod[uint256 (dispute.period)]) {
602
+ revert AppealPeriodNotPassed ();
603
+ }
617
604
dispute.period = Period.execution;
618
605
} else if (dispute.period == Period.execution) {
619
- revert ( " Dispute period is final " );
606
+ revert DisputePeriodIsFinal ( );
620
607
}
621
608
622
609
dispute.lastPeriodChange = block .timestamp ;
@@ -630,7 +617,7 @@ contract KlerosCore is IArbitrator {
630
617
Dispute storage dispute = disputes[_disputeID];
631
618
uint256 currentRound = dispute.rounds.length - 1 ;
632
619
Round storage round = dispute.rounds[currentRound];
633
- require (dispute.period == Period.evidence, " !Evidence period " );
620
+ if (dispute.period != Period.evidence) revert NotEvidencePeriod ( );
634
621
635
622
IDisputeKit disputeKit = disputeKitNodes[round.disputeKitID].disputeKit;
636
623
@@ -657,13 +644,13 @@ contract KlerosCore is IArbitrator {
657
644
/// @param _numberOfChoices Number of choices for the dispute. Can be required during court jump.
658
645
/// @param _extraData Extradata for the dispute. Can be required during court jump.
659
646
function appeal (uint256 _disputeID , uint256 _numberOfChoices , bytes memory _extraData ) external payable {
660
- require (msg .value >= appealCost (_disputeID), " ETH too low for appeal cost " );
647
+ if (msg .value < appealCost (_disputeID)) revert AppealFeesNotEnough ( );
661
648
662
649
Dispute storage dispute = disputes[_disputeID];
663
- require (dispute.period == Period.appeal, " Dispute not appealable " );
650
+ if (dispute.period != Period.appeal) revert DisputeNotAppealable ( );
664
651
665
652
Round storage round = dispute.rounds[dispute.rounds.length - 1 ];
666
- require (msg .sender == address (disputeKitNodes[round.disputeKitID].disputeKit), " Dispute Kit only " );
653
+ if (msg .sender != address (disputeKitNodes[round.disputeKitID].disputeKit)) revert DisputeKitOnly ( );
667
654
668
655
uint96 newCourtID = dispute.courtID;
669
656
uint256 newDisputeKitID = round.disputeKitID;
@@ -727,7 +714,7 @@ contract KlerosCore is IArbitrator {
727
714
/// @param _iterations The number of iterations to run.
728
715
function execute (uint256 _disputeID , uint256 _round , uint256 _iterations ) external {
729
716
Dispute storage dispute = disputes[_disputeID];
730
- require (dispute.period == Period.execution, " !Execution period " );
717
+ if (dispute.period != Period.execution) revert NotExecutionPeriod ( );
731
718
732
719
Round storage round = dispute.rounds[_round];
733
720
IDisputeKit disputeKit = disputeKitNodes[round.disputeKitID].disputeKit;
@@ -921,8 +908,8 @@ contract KlerosCore is IArbitrator {
921
908
/// @param _disputeID The ID of the dispute.
922
909
function executeRuling (uint256 _disputeID ) external {
923
910
Dispute storage dispute = disputes[_disputeID];
924
- require (dispute.period == Period.execution, " !Execution period " );
925
- require ( ! dispute.ruled, " Ruling already executed " );
911
+ if (dispute.period != Period.execution) revert NotExecutionPeriod ( );
912
+ if ( dispute.ruled) revert RulingAlreadyExecuted ( );
926
913
927
914
(uint256 winningChoice , , ) = currentRuling (_disputeID);
928
915
dispute.ruled = true ;
@@ -1252,4 +1239,36 @@ contract KlerosCore is IArbitrator {
1252
1239
);
1253
1240
return (success && (data.length == 0 || abi.decode (data, (bool ))));
1254
1241
}
1242
+
1243
+ // ************************************* //
1244
+ // * Errors * //
1245
+ // ************************************* //
1246
+
1247
+ error GovernorOnly ();
1248
+ error UnsuccessfulCall ();
1249
+ error InvalidDisputKitParent ();
1250
+ error DepthLevelMax ();
1251
+ error MinStakeLowerThanParentCourt ();
1252
+ error UnsupportedDisputeKit ();
1253
+ error InvalidForkingCourtAsParent ();
1254
+ error WrongDisputeKitIndex ();
1255
+ error CannotDisableRootDKInGeneral ();
1256
+ error ArraysLengthMismatch ();
1257
+ error StakingFailed ();
1258
+ error WrongCaller ();
1259
+ error ArbitrationFeesNotEnough ();
1260
+ error DisputeKitNotSupportedByCourt ();
1261
+ error TokenNotAccepted ();
1262
+ error EvidenceNotPassedAndNotAppeal ();
1263
+ error DisputeStillDrawing ();
1264
+ error CommitPeriodNotPassed ();
1265
+ error VotePeriodNotPassed ();
1266
+ error AppealPeriodNotPassed ();
1267
+ error NotEvidencePeriod ();
1268
+ error AppealFeesNotEnough ();
1269
+ error DisputeNotAppealable ();
1270
+ error DisputeKitOnly ();
1271
+ error NotExecutionPeriod ();
1272
+ error RulingAlreadyExecuted ();
1273
+ error DisputePeriodIsFinal ();
1255
1274
}
0 commit comments