diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol b/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol index 912155986..464e848d6 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol @@ -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); } diff --git a/contracts/test/foundry/KlerosCore_Voting.t.sol b/contracts/test/foundry/KlerosCore_Voting.t.sol index 41f8e3973..961d0741d 100644 --- a/contracts/test/foundry/KlerosCore_Voting.t.sol +++ b/contracts/test/foundry/KlerosCore_Voting.t.sol @@ -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); @@ -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;