Skip to content

Commit

Permalink
Develop (#37)
Browse files Browse the repository at this point in the history
* Ag 17 commitlint fix (#1)

* fix(@script): AG-17 changed script logic

changed script login the commit script

* fix(@script): AG-17 changed script

modified some logic in the script folder

* docs(@agora): modified readme

modified readme

* feat(@agora): AG-35 basic workflow (#3)

* feat(@agora): AG-35 basic workflow

basic GitHub Actions workflow implementation

* feat(@agora): AG-35 duplicated code

inserted duplicated code check in ci-cd

* docs(@agora): AG-35 updloaded image (#5)

uploaded image for functional analysis

* Ag 18 eoa implementation (#7)

* feat(@script): AG-18 EOA script implementation

implemented script in order to generate an EOA over different ethereum networks configured

* test(@script): AG-18 unit test configuration

unit test configuration for scripts using jest

* test(@agora): AG-18 configured test step in workflow

configured workflow to run script unit test

* test(@script): AG-18 configured commit script

configured pre-commit hook script to run unit test

* test(@script): AG-18 unit test implementation

implemented unit test for eoa script

* test(@script): AG-18 code coverage

unit test code coverage report implementation

* refactor(@script): AG-18 precommit hook

added check in pre-commit hook

* fix(@script): AG-18 fixed unit test threshold

fixed unit test code coverage threshold

* fix(@agora): AG-18 fixed package.json

fixed package json property not used

* fix(@agora): AG-18 fixed unit test

n

* fix(@agora): AG-18 fixed workflow

fixed workflow

* refactor(@script): AG-18 test code coverage threshold

test code coverage threshold

* docs(@agora): AG-18 updated readme

updated readme file

* Ag 19 DECsRegistry smart contract (#8)

* fix(@script): AG-19 removed comments

removed code comments

* docs(@docs): AG-19 updated sequence diagrams

updated the sequence diagrams images for the functional analysis

* docs(@docs): AG-19 updated smart contract classes

updated docs about the smart contracts classes

* feat(@contracts): AG-19 DEC contract implementation

implemented a first version of the DEC contract

* feat(@contracts): AG-19 added events to DEC sc

emitted event in the DEC smart contract implementation

* feat(@contracts): AG-19 implemented DEC contract

implemented DEC contract and related unit tests

* fix(@contracts): AG-19 removed event

removed event not used in DEC contract

* feat(@contracts): AG-19 DECs registry implementation

implemented the register of the DECs with the required methods

* test(@contracts): AG-19 defined test for DECsRegistry contract

defined test structure for the DECsRegistry smart contract

* test(@contracts): AG-19 implemented unit test

implemented unit tests for DECsRegistry smart contract

* feat(@contracts): AG-19 added events to smart contract

added events to the DECsRegistry smart contract

* Ag 20 election smart contract (#9)

* refactor(@agora): AG-20 switched test network

switched from legacy goerli test network to sepolia

* docs(@docs): AG-20 updated analysis diagrams

updated diagrams in the functional analysis

* feat(@contracts): AG-20 Election smart contract

implemented Election smart contract with unit tests

* feat(@contracts): AG-20 Elections smart contracts

implemeneted different smart contracts for different kind of elections

* docs(@docs): AG-20 addded diagrams files to docs

added diagrams file to the docs folder

* docs(@docs): AG-20 updated class diagrams

updated the smart contracts class diagrams

* Ag 20 election smart contract (#10)

* refactor(@agora): AG-20 switched test network

switched from legacy goerli test network to sepolia

* docs(@docs): AG-20 updated analysis diagrams

updated diagrams in the functional analysis

* feat(@contracts): AG-20 Election smart contract

implemented Election smart contract with unit tests

* feat(@contracts): AG-20 Elections smart contracts

implemeneted different smart contracts for different kind of elections

* docs(@docs): AG-20 addded diagrams files to docs

added diagrams file to the docs folder

* docs(@docs): AG-20 updated class diagrams

updated the smart contracts class diagrams

* fix(@agora): AG-20 updated version number

updated version number in package json

* Ag 25 deploy contracts (#13)

* feat(@agora): AG-25 configured evm compiler

configured the evm compiler in the hardhat configuration file

* refactor(@contracts): AG-25 refactored DECs Registry contract

refactored DECs registry contract

* refactor(@contracts): AG-25 refactored DEC contract

refactored DEC smart contract

* feat(@contracts): AG-25 added name property to DECs Registry

added name property to DECs Registry smart contract

* feat(@contracts): ignition modules implementation

implemented the ignition modules for contracts deploy

* fix(@contracts): AG-25 added folder to gitignore

added foldet to gitignore

* fix(@contracts): AG-25 ignored files

added files to gitignore

* Ag 26 register election script (#14)

* docs(@docs): modified main flow diagram

modified the representation of the entire process in the functional analysis

* docs(@docs): AG-26 typo fix

typo fix in the README file

* feat(@scripts): AG-26 implemented the deploy for the Election smart contract

implemented the ignition module for the deploy of the Election smart contract

* feat(@script): AG-26 municipality election deploy

created the ignition module for the deploy of a municipality election

* feat(@contracts): AG-26 defined methods for municipality election contract

defined properties and methods for the municipality election smart contract

* feat(@contracts): AG-26 election contract modifier implementation

implemented a modifier in the municipality election smart contract

* feat(@contracts): AG-26 municipality election method implementation

implemented the registerParty method in the municipality election smart contract

* refactor(@contracts): AG_26 modified contracts methods

modified the sign of the methods of all the smart contracts

* feat(@contracts): AG-26 municipality election smart contract

implemented the municipality election smart contract

* refactor(@contracts): AG-26 refactored municipality election contract

refactored municipality election smart contract to make it more gas efficient

* feat(@contracts): AG-26 added getter to municipality election contract

added a getter function to the municipality election getter contract

* refactor(@contracts): AG-26 formatted smart contract

formatted smart contract file

* feat(@contracts): AG-26 get coalition in municipality election

implemented a get coalition in the municipality election contract

* refactor(@contracts): AG-26 refactored municipality election contract

refactored municipality election contract

* refactor(@contracts): AG-26 Municipality contract unit test

unit tests implementation for municipality election smart contract

* feat(contracts): AG-26 refactored Municipality Election

modified Municipality Election smart contract deploy

* feat(@contracts): AG-26 Ignition module implementation

ignition module implementation

* style(@contracts): AG-26 contract refactor

refactored formatting of a smart contract

* feat(@contracts): AG-26 MunicipalityElection smart contract deploy script

implementation of the ignition module for the deploy of the MunicipalityElection smart dd contract

* feat(@contracts): AG-26 Create election script definition

defined create-election script that register the data into a given election contract

* feat(@scripts): AG-26 create election script partial implementation

partially implemented the script for the MunicipalityElection smart contract

* feat(@scripts): AG-26 Implemented the create-election script

implemented the create election script

* feat(@script): AG-26 unit test implementation

implemented unit test for create election script

* refactor(@script): improved script

improved script

* Ag 37 actions api layer (#16)

* feat(@ci): AG-37 defined ci module

defined a ci module for the workflows api layer

* feat(@ci): AG-37 ci api integration

integrated ci apis into github actions workflow

* fix(@ci): AG-37 fixed command path

fixed ci command path

* fix(ci): AG-37 fixed ci module logic

fixed ci module logic

* docs(@docs): updated README

updated README

* fix(@ci): AG-36 fixed github username (#19)

fixed git user in workflow

* Ag 39 encrypt dec data (#21)

* docs(@docs): AG-39 updated architectural diagram

updated architectural diagram

* feat(@lib): AG-39 cryptoUtils lib implementation

implemented library that ecrypt and decrypt strings

* feat(@script): AG-39 deploy encrypted DEC implementation

implemented the encryption of DEC data and deploy of smart contract instance

* feat(@script): AG-39 script test

implemented unit test for election scripts

* Ag 40 dec registration (#22)

* feat(@scripts): AG-40 decs registry deploy script

defined the script for the deploy of the DECs Registry

* feat(scripts): AG-40 decs registry deploy script

implemented the script for the deploy of the DECs Registry

* test(scripts): unit test implementation

implemented unit test for the DECsRegistry deploy script

* feat(scripts): AG-40 DEC registration

defined the script for the registration of a DEC into the Registry

* feat(scripts): AG-40 register dec script

implemented register dec script

* feat(@script): AG-40 register dec

refactored the register dec script implementation

* feat(@script): AG-40 process review

review and fixes of the entire process with scripts

* docs(@docs ): AG-40 updated readme

updated readme

* refactor(@docs): AG-40 updated app version

updated version

* fix(@cicd): AG-42 fix github actions (#24)

fixed tag creation in workflow

* fix(CICD): AG-42 workflow fixes (#26)

workflow fixes

* Ag 42 fixes 2 (#28)

* Develop (#27)

* Ag 17 commitlint fix (#1)

* fix(@script): AG-17 changed script logic

changed script login the commit script

* fix(@script): AG-17 changed script

modified some logic in the script folder

* docs(@agora): modified readme

modified readme

* feat(@agora): AG-35 basic workflow (#3)

* feat(@agora): AG-35 basic workflow

basic GitHub Actions workflow implementation

* feat(@agora): AG-35 duplicated code

inserted duplicated code check in ci-cd

* docs(@agora): AG-35 updloaded image (#5)

uploaded image for functional analysis

* Ag 18 eoa implementation (#7)

* feat(@script): AG-18 EOA script implementation

implemented script in order to generate an EOA over different ethereum networks configured

* test(@script): AG-18 unit test configuration

unit test configuration for scripts using jest

* test(@agora): AG-18 configured test step in workflow

configured workflow to run script unit test

* test(@script): AG-18 configured commit script

configured pre-commit hook script to run unit test

* test(@script): AG-18 unit test implementation

implemented unit test for eoa script

* test(@script): AG-18 code coverage

unit test code coverage report implementation

* refactor(@script): AG-18 precommit hook

added check in pre-commit hook

* fix(@script): AG-18 fixed unit test threshold

fixed unit test code coverage threshold

* fix(@agora): AG-18 fixed package.json

fixed package json property not used

* fix(@agora): AG-18 fixed unit test

n

* fix(@agora): AG-18 fixed workflow

fixed workflow

* refactor(@script): AG-18 test code coverage threshold

test code coverage threshold

* docs(@agora): AG-18 updated readme

updated readme file

* Ag 19 DECsRegistry smart contract (#8)

* fix(@script): AG-19 removed comments

removed code comments

* docs(@docs): AG-19 updated sequence diagrams

updated the sequence diagrams images for the functional analysis

* docs(@docs): AG-19 updated smart contract classes

updated docs about the smart contracts classes

* feat(@contracts): AG-19 DEC contract implementation

implemented a first version of the DEC contract

* feat(@contracts): AG-19 added events to DEC sc

emitted event in the DEC smart contract implementation

* feat(@contracts): AG-19 implemented DEC contract

implemented DEC contract and related unit tests

* fix(@contracts): AG-19 removed event

removed event not used in DEC contract

* feat(@contracts): AG-19 DECs registry implementation

implemented the register of the DECs with the required methods

* test(@contracts): AG-19 defined test for DECsRegistry contract

defined test structure for the DECsRegistry smart contract

* test(@contracts): AG-19 implemented unit test

implemented unit tests for DECsRegistry smart contract

* feat(@contracts): AG-19 added events to smart contract

added events to the DECsRegistry smart contract

* Ag 20 election smart contract (#9)

* refactor(@agora): AG-20 switched test network

switched from legacy goerli test network to sepolia

* docs(@docs): AG-20 updated analysis diagrams

updated diagrams in the functional analysis

* feat(@contracts): AG-20 Election smart contract

implemented Election smart contract with unit tests

* feat(@contracts): AG-20 Elections smart contracts

implemeneted different smart contracts for different kind of elections

* docs(@docs): AG-20 addded diagrams files to docs

added diagrams file to the docs folder

* docs(@docs): AG-20 updated class diagrams

updated the smart contracts class diagrams

* Ag 20 election smart contract (#10)

* refactor(@agora): AG-20 switched test network

switched from legacy goerli test network to sepolia

* docs(@docs): AG-20 updated analysis diagrams

updated diagrams in the functional analysis

* feat(@contracts): AG-20 Election smart contract

implemented Election smart contract with unit tests

* feat(@contracts): AG-20 Elections smart contracts

implemeneted different smart contracts for different kind of elections

* docs(@docs): AG-20 addded diagrams files to docs

added diagrams file to the docs folder

* docs(@docs): AG-20 updated class diagrams

updated the smart contracts class diagrams

* fix(@agora): AG-20 updated version number

updated version number in package json

* Ag 25 deploy contracts (#13)

* feat(@agora): AG-25 configured evm compiler

configured the evm compiler in the hardhat configuration file

* refactor(@contracts): AG-25 refactored DECs Registry contract

refactored DECs registry contract

* refactor(@contracts): AG-25 refactored DEC contract

refactored DEC smart contract

* feat(@contracts): AG-25 added name property to DECs Registry

added name property to DECs Registry smart contract

* feat(@contracts): ignition modules implementation

implemented the ignition modules for contracts deploy

* fix(@contracts): AG-25 added folder to gitignore

added foldet to gitignore

* fix(@contracts): AG-25 ignored files

added files to gitignore

* Ag 26 register election script (#14)

* docs(@docs): modified main flow diagram

modified the representation of the entire process in the functional analysis

* docs(@docs): AG-26 typo fix

typo fix in the README file

* feat(@scripts): AG-26 implemented the deploy for the Election smart contract

implemented the ignition module for the deploy of the Election smart contract

* feat(@script): AG-26 municipality election deploy

created the ignition module for the deploy of a municipality election

* feat(@contracts): AG-26 defined methods for municipality election contract

defined properties and methods for the municipality election smart contract

* feat(@contracts): AG-26 election contract modifier implementation

implemented a modifier in the municipality election smart contract

* feat(@contracts): AG-26 municipality election method implementation

implemented the registerParty method in the municipality election smart contract

* refactor(@contracts): AG_26 modified contracts methods

modified the sign of the methods of all the smart contracts

* feat(@contracts): AG-26 municipality election smart contract

implemented the municipality election smart contract

* refactor(@contracts): AG-26 refactored municipality election contract

refactored municipality election smart contract to make it more gas efficient

* feat(@contracts): AG-26 added getter to municipality election contract

added a getter function to the municipality election getter contract

* refactor(@contracts): AG-26 formatted smart contract

formatted smart contract file

* feat(@contracts): AG-26 get coalition in municipality election

implemented a get coalition in the municipality election contract

* refactor(@contracts): AG-26 refactored municipality election contract

refactored municipality election contract

* refactor(@contracts): AG-26 Municipality contract unit test

unit tests implementation for municipality election smart contract

* feat(contracts): AG-26 refactored Municipality Election

modified Municipality Election smart contract deploy

* feat(@contracts): AG-26 Ignition module implementation

ignition module implementation

* style(@contracts): AG-26 contract refactor

refactored formatting of a smart contract

* feat(@contracts): AG-26 MunicipalityElection smart contract deploy script

implementation of the ignition module for the deploy of the MunicipalityElection smart dd contract

* feat(@contracts): AG-26 Create election script definition

defined create-election script that register the data into a given election contract

* feat(@scripts): AG-26 create election script partial implementation

partially implemented the script for the MunicipalityElection smart contract

* feat(@scripts): AG-26 Implemented the create-election script

implemented the create election script

* feat(@script): AG-26 unit test implementation

implemented unit test for create election script

* refactor(@script): improved script

improved script

* Ag 37 actions api layer (#16)

* feat(@ci): AG-37 defined ci module

defined a ci module for the workflows api layer

* feat(@ci): AG-37 ci api integration

integrated ci apis into github actions workflow

* fix(@ci): AG-37 fixed command path

fixed ci command path

* fix(ci): AG-37 fixed ci module logic

fixed ci module logic

* docs(@docs): updated README

updated README

* fix(@ci): AG-36 fixed github username (#19)

fixed git user in workflow

* Ag 39 encrypt dec data (#21)

* docs(@docs): AG-39 updated architectural diagram

updated architectural diagram

* feat(@lib): AG-39 cryptoUtils lib implementation

implemented library that ecrypt and decrypt strings

* feat(@script): AG-39 deploy encrypted DEC implementation

implemented the encryption of DEC data and deploy of smart contract instance

* feat(@script): AG-39 script test

implemented unit test for election scripts

* Ag 40 dec registration (#22)

* feat(@scripts): AG-40 decs registry deploy script

defined the script for the deploy of the DECs Registry

* feat(scripts): AG-40 decs registry deploy script

implemented the script for the deploy of the DECs Registry

* test(scripts): unit test implementation

implemented unit test for the DECsRegistry deploy script

* feat(scripts): AG-40 DEC registration

defined the script for the registration of a DEC into the Registry

* feat(scripts): AG-40 register dec script

implemented register dec script

* feat(@script): AG-40 register dec

refactored the register dec script implementation

* feat(@script): AG-40 process review

review and fixes of the entire process with scripts

* docs(@docs ): AG-40 updated readme

updated readme

* refactor(@docs): AG-40 updated app version

updated version

* fix(@cicd): AG-42 fix github actions (#24)

fixed tag creation in workflow

* fix(CICD): AG-42 workflow fixes (#26)

workflow fixes

* fix(CICD): AG-42 fixes

fixes

* AG-42 fixes (#30)

* fixes (#32)

* Ag 32 zokrates init (#36)

* feat(@zkp): AG-32 zokrates init

init a zokrates proof as example

* docs(docs): AG-32 updated docs

updated documentation
  • Loading branch information
g3k0 authored Apr 14, 2024
1 parent 884c7dd commit 772b22c
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 39 deletions.
26 changes: 13 additions & 13 deletions contracts/MunicipalityElection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./Election.sol";
contract MunicipalityElection is Election {
struct Candidate {
string name;
string candidatesFor; // major or councilior
string candidatesFor; // major or councilor
uint256 points;
}

Expand All @@ -27,8 +27,8 @@ contract MunicipalityElection is Election {
Coalition[] private coalitions;

/// @dev this is a mapping used in private function
mapping(string => bool) private isCounciliorCandidateInArray;
Candidate[] private counciliorCandidatesArray;
mapping(string => bool) private iscouncilorCandidateInArray;
Candidate[] private councilorCandidatesArray;

/// @dev this is a mapping used in private function
mapping(string => bool) private partyExistsInCoalition;
Expand Down Expand Up @@ -92,32 +92,32 @@ contract MunicipalityElection is Election {
return (coalition.majorCandidate, partyNames);
}

/// @notice as first step, during the registration period the parties register their names and list of councilior candidates
/// @notice as first step, during the registration period the parties register their names and list of councilor candidates
function registerParty(
string memory name,
string[] memory counciliorCandidates
string[] memory councilorCandidates
) external onlyOwner isRegistrationPeriod {
require(
counciliorCandidates.length == 5,
"The list of councilior candidates must be composed of 5 names"
councilorCandidates.length == 5,
"The list of councilor candidates must be composed of 5 names"
);

Candidate[] storage candidatesList = parties[name];

for (uint i = 0; i < counciliorCandidates.length; i++) {
for (uint i = 0; i < councilorCandidates.length; i++) {
require(
!isCounciliorCandidateInArray[counciliorCandidates[i]],
"Councilior candidate names must be unique"
!iscouncilorCandidateInArray[councilorCandidates[i]],
"councilor candidate names must be unique"
);

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

candidatesList.push(c);
isCounciliorCandidateInArray[counciliorCandidates[i]] = true;
iscouncilorCandidateInArray[councilorCandidates[i]] = true;
}

partiesLength++;
Expand Down
Binary file added docs/assets/dec_class.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/decs_registry_class.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/election_class.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 19 additions & 25 deletions docs/diagrams/Agora diagrams.drawio

Large diffs are not rendered by default.

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.6.0",
"version": "0.7.0",
"description": "A confidentiality-first electronic voting system",
"author": {
"name": "nova collective",
Expand Down
20 changes: 20 additions & 0 deletions zokrates/example/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"inputs": [
{
"name": "a",
"public": false,
"type": "field"
},
{
"name": "b",
"public": true,
"type": "field"
}
],
"output": {
"type": "tuple",
"components": {
"elements": []
}
}
}
Binary file added zokrates/example/out
Binary file not shown.
Binary file added zokrates/example/out.r1cs
Binary file not shown.
Binary file added zokrates/example/out.wtns
Binary file not shown.
27 changes: 27 additions & 0 deletions zokrates/example/proof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"scheme": "g16",
"curve": "bn128",
"proof": {
"a": [
"0x13a494590cd3611b3f99892d1a500996d1720e6a0ff914e80200a90cda9253c3",
"0x304739d412e31aab8e92da6db59841c6145fdc7b029d758cd17d2e5339363988"
],
"b": [
[
"0x26d2a85ce5a207780b907c4b494d60c237b64c79733326877bb0186be97ac010",
"0x1aacd62104f32ecdc1369913daab58f0e0029bbf0a9b115a34a46b838f4741b6"
],
[
"0x14445684c9500b3ac39764ba2eb053cd682d0bde9c0222622f739a202f21bbf8",
"0x1a3fa66376458c9870ba0de3ddc29872d61cbbad423da04e93458ec42ff303d1"
]
],
"c": [
"0x2d1d8e3991a5820dab06ffb23cb78a5fbce396325f837ff2599d637786f0fb82",
"0x18c2c215c889f4e6abe473f6b1f84fe83529705eac10bc81d0ac5ae9f3a092b7"
]
},
"inputs": [
"0x000000000000000000000000000000000000000000000000000000000001bba1"
]
}
Binary file added zokrates/example/proving.key
Binary file not shown.
5 changes: 5 additions & 0 deletions zokrates/example/root.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def main(private field a, field b) {
assert(a * a == b);
return;
}

48 changes: 48 additions & 0 deletions zokrates/example/verification.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"scheme": "g16",
"curve": "bn128",
"alpha": [
"0x1f9e716d1a7cc63c1e07ba09e762bae1326a6204f334b18913e4e919a6d0e064",
"0x0692f7de6ef3fbbdd6ab896517c6cdd67915a66a35dfca399e5bab43d9cd8733"
],
"beta": [
[
"0x1aaed8506d67d1f7deae5eeeb0f3d6ec6643b536128d1ce97f2ef52dfd86996d",
"0x2d466f12cd90035edb520f695933b74f16e12360630834b3c2feaf909ece8fbd"
],
[
"0x1783da1f135c023089043ae327bd2779b2af303e13d5c25cc9f6a6adfe6aa6b7",
"0x13b3ee585a3e269df4b1fb1c2f8d52089bbe3654f35012ec33909ff6737fb8d9"
]
],
"gamma": [
[
"0x2e4f04a66ade653cc98984e1c6595f91506e25a65e801b58bae37c17aed43018",
"0x2183bd54c9d43db344a895b31fa0f9d08e4081b9deb0745583716214f67129ba"
],
[
"0x2f1ebb5ebb52a1159f5b98319ef76bc280ff0c659080fc5813b75882707b73aa",
"0x0da1457454afba9ffc705805187369ff966e3048c3365b50d41170d39b45de63"
]
],
"delta": [
[
"0x0b6b8cb3908dc31c41789292533daf608fbca8c75363fdc17ad79b1c1d32b1c3",
"0x0b3de4718b7e12c4b6e20caaf618c43adae1cb0c50e8f59e4177fe9378557b61"
],
[
"0x23e7d597e8385d24398c7542954ff75571a194491ecb21ec089ab0775639501b",
"0x28eff9715119798a9a1dd3cbcf8ffc609928f0585b77742a933153293bf25166"
]
],
"gamma_abc": [
[
"0x01f44aa244b9ecd20c9b94381581a408a60cda2281ccabe39b4e3e9c80ff047e",
"0x2117ff110b33b756808a293cd3f69bfcebf9d5cc3184efc2110aff7b886d4286"
],
[
"0x21fe20b04b62b25099638a3e6f3da919547d51be5e1d27b7287097a72e3c1bce",
"0x01c6a6f3707f5310023e22ce0a112d1a04f082018962983fb263274e7b52007c"
]
]
}
201 changes: 201 additions & 0 deletions zokrates/example/verifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// This file is MIT Licensed.
//
// Copyright 2017 Christian Reitwiessner
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pragma solidity ^0.8.0;
library Pairing {
struct G1Point {
uint X;
uint Y;
}
// Encoding of field elements is: X[0] * z + X[1]
struct G2Point {
uint[2] X;
uint[2] Y;
}
/// @return the generator of G1
function P1() pure internal returns (G1Point memory) {
return G1Point(1, 2);
}
/// @return the generator of G2
function P2() pure internal returns (G2Point memory) {
return G2Point(
[10857046999023057135944570762232829481370756359578518086990519993285655852781,
11559732032986387107991004021392285783925812861821192530917403151452391805634],
[8495653923123431417604973247489272438418190587263600148770280649306958101930,
4082367875863433681332203403145435568316851327593401208105741076214120093531]
);
}
/// @return the negation of p, i.e. p.addition(p.negate()) should be zero.
function negate(G1Point memory p) pure internal returns (G1Point memory) {
// The prime q in the base field F_q for G1
uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
if (p.X == 0 && p.Y == 0)
return G1Point(0, 0);
return G1Point(p.X, q - (p.Y % q));
}
/// @return r the sum of two points of G1
function addition(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) {
uint[4] memory input;
input[0] = p1.X;
input[1] = p1.Y;
input[2] = p2.X;
input[3] = p2.Y;
bool success;
assembly {
success := staticcall(sub(gas(), 2000), 6, input, 0xc0, r, 0x60)
// Use "invalid" to make gas estimation work
switch success case 0 { invalid() }
}
require(success);
}


/// @return r the product of a point on G1 and a scalar, i.e.
/// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p.
function scalar_mul(G1Point memory p, uint s) internal view returns (G1Point memory r) {
uint[3] memory input;
input[0] = p.X;
input[1] = p.Y;
input[2] = s;
bool success;
assembly {
success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60)
// Use "invalid" to make gas estimation work
switch success case 0 { invalid() }
}
require (success);
}
/// @return the result of computing the pairing check
/// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1
/// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
/// return true.
function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) {
require(p1.length == p2.length);
uint elements = p1.length;
uint inputSize = elements * 6;
uint[] memory input = new uint[](inputSize);
for (uint i = 0; i < elements; i++)
{
input[i * 6 + 0] = p1[i].X;
input[i * 6 + 1] = p1[i].Y;
input[i * 6 + 2] = p2[i].X[1];
input[i * 6 + 3] = p2[i].X[0];
input[i * 6 + 4] = p2[i].Y[1];
input[i * 6 + 5] = p2[i].Y[0];
}
uint[1] memory out;
bool success;
assembly {
success := staticcall(sub(gas(), 2000), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
// Use "invalid" to make gas estimation work
switch success case 0 { invalid() }
}
require(success);
return out[0] != 0;
}
/// Convenience method for a pairing check for two pairs.
function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal view returns (bool) {
G1Point[] memory p1 = new G1Point[](2);
G2Point[] memory p2 = new G2Point[](2);
p1[0] = a1;
p1[1] = b1;
p2[0] = a2;
p2[1] = b2;
return pairing(p1, p2);
}
/// Convenience method for a pairing check for three pairs.
function pairingProd3(
G1Point memory a1, G2Point memory a2,
G1Point memory b1, G2Point memory b2,
G1Point memory c1, G2Point memory c2
) internal view returns (bool) {
G1Point[] memory p1 = new G1Point[](3);
G2Point[] memory p2 = new G2Point[](3);
p1[0] = a1;
p1[1] = b1;
p1[2] = c1;
p2[0] = a2;
p2[1] = b2;
p2[2] = c2;
return pairing(p1, p2);
}
/// Convenience method for a pairing check for four pairs.
function pairingProd4(
G1Point memory a1, G2Point memory a2,
G1Point memory b1, G2Point memory b2,
G1Point memory c1, G2Point memory c2,
G1Point memory d1, G2Point memory d2
) internal view returns (bool) {
G1Point[] memory p1 = new G1Point[](4);
G2Point[] memory p2 = new G2Point[](4);
p1[0] = a1;
p1[1] = b1;
p1[2] = c1;
p1[3] = d1;
p2[0] = a2;
p2[1] = b2;
p2[2] = c2;
p2[3] = d2;
return pairing(p1, p2);
}
}

contract Verifier {
using Pairing for *;
struct VerifyingKey {
Pairing.G1Point alpha;
Pairing.G2Point beta;
Pairing.G2Point gamma;
Pairing.G2Point delta;
Pairing.G1Point[] gamma_abc;
}
struct Proof {
Pairing.G1Point a;
Pairing.G2Point b;
Pairing.G1Point c;
}
function verifyingKey() pure internal returns (VerifyingKey memory vk) {
vk.alpha = Pairing.G1Point(uint256(0x1f9e716d1a7cc63c1e07ba09e762bae1326a6204f334b18913e4e919a6d0e064), uint256(0x0692f7de6ef3fbbdd6ab896517c6cdd67915a66a35dfca399e5bab43d9cd8733));
vk.beta = Pairing.G2Point([uint256(0x1aaed8506d67d1f7deae5eeeb0f3d6ec6643b536128d1ce97f2ef52dfd86996d), uint256(0x2d466f12cd90035edb520f695933b74f16e12360630834b3c2feaf909ece8fbd)], [uint256(0x1783da1f135c023089043ae327bd2779b2af303e13d5c25cc9f6a6adfe6aa6b7), uint256(0x13b3ee585a3e269df4b1fb1c2f8d52089bbe3654f35012ec33909ff6737fb8d9)]);
vk.gamma = Pairing.G2Point([uint256(0x2e4f04a66ade653cc98984e1c6595f91506e25a65e801b58bae37c17aed43018), uint256(0x2183bd54c9d43db344a895b31fa0f9d08e4081b9deb0745583716214f67129ba)], [uint256(0x2f1ebb5ebb52a1159f5b98319ef76bc280ff0c659080fc5813b75882707b73aa), uint256(0x0da1457454afba9ffc705805187369ff966e3048c3365b50d41170d39b45de63)]);
vk.delta = Pairing.G2Point([uint256(0x0b6b8cb3908dc31c41789292533daf608fbca8c75363fdc17ad79b1c1d32b1c3), uint256(0x0b3de4718b7e12c4b6e20caaf618c43adae1cb0c50e8f59e4177fe9378557b61)], [uint256(0x23e7d597e8385d24398c7542954ff75571a194491ecb21ec089ab0775639501b), uint256(0x28eff9715119798a9a1dd3cbcf8ffc609928f0585b77742a933153293bf25166)]);
vk.gamma_abc = new Pairing.G1Point[](2);
vk.gamma_abc[0] = Pairing.G1Point(uint256(0x01f44aa244b9ecd20c9b94381581a408a60cda2281ccabe39b4e3e9c80ff047e), uint256(0x2117ff110b33b756808a293cd3f69bfcebf9d5cc3184efc2110aff7b886d4286));
vk.gamma_abc[1] = Pairing.G1Point(uint256(0x21fe20b04b62b25099638a3e6f3da919547d51be5e1d27b7287097a72e3c1bce), uint256(0x01c6a6f3707f5310023e22ce0a112d1a04f082018962983fb263274e7b52007c));
}
function verify(uint[] memory input, Proof memory proof) internal view returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.gamma_abc.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.gamma_abc[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.gamma_abc[0]);
if(!Pairing.pairingProd4(
proof.a, proof.b,
Pairing.negate(vk_x), vk.gamma,
Pairing.negate(proof.c), vk.delta,
Pairing.negate(vk.alpha), vk.beta)) return 1;
return 0;
}
function verifyTx(
Proof memory proof, uint[1] memory input
) public view returns (bool r) {
uint[] memory inputValues = new uint[](1);

for(uint i = 0; i < input.length; i++){
inputValues[i] = input[i];
}
if (verify(inputValues, proof) == 0) {
return true;
} else {
return false;
}
}
}
Binary file added zokrates/example/witness
Binary file not shown.

0 comments on commit 772b22c

Please sign in to comment.