Skip to content

Commit 62e4e75

Browse files
unknownunknown1jaybuidl
authored andcommitted
fix(KC): small bug fixes
1 parent 17d7a81 commit 62e4e75

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

contracts/src/arbitration/KlerosCore.sol

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,12 @@ contract KlerosCore is IArbitratorV2 {
767767
address account = round.drawnJurors[_params.repartition];
768768
jurors[account].lockedPnk -= penalty;
769769

770-
// Apply the penalty to the staked PNKs if there ara any.
770+
// Apply the penalty to the staked PNKs.
771771
// Note that lockedPnk will always cover penalty while stakedPnk can become lower after manual unstaking.
772772
if (jurors[account].stakedPnk >= penalty) {
773773
jurors[account].stakedPnk -= penalty;
774+
} else {
775+
jurors[account].stakedPnk = 0;
774776
}
775777
emit TokenAndETHShift(
776778
account,
@@ -1118,6 +1120,8 @@ contract KlerosCore is IArbitratorV2 {
11181120

11191121
if (_stake != 0) {
11201122
if (_stake < courts[_courtID].minStake) return false;
1123+
} else if (currentStake == 0) {
1124+
return false;
11211125
}
11221126

11231127
ISortitionModule.preStakeHookResult result = sortitionModule.preStakeHook(_account, _courtID, _stake);
@@ -1137,14 +1141,13 @@ contract KlerosCore is IArbitratorV2 {
11371141
? _stake - currentStake - previouslyLocked
11381142
: 0;
11391143
if (transferredAmount > 0) {
1140-
if (pinakion.safeTransferFrom(_account, address(this), transferredAmount)) {
1141-
if (currentStake == 0) {
1142-
juror.courtIDs.push(_courtID);
1143-
}
1144-
} else {
1144+
if (!pinakion.safeTransferFrom(_account, address(this), transferredAmount)) {
11451145
return false;
11461146
}
11471147
}
1148+
if (currentStake == 0) {
1149+
juror.courtIDs.push(_courtID);
1150+
}
11481151
} else {
11491152
if (_stake == 0) {
11501153
// Make sure locked tokens always stay in the contract. They can only be released during Execution.
@@ -1156,18 +1159,17 @@ contract KlerosCore is IArbitratorV2 {
11561159
transferredAmount = juror.stakedPnk - juror.lockedPnk;
11571160
}
11581161
if (transferredAmount > 0) {
1159-
if (pinakion.safeTransfer(_account, transferredAmount)) {
1160-
for (uint256 i = juror.courtIDs.length; i > 0; i--) {
1161-
if (juror.courtIDs[i - 1] == _courtID) {
1162-
juror.courtIDs[i - 1] = juror.courtIDs[juror.courtIDs.length - 1];
1163-
juror.courtIDs.pop();
1164-
break;
1165-
}
1166-
}
1167-
} else {
1162+
if (!pinakion.safeTransfer(_account, transferredAmount)) {
11681163
return false;
11691164
}
11701165
}
1166+
for (uint256 i = juror.courtIDs.length; i > 0; i--) {
1167+
if (juror.courtIDs[i - 1] == _courtID) {
1168+
juror.courtIDs[i - 1] = juror.courtIDs[juror.courtIDs.length - 1];
1169+
juror.courtIDs.pop();
1170+
break;
1171+
}
1172+
}
11711173
} else {
11721174
if (juror.stakedPnk >= currentStake - _stake + juror.lockedPnk) {
11731175
// We have enough pnk staked to afford withdrawal while keeping locked tokens.

0 commit comments

Comments
 (0)