Skip to content

Commit

Permalink
Merge pull request #282 from corydickson/first-batch-vo
Browse files Browse the repository at this point in the history
Add is zero to initial vote tally credits
  • Loading branch information
corydickson authored Sep 20, 2021
2 parents 4bc217d + 61d45ed commit 4892ada
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions circuits/circom/tallyVotes.circom
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ template TallyVotes(

// Tally the new total of spent voice credits
component newSpentVoiceCreditSubtotal = CalculateTotal(batchSize * numVoteOptions + 1);
newSpentVoiceCreditSubtotal.nums[batchSize * numVoteOptions] <== currentSpentVoiceCreditSubtotal;
newSpentVoiceCreditSubtotal.nums[batchSize * numVoteOptions] <== currentSpentVoiceCreditSubtotal * iz.out;
for (var i = 0; i < batchSize; i ++) {
for (var j = 0; j < numVoteOptions; j ++) {
newSpentVoiceCreditSubtotal.nums[i * numVoteOptions + j] <==
Expand All @@ -163,7 +163,7 @@ template TallyVotes(
component newPerVOSpentVoiceCredits[numVoteOptions];
for (var i = 0; i < numVoteOptions; i ++) {
newPerVOSpentVoiceCredits[i] = CalculateTotal(batchSize + 1);
newPerVOSpentVoiceCredits[i].nums[batchSize] <== currentPerVOSpentVoiceCredits[i];
newPerVOSpentVoiceCredits[i].nums[batchSize] <== currentPerVOSpentVoiceCredits[i] * iz.out;
for (var j = 0; j < batchSize; j ++) {
newPerVOSpentVoiceCredits[i].nums[j] <== votes[j][i] * votes[j][i];
}
Expand Down
10 changes: 10 additions & 0 deletions circuits/ts/__tests__/TallyVotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ describe('TallyVotes circuit', () => {

for (let i = 0; i < NUM_BATCHES; i ++) {
const generatedInputs = poll.tallyVotes()

// For the 0th batch, the circuit should ignore currentResults,
// currentSpentVoiceCreditSubtotal, and
// currentPerVOSpentVoiceCredits
if (i === 0) {
generatedInputs.currentResults[0] = '123'
generatedInputs.currentSpentVoiceCreditSubtotal = '456'
generatedInputs.currentPerVOSpentVoiceCredits[0] = '789'
}

const witness = await genWitness(circuit, generatedInputs)
expect(witness.length > 0).toBeTruthy()
}
Expand Down

0 comments on commit 4892ada

Please sign in to comment.