Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,16 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi

Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
Round storage round = dispute.rounds[dispute.rounds.length - 1];
// Introduce a counter so we don't count a re-commited votes.
uint256 commitCount;
for (uint256 i = 0; i < _voteIDs.length; i++) {
if (round.votes[_voteIDs[i]].account != msg.sender) revert JurorHasToOwnTheVote();
if (round.votes[_voteIDs[i]].commit == bytes32(0)) {
commitCount++;
}
round.votes[_voteIDs[i]].commit = _commit;
}
round.totalCommitted += _voteIDs.length;
round.totalCommitted += commitCount;
emit CommitCast(_coreDisputeID, msg.sender, _voteIDs, _commit);
}

Expand Down
11 changes: 11 additions & 0 deletions contracts/test/foundry/KlerosCore_Voting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract KlerosCore_VotingTest is KlerosCore_TestBase {
sortitionModule.passPhase(); // Drawing phase
core.draw(disputeID, DEFAULT_NB_OF_JURORS);

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

// Cast again with the same voteID to check that the count doesn't increase.
bytes32 newCommit = keccak256(abi.encodePacked(NO, salt));
vm.prank(staker1);
disputeKit.castCommit(disputeID, voteIDs, newCommit);

(, , , totalCommited, , ) = disputeKit.getRoundInfo(disputeID, 0, 0);
assertEq(totalCommited, 1, "totalCommited should still be 1");
(, commitStored, , ) = disputeKit.getVoteInfo(0, 0, 0);
assertEq(commitStored, keccak256(abi.encodePacked(NO, salt)), "Incorrect commit after recommitting");

voteIDs = new uint256[](2); // Create the leftover votes subset
voteIDs[0] = 1;
voteIDs[1] = 2;
Expand Down
Loading