A confidentiality-first electronic voting system.
this is an experimental project, don't use it in production
Agora is a voting platform based on the Ethereum public blockchain and a Zero-Knowledge Proof cryptographic protocol.
Consult the technical documentation in the wiki of the project:
Agora is a web3 dApp based on the Hardhat framework and the Alchemy SDK. Consult the documentation.
In order to run the application you need the following software installed on you machine:
You also need an Alchemy account.
To setup the application follow these steps:
- clone this repository
- from the root folder of the application run:
npm i
- run
npm run prepare
- Write a
.env
file in the root of the project and configure:SEPOLIA_URL
You can find the data in your Alchemy account, after you create an app there;ALCHEMY_PRIVATE_KEY
You can find the data in your Alchemy account;REPORT_GAS
enable or disable the gas report on smart contracts unit tests executions;NODE_ENV
setdevelopment
for your local machine;
Agora uses a Python external library for cryptographic operations called crypto-py. This library needs to be manually integrated into the Hardhat framework, follow this steps:
- from the root folder of application, go to the
lib
folder; - clone
crypto-py
inside the lib folder; - go inside the crypto-py folder and install the dependencies
pip install -r requirements.txt
; - if you decide to set a python environment inside the crypto-py folder, remember to activate the environment;
Alternatively, If you are in a Unix environment, you can clone the library somewhere else and create a symbolic link inside the Agora lib folder.
The main
and the develop
branches are protected. It is required to open and review pull requests in order to merge the code.
Since the development of this project is planned, if you are considering to open a Pull Request please contact first the maintainer of the code at:
nova.web3.collective@gmail.com
To commit:
git add <files list>
npm run commit
Remember to follow this convention for commit messages: AG-<jira id> <description>
, this allows to link the commit to its ticket in the Jira board.
- Run the unit tests for smart contracts:
npm run test-contracts
- Run the unit test code coverage for smart contracts:
npm run coverage-contracts
- Run the unit test for scripts:
npm run test-scripts
Smart contracts code coverage documentation here.
step | library used | theshold | is error blocking |
---|---|---|---|
Code Linting | eslint | Not applicable | yes |
Code duplication | jscpd | 10% | yes |
Smart contracts unit tests | jest | all tests must pass | yes |
TypeScript files unit tests | jest | all tests must pass; 80% code coverage | yes |
Hardhat framework provides a local blockchain network that lives in memory, that is useful to test local developments. To start the network run the command:
npm run node:start
Run the command: npm run compile
The smart contracts deploy process is managed, under the hood, by Ignition.
To deploy smart contract instances run the command:
npm run deploy-contract <ignition-module-path> <network>
Ignition will deploy the instances of the smart contract following the logic specified in the ignition module.
To deploy to a specific network (e.g. mainnet, sepora), the network must be configured in the hardhat.config.ts
file.
For the local network the parameter to pass is localhost
, there is no need to configure the local network.
- Edit the scripts mocks file:
election-scripts/__mocks__.ts
;- edit the municipality election contract data, in particular registrationStart and registrationEnd are timestamps in seconds;
- edit the data of the parties and candidates as you prefer;
- edit the data of the Voter as you prefer;
- Compile the smart contracts in order to produce the artifacts:
npm run compile
; - Creates the
typechain-types
folder with the command:npx hardhat typechain
; - start the local network (unless you want to run the scripts on Sepolia):
npm run node:start
;
For the creation of the registry we deploy the DECs Registry smart contract:
npx hardhat run election-scripts/create-decs-registry.ts --network localhost
;
Take note of the contract address returned by the script;
If you are using the local network, you can skip this step and just take note of one EOA returned by the start of the local network.
Execute the create-voter
scripts and take note of the resulting address
and privateKey
:
npx hardhat run election-scripts/create-voter-eoa.ts
3. The Public Authority / Admin creates the DEC for the Voter and register the DEC into the DECs Registry
in the election-scripts/create-dec.ts
file, insert the Voter's private key and save the file.
Then, deploy the contract encrypting the Voter's data with the command:
npx hardhat run election-scripts/create-dec.ts --network localhost
Take note of the DEC contract address returned by the script;
Write in the __mock__.ts
file the data required in the DECsRegistryData
. The data are retrieved by the previous scripts.
Then run the script in order to register the Voter DEC into the DECsRegistry:
npx hardhat run election-scripts/register-dec.ts --network localhost
At this point we have the EOA credentials and the DEC for our voters, and the DECs are registered on the DECs Registry. It's time to create an election: as an example we implemented a smart contract for a municipality election, that elects the mayor and the council.
Now it's time to deploy the smart contract election and register parties, councilor and mayor candidates, parties coalitions in the municipality election contract, run the command:
npx hardhat run election-scripts/create-election.ts --network localhost
Please note that to make the registration of parties and coalition working, the functions must be called in the registration period set before.
[COMING SOON...]