The MerkleVoting smart contract was written using the Motoko programming language and deployed on the Internet Computer (IC) blockchain. The contract utilizes two main actors, a Voter actor and a Candidate actor. The smart contract has an owner that can add candidates and administer the election phases.
The Internet Computer blockchain was chosen due to its significant transaction processing capabilities and low transaction fees. Using the IC would make the voting process scalable and financially feasible for any election. The IC's built-in identity management system (IC ID) could further enhance the voter experience by providing seamless authentication and KYC (Know Your Customer) capabilities.
By utilizing Merkle trees for voter eligibility verification, the smart contract provides an efficient way of handling large amounts of voter data. Using the setMerkleRoot function, the contract owner can set the Merkle root (generated offline) for the Merkle proofs to be checked against. When voting, the voter has to submit the Merkle proof (to be generated in the UI backend) together with the candidate number that should receive the vote. The Merkle proof is then checked against the Merkle root using the built-in cryptographic functions provided by the Motoko language.
The key benefits of using the Internet Computer blockchain and the Motoko programming language for this use case are:
Scalability: The Internet Computer's high transaction processing capabilities and low transaction fees make it well-suited for large-scale voting applications. Efficiency: The use of Merkle trees for voter eligibility verification allows for quick and efficient validation of voter data, even for large voter populations. Security: The Motoko language and the Internet Computer's built-in security features provide a secure environment for running the voting smart contract and processing sensitive voter data. Native Identity Management: The IC ID system simplifies the voter authentication and KYC processes, improving the overall user experience. To learn more before you start working with votecrypt, see the following documentation available online:
- Quick Start
- SDK Developer Tools
- Motoko Programming Language Guide
- Motoko Language Quick Reference
- JavaScript API Reference
If you want to start working on the project right away, you might want to try the following commands:
cd votecrypt/
dfx help
dfx canister --help
If you want to test your project locally, you can use the following commands:
# Starts the replica, running in the background
dfx start --background
# Deploys your canisters to the replica and generates your candid interface
dfx deploy
Once the job completes, your application will be available at http://localhost:4943?canisterId={asset_canister_id}
.
If you have made changes to your backend canister, you can generate a new candid interface with
npm run generate
at any time. This is recommended before starting the frontend development server, and will be run automatically any time you run dfx deploy
.
If you are making frontend changes, you can start a development server with
npm start
Which will start a server at http://localhost:8080
, proxying API requests to the replica at port 4943.
If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
- set
DFX_NETWORK
toic
if you are using Webpack - use your own preferred method to replace
process.env.DFX_NETWORK
in the autogenerated declarations- Setting
canisters -> {asset_canister_id} -> declarations -> env_override to a string
indfx.json
will replaceprocess.env.DFX_NETWORK
with the string in the autogenerated declarations
- Setting
- Write your own
createActor
constructor