Skip to content

Commit 119785a

Browse files
committed
refactor: moved the residual rewards handling to a separate function
So that viaIR can be disabled without incurring a "stack too deep" error
1 parent 682a857 commit 119785a

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

contracts/hardhat.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const config: HardhatUserConfig = {
2525
enabled: true,
2626
runs: 100,
2727
},
28-
viaIR: true,
2928
},
3029
},
3130
paths: {

contracts/src/arbitration/KlerosCore.sol

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -745,20 +745,7 @@ contract KlerosCore is IArbitrator {
745745
);
746746

747747
if (i == numberOfVotesInRound * 2 - 1) {
748-
// Due to partial coherence of the jurors there might still be a leftover reward. Send it to governor.
749-
uint256 leftoverReward;
750-
uint256 leftoverTokenReward;
751-
if (round.totalFeesForJurors > round.sumRewardPaid) {
752-
leftoverReward = round.totalFeesForJurors - round.sumRewardPaid;
753-
payable(governor).send(leftoverReward);
754-
}
755-
if (penaltiesInRoundCache > round.sumTokenRewardPaid) {
756-
leftoverTokenReward = penaltiesInRoundCache - round.sumTokenRewardPaid;
757-
_safeTransfer(governor, leftoverTokenReward);
758-
}
759-
if (leftoverReward != 0 || leftoverTokenReward != 0) {
760-
emit LeftoverRewardSent(_disputeID, _round, leftoverTokenReward, leftoverReward);
761-
}
748+
_executeResidualRewards(_disputeID, _round, penaltiesInRoundCache); // distinct function to avoid a "stack too deep error"
762749
}
763750
}
764751
}
@@ -910,6 +897,8 @@ contract KlerosCore is IArbitrator {
910897
// * Public Views for Dispute Kits * //
911898
// ************************************* //
912899

900+
/// @dev Gets the number of votes permitted for the specified dispute in the latest round.
901+
/// @param _disputeID The ID of the dispute.
913902
function getNumberOfVotes(uint256 _disputeID) external view returns (uint256) {
914903
Dispute storage dispute = disputes[_disputeID];
915904
return dispute.rounds[dispute.rounds.length - 1].nbVotes;
@@ -935,10 +924,14 @@ contract KlerosCore is IArbitrator {
935924
return disputeKitNodes.length;
936925
}
937926

927+
/// @dev Gets the dispute kit for a specific `_disputeKitID`.
928+
/// @param _disputeKitID The ID of the dispute kit.
938929
function getDisputeKit(uint256 _disputeKitID) external view returns (IDisputeKit) {
939930
return disputeKitNodes[_disputeKitID].disputeKit;
940931
}
941932

933+
/// @dev Gets the court identifiers where a specific `_juror` has staked.
934+
/// @param _juror The address of the juror.
942935
function getJurorCourtIDs(address _juror) public view returns (uint96[] memory) {
943936
return jurors[_juror].courtIDs;
944937
}
@@ -947,11 +940,37 @@ contract KlerosCore is IArbitrator {
947940
// * Internal * //
948941
// ************************************* //
949942

943+
/// @dev Toggles the dispute kit support for a given court.
944+
/// @param _courtID The ID of the court to toggle the support for.
945+
/// @param _disputeKitID The ID of the dispute kit to toggle the support for.
946+
/// @param _enable Whether to enable or disable the support.
950947
function _enableDisputeKit(uint96 _courtID, uint256 _disputeKitID, bool _enable) internal {
951948
courts[_courtID].supportedDisputeKits[_disputeKitID] = _enable;
952949
emit DisputeKitEnabled(_courtID, _disputeKitID, _enable);
953950
}
954951

952+
/// @dev Sends the residual rewards to the governor. It may happen due to partial coherence of the jurors.
953+
/// @param _disputeID The ID of the dispute.
954+
/// @param _round The round to execute.
955+
/// @param _penaltiesInRound The total penalties in the round.
956+
function _executeResidualRewards(uint256 _disputeID, uint256 _round, uint256 _penaltiesInRound) internal {
957+
Dispute storage dispute = disputes[_disputeID];
958+
Round storage round = dispute.rounds[_round];
959+
uint256 leftoverReward;
960+
uint256 leftoverTokenReward;
961+
if (round.totalFeesForJurors > round.sumRewardPaid) {
962+
leftoverReward = round.totalFeesForJurors - round.sumRewardPaid;
963+
payable(governor).send(leftoverReward);
964+
}
965+
if (_penaltiesInRound > round.sumTokenRewardPaid) {
966+
leftoverTokenReward = _penaltiesInRound - round.sumTokenRewardPaid;
967+
_safeTransfer(governor, leftoverTokenReward);
968+
}
969+
if (leftoverReward != 0 || leftoverTokenReward != 0) {
970+
emit LeftoverRewardSent(_disputeID, _round, leftoverTokenReward, leftoverReward);
971+
}
972+
}
973+
955974
/// @dev Sets the specified juror's stake in a court.
956975
/// `O(n + p * log_k(j))` where
957976
/// `n` is the number of courts the juror has staked in,

0 commit comments

Comments
 (0)