Skip to content

Commit 06db2d0

Browse files
authored
Merge pull request #2145 from kleros/fix/dk-multiple-commits
fix(DK): multiple commit fix
2 parents 835d45b + 5b35be9 commit 06db2d0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,11 +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++) {
278280
if (round.votes[_voteIDs[i]].account != msg.sender) revert JurorHasToOwnTheVote();
281+
if (round.votes[_voteIDs[i]].commit == bytes32(0)) {
282+
commitCount++;
283+
}
279284
round.votes[_voteIDs[i]].commit = _commit;
280285
}
281-
round.totalCommitted += _voteIDs.length;
286+
round.totalCommitted += commitCount;
282287
emit CommitCast(_coreDisputeID, msg.sender, _voteIDs, _commit);
283288
}
284289

contracts/test/foundry/KlerosCore_Voting.t.sol

Lines changed: 11 additions & 0 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;

0 commit comments

Comments
 (0)