Skip to content

Commit 0c152e3

Browse files
authored
Merge pull request #681 from privacy-ethereum/fix/add-tally-results
fix(contracts): subtract previous vote square value from total
2 parents ca078b7 + 3ebf814 commit 0c152e3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/contracts/contracts/maci/Tally.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ contract Tally is TallyBase, IPayoutStrategy {
150150
if (amount == 0) {
151151
revert DepositMustBeGreaterThanZero();
152152
}
153+
153154
emit Deposited(msg.sender, amount);
154155

155156
token.safeTransferFrom(msg.sender, address(this), amount);
@@ -194,6 +195,10 @@ contract Tally is TallyBase, IPayoutStrategy {
194195
uint256 perVOSpentVoiceCreditsHash,
195196
uint8 voteOptionTreeDepth
196197
) internal override {
198+
uint256 previousValue = tallyResults[voteOptionIndex].value;
199+
200+
totalVotesSquares += tallyResult ** 2 - previousValue ** 2;
201+
197202
super.addTallyResult(
198203
voteOptionIndex,
199204
tallyResult,
@@ -204,8 +209,6 @@ contract Tally is TallyBase, IPayoutStrategy {
204209
voteOptionTreeDepth
205210
);
206211

207-
totalVotesSquares += tallyResult ** 2;
208-
209212
emit ResultAdded(voteOptionIndex, tallyResult);
210213
}
211214

0 commit comments

Comments
 (0)