Skip to content

Commit df07fbb

Browse files
fix(DK): allow recommits without changing counter
1 parent 6b74ebc commit df07fbb

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,16 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
274274

275275
Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
276276
Round storage round = dispute.rounds[dispute.rounds.length - 1];
277+
// Introduce a counter so we don't count a re-commited votes.
278+
uint256 commitCount;
277279
for (uint256 i = 0; i < _voteIDs.length; i++) {
278-
if (round.votes[_voteIDs[i]].commit != bytes32(0)) revert AlreadyCommittedThisVote();
279280
if (round.votes[_voteIDs[i]].account != msg.sender) revert JurorHasToOwnTheVote();
281+
if (round.votes[_voteIDs[i]].commit == bytes32(0)) {
282+
commitCount++;
283+
}
280284
round.votes[_voteIDs[i]].commit = _commit;
281285
}
282-
round.totalCommitted += _voteIDs.length;
286+
round.totalCommitted += commitCount;
283287
emit CommitCast(_coreDisputeID, msg.sender, _voteIDs, _commit);
284288
}
285289

@@ -760,5 +764,4 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
760764
error AppealFeeIsAlreadyPaid();
761765
error DisputeNotResolved();
762766
error CoreIsPaused();
763-
error AlreadyCommittedThisVote();
764767
}

contracts/test/foundry/KlerosCore_Voting.t.sol

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ contract KlerosCore_VotingTest is KlerosCore_TestBase {
3535
sortitionModule.passPhase(); // Drawing phase
3636
core.draw(disputeID, DEFAULT_NB_OF_JURORS);
3737

38+
uint256 NO = 0;
3839
uint256 YES = 1;
3940
uint256 salt = 123455678;
4041
uint256[] memory voteIDs = new uint256[](1);
@@ -79,6 +80,16 @@ contract KlerosCore_VotingTest is KlerosCore_TestBase {
7980
(, bytes32 commitStored, , ) = disputeKit.getVoteInfo(0, 0, 0);
8081
assertEq(commitStored, keccak256(abi.encodePacked(YES, salt)), "Incorrect commit");
8182

83+
// Cast again with the same voteID to check that the count doesn't increase.
84+
bytes32 newCommit = keccak256(abi.encodePacked(NO, salt));
85+
vm.prank(staker1);
86+
disputeKit.castCommit(disputeID, voteIDs, newCommit);
87+
88+
(, , , totalCommited, , ) = disputeKit.getRoundInfo(disputeID, 0, 0);
89+
assertEq(totalCommited, 1, "totalCommited should still be 1");
90+
(, commitStored, , ) = disputeKit.getVoteInfo(0, 0, 0);
91+
assertEq(commitStored, keccak256(abi.encodePacked(NO, salt)), "Incorrect commit after recommitting");
92+
8293
voteIDs = new uint256[](2); // Create the leftover votes subset
8394
voteIDs[0] = 1;
8495
voteIDs[1] = 2;
@@ -97,10 +108,6 @@ contract KlerosCore_VotingTest is KlerosCore_TestBase {
97108
assertEq(commitStored, keccak256(abi.encodePacked(YES, salt)), "Incorrect commit");
98109
}
99110

100-
vm.prank(staker1);
101-
vm.expectRevert(DisputeKitClassicBase.AlreadyCommittedThisVote.selector);
102-
disputeKit.castCommit(disputeID, voteIDs, commit);
103-
104111
// Check reveal in the next period
105112
vm.warp(block.timestamp + timesPerPeriod[1]);
106113
core.passPeriod(disputeID);

0 commit comments

Comments
 (0)