diff --git a/.jscpd.json b/.jscpd.json index d132b8a..8a5e143 100644 --- a/.jscpd.json +++ b/.jscpd.json @@ -14,6 +14,6 @@ "reporters": ["console"], "languages": ["javascript", "typescript"], "gitignore": true, - "failOnDuplication": false + "failOnDuplication": true } \ No newline at end of file diff --git a/README.md b/README.md index f57d2dc..390c77a 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,14 @@ Remember to follow this convention for commit messages: `AG- { expect(coalitionFromContract[0][1]).to.equal( coalition.majorCandidate.candidatesFor, ); - expect(coalitionFromContract[0][2]).to.equal( - coalition.majorCandidate.points, - ); expect(coalitionFromContract[1]).to.deep.equal( coalition.parties.map((p) => p.name), ); diff --git a/election-scripts/create-election.ts b/election-scripts/create-election.ts index 9348a09..5c5b1d9 100644 --- a/election-scripts/create-election.ts +++ b/election-scripts/create-election.ts @@ -92,7 +92,7 @@ export async function main( majorCandidate: { name: coalition1Raw[0][0], candidatesFor: coalition1Raw[0][1] as Candidature, - points: Number(coalition1Raw[0][2]), + points: 0, }, parties: [], }; @@ -100,6 +100,7 @@ export async function main( for (const p of parties) { for (const k of coalition1Raw[1]) { if (k === p.name) { + p.points = 0; coalition1.parties.push(p); } } @@ -120,7 +121,7 @@ export async function main( majorCandidate: { name: coalition2Raw[0][0], candidatesFor: coalition2Raw[0][1] as Candidature, - points: Number(coalition2Raw[0][2]), + points: 0, }, parties: [], }; @@ -128,6 +129,7 @@ export async function main( for (const p of parties) { for (const k of coalition2Raw[1]) { if (k === p.name) { + p.points = 0; coalition2.parties.push(p); } } diff --git a/election-scripts/types.ts b/election-scripts/types.ts index 40730a9..82516c7 100644 --- a/election-scripts/types.ts +++ b/election-scripts/types.ts @@ -33,6 +33,7 @@ export type Candidate = { export type Party = { name: string; + points: number; councilorCandidates: string[]; }; diff --git a/package.json b/package.json index d1acbd1..901b718 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "agora", - "version": "0.7.0", + "version": "0.8.0", "description": "A confidentiality-first electronic voting system", "author": { "name": "nova collective", diff --git a/test/MunicipalityElection.ts b/test/MunicipalityElection.ts index ff51724..79a748a 100644 --- a/test/MunicipalityElection.ts +++ b/test/MunicipalityElection.ts @@ -69,7 +69,6 @@ describe("MunicipalityElection Contract", function () { expect(coalition[0][0]).to.be.equal(majorCandidate); expect(coalition[0][1]).to.be.equal("major"); - expect(coalition[0][2]).to.be.equal(0); expect(coalition[1][0]).to.be.equal(partyName); expect(coalition[1][1]).to.be.equal(partyNameB); }); diff --git a/zokrates/example/abi.json b/zkProtocols/example/abi.json similarity index 100% rename from zokrates/example/abi.json rename to zkProtocols/example/abi.json diff --git a/zokrates/example/out b/zkProtocols/example/out similarity index 100% rename from zokrates/example/out rename to zkProtocols/example/out diff --git a/zokrates/example/out.r1cs b/zkProtocols/example/out.r1cs similarity index 100% rename from zokrates/example/out.r1cs rename to zkProtocols/example/out.r1cs diff --git a/zokrates/example/out.wtns b/zkProtocols/example/out.wtns similarity index 100% rename from zokrates/example/out.wtns rename to zkProtocols/example/out.wtns diff --git a/zokrates/example/proof.json b/zkProtocols/example/proof.json similarity index 100% rename from zokrates/example/proof.json rename to zkProtocols/example/proof.json diff --git a/zokrates/example/proving.key b/zkProtocols/example/proving.key similarity index 100% rename from zokrates/example/proving.key rename to zkProtocols/example/proving.key diff --git a/zokrates/example/root.zok b/zkProtocols/example/root.zok similarity index 100% rename from zokrates/example/root.zok rename to zkProtocols/example/root.zok diff --git a/zokrates/example/verification.key b/zkProtocols/example/verification.key similarity index 100% rename from zokrates/example/verification.key rename to zkProtocols/example/verification.key diff --git a/zokrates/example/verifier.sol b/zkProtocols/example/verifier.sol similarity index 100% rename from zokrates/example/verifier.sol rename to zkProtocols/example/verifier.sol diff --git a/zokrates/example/witness b/zkProtocols/example/witness similarity index 100% rename from zokrates/example/witness rename to zkProtocols/example/witness diff --git a/zkProtocols/voting/README.md b/zkProtocols/voting/README.md new file mode 100644 index 0000000..14f3f13 --- /dev/null +++ b/zkProtocols/voting/README.md @@ -0,0 +1,98 @@ +# Municipality Election zk-SNARKS Voting proof + +## About + +This program implements a π-vote proof based on a municipality election smart contract deployed using the election-scripts. + +The TypeScript script deploy the MunicipalityElection smart contract and registers parties and candidates using mock data.This must be done +before to generate the proof program. + +In a real use case of this program, the circuit for the π-vote proof must be generated after the election +registration phase has closed, so that you know the ballot paper used by the Voter to vote. + +Following the ballot paper for the municipalityElection generated by the ts script: + +```json +{ + "contractAddress":"0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9", + "coalitions":[ + { + "majorCandidate":{ + "name":"Pino Pini", + "candidatesFor":"major", + "points":0 + }, + "parties":[ + { + "name":"Partito Democratico", + "councilorCandidates":[ + "Luigi Rossi", + "Maria Verdi", + "Renato Bianchi", + "Francesco Guidi", + "Paolo Franchi" + ], + "points":0 + }, + { + "name":"Forza Italia", + "councilorCandidates":[ + "Francesca Riti", + "Vanessa Reti", + "Mario Checchi", + "Carlo Proni", + "Pierpaolo Pingitore" + ], + "points":0 + } + ] + }, + { + "majorCandidate":{ + "name":"Ugo Silenti", + "candidatesFor":"major", + "points":0 + }, + "parties":[ + { + "name":"Cinque Stelle", + "councilorCandidates":[ + "Giuseppe Toni", + "Nicolò Movizzo", + "Alessandra Tonali", + "Antonella Chierici", + "Antonio Basso" + ], + "points":0 + }, + { + "name":"Lega", + "councilorCandidates":[ + "Patrizio Pini", + "Mariagrazia Crudi", + "Sabrina Giacigli", + "Marco Lioni", + "Pio Pedri" + ], + "points":0 + } + ] + } + ] +} +``` + +## Voting mechanism + +The election is created assigning 20 voting points (see the `election-scripts/create-election.ts`). + +Therefore, each voter can assign point to the major candidates and/or the parties +up to a maximum of 20 points totally. + +It is possible to assign points to more that one major candidate at the same time and also to parties in different coalitions. + +## What this program proofs + +1. The sum of the points assigned to the candidates and the parties does not exceed 20; +2. Since a voter can assign negative points in that way that the sum is 20, the second proof verifies that the points assigned are positive integers; +3. The third proof consist to demonstrate that the voter knows for whom he/she is voting; diff --git a/zkProtocols/voting/root.zk b/zkProtocols/voting/root.zk new file mode 100644 index 0000000..e69de29