Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #40

Merged
merged 41 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f43bacb
Ag 17 commitlint fix (#1)
g3k0 Mar 24, 2024
9260287
feat(@agora): AG-35 basic workflow (#3)
g3k0 Mar 25, 2024
3424f31
docs(@agora): AG-35 updloaded image (#5)
g3k0 Mar 26, 2024
56f40f9
Ag 18 eoa implementation (#7)
g3k0 Mar 28, 2024
db20673
Ag 19 DECsRegistry smart contract (#8)
g3k0 Mar 29, 2024
0dc0d57
Ag 20 election smart contract (#9)
g3k0 Mar 30, 2024
fb1dc90
Ag 20 election smart contract (#10)
g3k0 Mar 30, 2024
07a2bad
Merge branch 'main' into develop
g3k0 Mar 30, 2024
ed96d8d
Ag 25 deploy contracts (#13)
g3k0 Mar 31, 2024
202b9fa
Ag 26 register election script (#14)
g3k0 Apr 7, 2024
b7d36ec
Merge branch 'main' into develop
g3k0 Apr 7, 2024
c3eb2ba
Merge branch 'main' into develop
g3k0 Apr 7, 2024
2639ecd
Ag 37 actions api layer (#16)
g3k0 Apr 7, 2024
c9596a4
docs(@docs): updated README
g3k0 Apr 7, 2024
81f457a
Merge branch 'main' into develop
g3k0 Apr 7, 2024
3e5dd41
Merge branch 'main' into develop
g3k0 Apr 7, 2024
03e502d
fix(@ci): AG-36 fixed github username (#19)
g3k0 Apr 7, 2024
93631f7
Ag 39 encrypt dec data (#21)
g3k0 Apr 9, 2024
14581fc
Ag 40 dec registration (#22)
g3k0 Apr 11, 2024
7aeb927
Merge branch 'main' into develop
g3k0 Apr 11, 2024
82bb5c4
fix(@CICD): AG-42 fix github actions (#24)
g3k0 Apr 11, 2024
9241c8e
fix(CICD): AG-42 workflow fixes (#26)
g3k0 Apr 11, 2024
37ecada
Merge branch 'main' into develop
g3k0 Apr 11, 2024
86f3780
Merge branch 'main' into develop
g3k0 Apr 11, 2024
3dad309
Ag 42 fixes 2 (#28)
g3k0 Apr 11, 2024
8dec442
Merge branch 'main' into develop
g3k0 Apr 11, 2024
e79d573
Merge branch 'develop' of https://github.com/nova-collective/agora in…
g3k0 Apr 11, 2024
a3ea86f
Merge branch 'main' into develop
g3k0 Apr 11, 2024
3f87a38
AG-42 fixes (#30)
g3k0 Apr 11, 2024
e7463b6
Merge branch 'main' into develop
g3k0 Apr 11, 2024
3d205f3
fixes (#32)
g3k0 Apr 11, 2024
112da11
Merge branch 'main' into develop
g3k0 Apr 11, 2024
5314b97
Merge branch 'main' into develop
g3k0 Apr 11, 2024
af2ab5e
Merge branch 'main' into develop
g3k0 Apr 11, 2024
33a7097
Merge branch 'main' into develop
g3k0 Apr 12, 2024
cf01269
Merge branch 'main' into develop
g3k0 Apr 12, 2024
6575a17
Ag 32 zokrates init (#36)
g3k0 Apr 14, 2024
d1d6fdf
Merge branch 'main' into develop
g3k0 Apr 14, 2024
970496f
fix(CI/CD): AG-45 added set -e parameter to workflow (#38)
g3k0 Apr 17, 2024
c166750
feat(zk-snarks): AG-32 defined voting program (#39)
g3k0 Apr 18, 2024
91fc545
updated version
g3k0 Apr 18, 2024
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
2 changes: 1 addition & 1 deletion .jscpd.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"reporters": ["console"],
"languages": ["javascript", "typescript"],
"gitignore": true,
"failOnDuplication": false
"failOnDuplication": true
}

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ Remember to follow this convention for commit messages: `AG-<jira id> <descripti

Smart contracts code coverage documentation [here](https://www.npmjs.com/package/solidity-coverage).

CI/CD workflow fails if the unit test code coverage threshold (**80% of lines of code**) for scripts is not met.
### Quality gates

| step | library used | theshold | is error blocking |
|------|--------------|----------|-------------------|
| Code Linting | [eslint](https://www.npmjs.com/package/eslint) | No thesholds | yes |
| Code duplication | [jscpd](https://www.npmjs.com/package/jscpd) | 10% | yes |
| Smart contracts unit tests | [jest](https://www.npmjs.com/package/jest) | all tests must pass | yes |
| TypeScript files unit tests | [jest](https://www.npmjs.com/package/jest) | all tests must pass; 80% code coverage | yes |

## Run the localhost development network

Expand Down
38 changes: 32 additions & 6 deletions ci/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,44 @@ const execSyncOptions = { stdio: "inherit" };

const functions = {
installDeps: function () {
return execSync("npm install", execSyncOptions);
try {
execSync("npm install", execSyncOptions);
} catch (e) {
console.log(e);
process.exit(1);
}
},
lint: function () {
return execSync("npm run lint", execSyncOptions);
try {
execSync("npm run lint", execSyncOptions);
} catch (e) {
console.log(e);
process.exit(1);
}
},
checksDuplications: function () {
return execSync("npm run duplicated", execSyncOptions);
try {
execSync("npm run duplicated", execSyncOptions);
} catch (e) {
console.log(e);
process.exit(1);
}
},
smartContractsUnitTest: function () {
return execSync("npm run test-contracts", execSyncOptions);
try {
execSync("npm run test-contracts", execSyncOptions);
} catch (e) {
console.log(e);
process.exit(1);
}
},
scriptsUnitTest: function () {
return execSync("npm run test-scripts", execSyncOptions);
try {
execSync("npm run test-scripts", execSyncOptions);
} catch (e) {
console.log(e);
process.exit(1);
}
},
tagRelease: function () {
try {
Expand All @@ -39,7 +64,8 @@ const functions = {
);
execSync("git push origin --tags", execSyncOptions);
} catch (e) {
throw new Error(e);
console.log(e);
process.exit(1);
}
},
};
Expand Down
7 changes: 2 additions & 5 deletions contracts/MunicipalityElection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ contract MunicipalityElection is Election {
struct Candidate {
string name;
string candidatesFor; // major or councilor
uint256 points;
}

/// @dev the string key of the map correspond tho the party name registered in the parties mapping
Expand Down Expand Up @@ -112,8 +111,7 @@ contract MunicipalityElection is Election {

Candidate memory c = Candidate({
name: councilorCandidates[i],
candidatesFor: "councilor",
points: 0
candidatesFor: "councilor"
});

candidatesList.push(c);
Expand Down Expand Up @@ -143,8 +141,7 @@ contract MunicipalityElection is Election {

Candidate memory mcandidate = Candidate({
name: majorCandidate,
candidatesFor: "major",
points: 0
candidatesFor: "major"
});

Coalition memory newCoalition;
Expand Down
4 changes: 4 additions & 0 deletions election-scripts/__mocks__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const MAJOR_CANDIDATE_2 = "Ugo Silenti";
export const PARTIES: Party[] = [
{
name: PARTY_NAME_A,
points: 0,
councilorCandidates: [
"Luigi Rossi",
"Maria Verdi",
Expand All @@ -50,6 +51,7 @@ export const PARTIES: Party[] = [
},
{
name: PARTY_NAME_B,
points: 0,
councilorCandidates: [
"Francesca Riti",
"Vanessa Reti",
Expand All @@ -60,6 +62,7 @@ export const PARTIES: Party[] = [
},
{
name: PARTY_NAME_C,
points: 0,
councilorCandidates: [
"Giuseppe Toni",
"Nicolò Movizzo",
Expand All @@ -70,6 +73,7 @@ export const PARTIES: Party[] = [
},
{
name: PARTY_NAME_D,
points: 0,
councilorCandidates: [
"Patrizio Pini",
"Mariagrazia Crudi",
Expand Down
3 changes: 0 additions & 3 deletions election-scripts/create-election.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ describe("Create Election Script", () => {
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),
);
Expand Down
6 changes: 4 additions & 2 deletions election-scripts/create-election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ export async function main(
majorCandidate: {
name: coalition1Raw[0][0],
candidatesFor: coalition1Raw[0][1] as Candidature,
points: Number(coalition1Raw[0][2]),
points: 0,
},
parties: [],
};

for (const p of parties) {
for (const k of coalition1Raw[1]) {
if (k === p.name) {
p.points = 0;
coalition1.parties.push(p);
}
}
Expand All @@ -120,14 +121,15 @@ export async function main(
majorCandidate: {
name: coalition2Raw[0][0],
candidatesFor: coalition2Raw[0][1] as Candidature,
points: Number(coalition2Raw[0][2]),
points: 0,
},
parties: [],
};

for (const p of parties) {
for (const k of coalition2Raw[1]) {
if (k === p.name) {
p.points = 0;
coalition2.parties.push(p);
}
}
Expand Down
1 change: 1 addition & 0 deletions election-scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Candidate = {

export type Party = {
name: string;
points: number;
councilorCandidates: string[];
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 0 additions & 1 deletion test/MunicipalityElection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
98 changes: 98 additions & 0 deletions zkProtocols/voting/README.md
Original file line number Diff line number Diff line change
@@ -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;
Empty file added zkProtocols/voting/root.zk
Empty file.
Loading