E-VOTING SYSTEM BASED ON BLOCKCHAIN CSE1091 – Technical Answers for Real World Problems PROJECT REPORT By R Mukesh Kanna – 19BCE2385 Rulakshitha M – 19BCI0261 S K Shri Charan – 19BCE2404 School of Computer Science and Engineering 1 DECLARATION We hereby declare that the report entitled “E-VOTING SYSTEM BASED ON BLOCKCHAIN” submitted by us, for the CSE1901 Technical Answers for Real World Problems (EPJ) to VIT is a record of bonafide work carried out by us under the supervision of Prof. Jothi K R. We further declare that the work reported in this report has not been submitted and will not be submitted, either in part or in full, for any other courses in this institute or any other institute or university. Place : Vellore Date: 25/08/22 2 Acknowledgement In preparation of our project for CSE1901 Technical Answers for Real World Problems JComponent, we had to take the help and guidance of our professor Prof. Jothi K R, who deserves our deepest gratitude for giving us good guidelines for assignment throughout numerous consultations. We would also like to expand our gratitude to all those who have directly and indirectly guided us in writing this assignment. We also thank Vellore Institute of Technology for giving us the required resources and the opportunity to make this project, and the consent to include copyrighted pictures as a part of our paper. Many people, especially our classmates have made valuable comment suggestions on our paper which gave us an inspiration to improve the quality of the assignment. 3 INDEX Sl. No. Title Page No. 1. ABSTRACT 5 2.1 INTRODUCTION 5 2.2 Objective 5 2.3 Motivation 6 3 LITERATURE SURVEY 6 4 PROPOSED METHODOLOGY 9 5 DESIGN AND SETUP 9 6 ALGORITHM 15 7 RESULTS AND DISCUSSION 19 8 CONCLUSION 22 9 FUTURE WORK 22 10 REFERENCES 22 4 1.Abstract It's been difficult for a long time to create a safe electronic voting system that gives the transparency and flexibility provided by electronic systems, as well as the fairness and privacy supplied by present voting systems. In this project, we assess a blockchain based Ethereum application that will be used to construct distributed electronic voting systems. The project puts forth a brand-new electronic voting system built on blockchain that tackles some of the drawbacks of current systems and assesses some of the well-known blockchain frameworks in order to build an electronic voting system built on blockchain. Through the explanation of a case study, namely the election process and the deployment of a blockchain based application, which increases security and lowers the cost of hosting a national election, we specifically assess the potential of distributed ledger technology Introduction All participants in elections will benefit from e-voting systems. Election tasks, for instance, can be improved by administrators, and voters can participate in elections at any time and from any location. It is also better than the current voting system since ideal e-voting systems are transparent, complete (only voters have the right to vote, and their votes are correctly counted), and verifiable (voters may check that their vote is appropriately counted). Digital voting is the act of casting a ballot using an electronic device, such as a voting machine or a web browser. When voting online or through a voting machine in a polling place, these are commonly referred to as "e-voting." When thinking about putting up a computerised voting system, security is always the first worry. There can be no uncertainty about the system's ability to secure data and defend against prospective assaults when such significant decisions are at stake. Blockchain technology offers one potential means of resolving the security challenges.. Objective Blockchain technology originates from the underlying architectural design of the crypto currency bitcoin. It is a form of distributed database where records take the form of transactions, a block is a collection of these transactions. With the use of blockchains a secure and robust system for digital voting can be devised. To solve the problem, we propose a way to use the ring signature and the blockchain to ensure the features of the e-voting. The blockchain technology is characterized by decentralization, irreversibility, distribution of joint accounting, asymmetric encryption and datasecurity. 5 Motivation The current voting policies have too many flaws in the system. From camping on the poling booths to not let people vote to the tampering of the electronic voting machines (EVM’s). The main thing for a voting system is to gain the trust of people, when people know that their vote is actually worth something is being accounted. This will be making great impact on the future of our country. For this sole purpose we came up with the idea of this blockchain backed e-voting system which will ensure safety as well as anonymity of the voter. 3. Literature Review Blockchain for Electronic Voting System—Review and Open Research Challenges This study offers an introduction to the basic structure and properties of the blockchain in relation to electronic voting as well as a conceptual description of the anticipated blockchain-based electronic voting application. This investigation led to the discovery that some of the problems now plaguing election systems may be resolved by blockchain technologies. On the other side, privacy protection and transaction speed are the problems with blockchain applications that are most frequently raised. The security of remote participation must be practical for a blockchainbased electronic voting system to be scalable, and transaction speed needs to be addressed. These issues led to the conclusion that the current frameworks needed to be upgraded before being used in voting systems.. Secure Online Voting System Using Biometric and Blockchain This paper discusses an online voting system that satisfies all of the aforementioned system requirements. They used iris recognition to solve the problem of user authentication. One Time Password (OTP) was utilized as an additional security check. Additionally, they have made sure that a single, legitimate user cannot cast numerous votes. Another security measure used is the use of blockchain technology to allow decentralized, tamper-proof storage of data relating to users' biometric, personal information, and votes cast by them. As a result, they are not just concerned with user authentication but also with data security. The system's effectiveness has been evaluated for users from various age groups and socioeconomic backgrounds, and conclusions are given. 6 In this piece of research. Voting is frequently associated with politics and is completed through an exploitative and manual process in which individuals cast their ballots in support of their choices. Sometimes, manual voting can result in mistakes. As a result, an online voting mechanism must be used. The purpose of this is to upgrade voting technology from manual to digital. In this particular study, they planned to construct an online voting system with features similar to the programmes that the targeted party has put in place; based on these features, we'll cast our votes. The primary reason we need to switch from the traditional voting process to an online one is that we can vote online whenever we want and from any location. An Online Voting System based on Ethereum Block-Chain for Enhancing Reliability Transparency and secrecy will be guaranteed by using blockchain technology to conduct online voting because voter data and aggregate data are distributed and maintained. The cost of voting will be significantly lowered if blockchain technology is used in public elections and the confidentiality and openness of the voting information are assured. This study attempts to integrate the Ethereum platform, one of the blockchain technologies, into an online voting system. A smart contract based on the Solidity programming language can be created and distributed to each voter using Ethereum, a highly scalable blockchain technology. The votes are given to other voters once each voter casts a ballot on the distributed contract. The experiment confirms the accuracy of the recorded voting data. Towards a Privacy-Preserving Voting System Through Blockchain Technologies The intriguing issue of international vote tampering exists in current voting systems. The problems could not be fully resolved by digitisation alone. because there are still many methods to interfere with digital technology and undermine the voting process. They provide a blockchain application as a service for the distributed electronic voting system in order to create a secure electronic voting environment. They ensure data integrity through the usage of blockchain, which is a requirement for a voting environment. The major objective of this effort is to protect the privacy, anonymity, and security of the voting environment. All of the security concerns in the voting environment have been resolved through the architecture of our system and the use of blockchain E-Voting System Using Proof of Voting (PoV) Consensus Algorithm Using Blockchain Technology Both central and dispersed networks can be used in an e-voting system, however the fundamental drawback of a central network is that it has a single point of failure. Electronic medical records (EMR), the Internet of Things (IoT), and electronic voting are just a few examples of applications that use blockchain technology. In this work, a blockchain-based electronic voting system with a potent Proof-OfVoting (POV) consensus mechanism was built. In this study, they assess the legal concerns created by conventional approaches and discuss how blockchain technology can help us resolve them. In this study, they created a system using PoV that improves security and uses less money and energy 7 goes for E-voting he must register with his name and email on registration authority page and later when he will go for voting so Election authority page will verify his email or signature so by this algorithm, we resist the Fraud voting. Machine Learning with Blockchain for Secure E-voting System In the proposed model, They used the concepts of a personal and public blockchain. The personal blockchain is used for the purposes of voter registration and voting. The public blockchain is used to maintain the integrity of the personal data of the voters by storing the root hash derived from the Merkle hash tree and revealing the results of the voting stations as soon as the voting process is completed. The proposed blockchain-based e-voting system offers transparency, treasury, confidence and prevents intrusion into the information exchange network.. Automatic Voting System Using Convolutional Neural Network The proposed system develops an automatic voting system without any human intervention. This system includes a camera for capturing the images of electors, captured images will be stored in the database for analysis. data analysis will be performed on the database. In this method, all the label images are trained through the convolutional neural network to predict the output by classifying the images. This classification system produces an accuracy of approximately 90%. To reduce and eliminate the frauds and unethical practices during elections, an automatic voting system has been proposed using a Convolutional neural network, a deep learning technique and it is implemented using python. Online voting system using Face recognition and OTP They propose a system that includes multiple layers of verification to ensure the reliability of the device which includes face verification and then OTP verification with validation data. Each voter can access the system only when being recognized and checked with the given database of enlisted voters. Once the corresponding face is matched with the information provided, the voter will be allowed to proceed with choosing their preferred candidate from the panel. The basic idea of this system is to create an Online Voting System that will help to suppress deceive of the manual voting system and also the prior versions of online voting by a camera for Face Recognition and OTP generation. We are also implementing a locationfree voting system for the voters for whom it is not possible to come to the voting location. 8 4. Methodology We used Blockchain to build a decentralised application for voting in the Lok Sabha elections for our prototype. Our overarching goal for this project was to create a voting system that is significantly safer than the one we now use for our Lok Sabha elections. Consequently, blockchain was our top pick. One of the main causes is that all transactions on a blockchain are recorded and unchangeable after processing. Furthermore, we used Ganache to create a private Ethereum blockchain on our system in order to construct and deploy our blockchain-based voting application. The smart contract, which is nothing more than a legal programme or transaction protocol that abides by a specific set of rules and regulations, was set up to test and build the application after which we used Node.js to deploy it. According to a legal contract, these programs/protocols document certain events, control them, and execute automatically. Finally, to communicate with the smart contract, we used the Web3 frontend framework. For our product, we can set up a public blockchain similar to Ethereum with the same number of nodes as votes. Each voter will therefore have a distinct address on the network once the system has been installed on their devices. In a sense, each voter's hardware now functions as a singlevote personal EVM. 5. DESIGN AND SETUP 1. Smart Contract Ganache was developed to enable developers to develop distributed applications with ease, mainly oriented towards blockchain. With the help of Ganache, we can set up our own personal blockchain utilizing Ethereum as well as Corda. Why Ganache is preferred is that it can we utilized throughout the entire development cycle. This assiststhe developers to build, deploy and even test their distributed applications or dApps in a very safe deployment environment. As mentioned above, Ganache utilizes both Ethereum as well as Cordera. The entire software is very userfriendly; a command-line tool: ganache-cli or TestRPC can be used in the form of 10 a Ethereum based Ganache.This software is also platform friendly; It is supported by the most widely used operaring systems: Windows, Mac as well as Linux 2. Deploy the smart contract A smart contract is nothing but a legal program or transaction protocol that follows a certain set of rules and regulations; According to a legal contract these programs/protocols document certain events, control them and execute automatically. contract Voting { // structs struct VoteOption{ string name; uint count; } struct Poll { address owner; string name; string description; 9 uint start_time; uint end_time; uint fee; uint option_count; // Number of options mapping(uint => VoteOption ) options; // mapping of index+1 to options (should start from 1) string[] option_names; // array of option names; mapping(address => uint ) votes; // mapping of address to option_id (should start from 1) } // get polls return values as a struct struct GetVotesReturn { address[] poll_owners; string[] poll_names; string[] poll_descriptions; uint[] poll_start_times; uint[] poll_end_times; uint[] poll_fees; uint[] poll_ids; string[][] poll_options; uint[][] poll_options_votes; uint[] poll_voted_idxs; } // Variables uint polls_created; // Mapping of addresses to usernames mapping(address => string ) address_to_username; mapping(string => address ) username_to_address; mapping(uint => Poll) polls; // variables address public owner; // events event createPollEvt(uint pollId, address owner, string name, string description, uint start_time, uint end_time, uint fee, string[] options); constructor() { owner = msg.sender; } // Private Functions function validStr(string memory str) private pure returns(bool isValid) { return bytes(str).length >= 1; } // Public Functions 10 function createPoll(string memory name, string memory description, uint start_time, uint end_time, uint fee, string[] memory options) public { // Check string length require(validStr(name) && validStr(description)); // Check end time after start time require(end_time >= start_time); // Check more than one option require(options.length >= 2); // Check that options have valid names for (uint i=0; i<options.length; i++) { require(validStr(options[i])); } // Adding the poll Poll storage newPoll = polls[polls_created]; newPoll.owner = msg.sender; newPoll.name = name; newPoll.description = description; newPoll.start_time = start_time; newPoll.end_time = end_time; newPoll.fee = fee; newPoll.option_count = options.length; newPoll.option_names = options; // Adding the poll options for (uint i=0; i<options.length; i++) { VoteOption storage option = newPoll.options[newPoll.option_count+1]; option.name = options[i]; } emit createPollEvt(polls_created, msg.sender, name, description, start_time, end_time, fee, options); // Increment poll id polls_created++; } function getUser() public view returns(string memory username) { return address_to_username[msg.sender]; } function createUser(string memory username) public{ // Make checks to ensure user name is not empty && not taken && address not registered require(validStr(username)); address_to_username[msg.sender] = username; username_to_address[username] = msg.sender; } 11 function getPolls() public view returns (GetVotesReturn memory poll_data) { address[] memory owners = new address[](polls_created); string[] memory names = new string[](polls_created); string[] memory descriptions = new string[](polls_created); uint[] memory start_times = new uint[](polls_created); uint[] memory end_times = new uint[](polls_created); uint[] memory fees = new uint[](polls_created); uint[] memory poll_ids = new uint[](polls_created); uint[] memory voted_idxs = new uint[](polls_created); // array of arrays for options string[][] memory option_list = new string[][](polls_created); // array of arrays for options votes uint[][] memory option_vote_list = new uint[][](polls_created); for (uint i=0; i<polls_created; i++) { owners[i] = polls[i].owner; names[i] = polls[i].name; descriptions[i] = polls[i].description; start_times[i] = polls[i].start_time; end_times[i] = polls[i].end_time; fees[i] = polls[i].fee; poll_ids[i] = i; voted_idxs[i] = polls[i].votes[msg.sender]; // get option_count from poll uint option_count = polls[i].option_count; uint[] memory option_votes = new uint[](option_count); for (uint j=0; j<option_count; j++) { VoteOption memory option = polls[i].options[j+1]; option_votes[j] = option.count; } // add options to option_list option_list[i] = polls[i].option_names; // add options_votes to option_vote_list option_vote_list[i] = option_votes; } return GetVotesReturn(owners, names, descriptions, start_times, end_times, fees, poll_ids, option_list, option_vote_list, voted_idxs); } function vote(uint poll_id, uint option_id) payable public { // Check that poll exists require(poll_id < polls_created, "Poll does not exist"); // Check that option exists require(option_id < polls[poll_id].option_count, "Option does not exist"); // Check that user has not already voted require(polls[poll_id].votes[msg.sender] == 0, "User has already voted"); // Check that user has not voted in the future 12 require(polls[poll_id].start_time <= block.timestamp, "User has tried voting in the future"); // Check that user has not voted in the past require(polls[poll_id].end_time >= block.timestamp, "User has tried voting for the past"); // Check that user has enough balance require(msg.value >= polls[poll_id].fee, "User does not have enough balance"); // set poll.votes of user to option_id polls[poll_id].votes[msg.sender] = option_id+1; polls[poll_id].options[option_id+1].count++; // transfer the balance to the poll owner payable(polls[poll_id].owner).transfer(polls[poll_id].fee); } } }); 3. Update the contract address in index.js As mentioned earlier, at a specific address in every Ethereum blockchain, we will encounter a collection of code along with data. This collection residing in that particular address is the contract and its address is nothing but the contract address. Contracts live on the blockchain in an Ethereum-specific binary format called Ethereum Virtual Machine (EVM) bytecode. This specific address where the contract resides has the ETH preserved. The ETH in simple terms is nothing but the notion of the public key created for cryptographic security purposes; This notion is represented in the hexadecimal form & hence starts with ‘0x’. Basically, the contract address is used for communicating the ETH, wherein every transaction is logged and immutable as it has its own unique number 13 4. Open index.html Evidently, index.html is the main go to file for testing our Blockchain-based voting system. If the votes are initialized then the system is working.. 14 6. ALGORITHM Code [primary code files] contract Voting { // structs struct VoteOption{ string name; uint count; } struct Poll { address owner; string name; string description; uint start_time; uint end_time; uint fee; uint option_count; // Number of options mapping(uint => VoteOption ) options; // mapping of index+1 to options (should start from 1) string[] option_names; // array of option names; mapping(address => uint ) votes; // mapping of address to option_id (should start from 1) } // get polls return values as a struct struct GetVotesReturn { address[] poll_owners; string[] poll_names; string[] poll_descriptions; uint[] poll_start_times; uint[] poll_end_times; uint[] poll_fees; uint[] poll_ids; string[][] poll_options; uint[][] poll_options_votes; uint[] poll_voted_idxs; } // Variables uint polls_created; // Mapping of addresses to usernames mapping(address => string ) address_to_username; mapping(string => address ) username_to_address; mapping(uint => Poll) polls; // variables address public owner; // events event createPollEvt(uint pollId, address owner, string name, string description, uint start_time, uint end_time, uint fee, string[] options); constructor() { 15 owner = msg.sender; } // Private Functions function validStr(string memory str) private pure returns(bool isValid) { return bytes(str).length >= 1; } // Public Functions function createPoll(string memory name, string memory description, uint start_time, uint end_time, uint fee, string[] memory options) public { // Check string length require(validStr(name) && validStr(description)); // Check end time after start time require(end_time >= start_time); // Check more than one option require(options.length >= 2); // Check that options have valid names for (uint i=0; i<options.length; i++) { require(validStr(options[i])); } // Adding the poll Poll storage newPoll = polls[polls_created]; newPoll.owner = msg.sender; newPoll.name = name; newPoll.description = description; newPoll.start_time = start_time; newPoll.end_time = end_time; newPoll.fee = fee; newPoll.option_count = options.length; newPoll.option_names = options; // Adding the poll options for (uint i=0; i<options.length; i++) { VoteOption storage option = newPoll.options[newPoll.option_count+1]; option.name = options[i]; } emit createPollEvt(polls_created, msg.sender, name, description, start_time, end_time, fee, options); // Increment poll id polls_created++; } function getUser() public view returns(string memory username) { return address_to_username[msg.sender]; } function createUser(string memory username) public{ // Make checks to ensure user name is not empty && not taken && address not registered require(validStr(username)); address_to_username[msg.sender] = username; 16 username_to_address[username] = msg.sender; } function getPolls() public view returns (GetVotesReturn memory poll_data) { address[] memory owners = new address[](polls_created); string[] memory names = new string[](polls_created); string[] memory descriptions = new string[](polls_created); uint[] memory start_times = new uint[](polls_created); uint[] memory end_times = new uint[](polls_created); uint[] memory fees = new uint[](polls_created); uint[] memory poll_ids = new uint[](polls_created); uint[] memory voted_idxs = new uint[](polls_created); // array of arrays for options string[][] memory option_list = new string[][](polls_created); // array of arrays for options votes uint[][] memory option_vote_list = new uint[][](polls_created); for (uint i=0; i<polls_created; i++) { owners[i] = polls[i].owner; names[i] = polls[i].name; descriptions[i] = polls[i].description; start_times[i] = polls[i].start_time; end_times[i] = polls[i].end_time; fees[i] = polls[i].fee; poll_ids[i] = i; voted_idxs[i] = polls[i].votes[msg.sender]; // get option_count from poll uint option_count = polls[i].option_count; uint[] memory option_votes = new uint[](option_count); for (uint j=0; j<option_count; j++) { VoteOption memory option = polls[i].options[j+1]; option_votes[j] = option.count; } // add options to option_list option_list[i] = polls[i].option_names; // add options_votes to option_vote_list option_vote_list[i] = option_votes; } return GetVotesReturn(owners, names, descriptions, start_times, end_times, fees, poll_ids, option_list, option_vote_list, voted_idxs); } function vote(uint poll_id, uint option_id) payable public { // Check that poll exists require(poll_id < polls_created, "Poll does not exist"); // Check that option exists require(option_id < polls[poll_id].option_count, "Option does not exist"); // Check that user has not already voted require(polls[poll_id].votes[msg.sender] == 0, "User has already voted"); // Check that user has not voted in the future require(polls[poll_id].start_time <= block.timestamp, "User has tried voting in the future"); 17 // Check that user has not voted in the past require(polls[poll_id].end_time >= block.timestamp, "User has tried voting for the past"); // Check that user has enough balance require(msg.value >= polls[poll_id].fee, "User does not have enough balance"); // set poll.votes of user to option_id polls[poll_id].votes[msg.sender] = option_id+1; polls[poll_id].options[option_id+1].count++; // transfer the balance to the poll owner payable(polls[poll_id].owner).transfer(polls[poll_id].fee); } } Index.js import Head from "next/head"; import Link from "next/link"; import { routes } from "../components/Sidebar"; export default function Home() { return ( <> <Head> <title>Voting DAPP</title> <meta name="description" content="Voting DAPP on Polygon" /> <link rel="icon" href="/favicon.ico" /> </Head> <main className="p-10"> Dummy Voting dApp Page <br /> {routes.map((route, i) => ( <Link key={i} href={route.path}><a className="block textprimary">{route.name}</a></Link> ))} <Link href="/404"><a className="text-primary block">404 page</a></Link> <Link href="/login"><a className="text-primary block">Login page</a></Link> </main> </> ); } 18 7. Results & Discussion Dashboard The user can see the active polls and the recent polls created in this field 19 Create a poll The user can create a new poll in this tab. Fill a poll In this tab the user can fill a poll that is created already. Each poll created will be assigned with a unique id. The user can use the id to vote the respective poll. 20 Poll history This tab is created for the purpose that the user can check out the poll that has been created in which the unique id will be displayed. 21 8. CONCLUSION We were successful in creating a prototype which can help us visualize our core idea. A core idea in a broader sense was to develop a mire secure platform or application for casting votes, specifically for our Lok Sabha Elections as we all know that certain malpractices are still prevalent. This was possible with the intense logging and high security of Ethereum-based Blockchain, which we had used to deploy our application.. Further this can be scaled into a product and can be implemented on a scale. This prototype is a proof that blockchain can bring in the revolution needed by voters and citizens of 21st century. 9. FUTURE WORK Unlike cloud-based applications, our private Ethereum-based Blockchain voting application requires new verified users to download and setup the previous blockchain setup in order to add themselves to the existing system. This is a tedious task especially in real time when we can expect thousands of users. Therefore, further work can be to research and come up with more feasible and effective ways of voter authentication, at the same time to sustain the high security factor fir casting vote in our Lok Sabha election. 10. References 1. Hjálmarsson, F. Þ., Hreiðarsson, G. K., Hamdaqa, M., & Hjálmtýsson, G. (2018, July). Blockchain-based e-voting system. In 2018 IEEE 11th International Conference on Cloud Computing (CLOUD) (pp. 983-986). IEEE. 2. Khan, K. M., Arshad, J., & Khan, M. M. (2018). Secure digital voting system based on blockchain technology. International Journal of Electronic Government Research (IJEGR), 14(1), 53-62. 3. Bulut, R., Kantarcı, A., Keskin, S., & Bahtiyar, Ş. (2019, September). Blockchain-Based Electronic Voting System for Elections in Turkey. In 2019 4th International Conference on Computer Science and Engineering (UBMK) (pp. 183-188). IEEE. 4. Barnes, A., Brake, C., & Perry, T. (2016). Digital Voting with the use of Blockchain Technology. Team Plymouth Pioneers-Plymouth University. 5. Patil, H. V., Rathi, K. G., & Tribhuwan, M. V. (2018). A study on decentralized e-voting system using blockchain technology. Int. Res. J. Eng. Technol, 5(11), 48-53. 22 6. Panja, S., & Roy, B. K. (2018). A secure end-to-end verifiable e-voting system using zero knowledge based blockchain. IACR Cryptology ePrint Archive, 2018, 466 7. Pawlak, M., Poniszewska-Marańda, A., & Kryvinska, N. (2018). Towards the intelligent agents for blockchain e-voting system. Procedia Computer Science, 141, 239-246 8. Wu, Y. (2017). An e-voting system based on blockchain and ring signature. Master. University of Birmingham. 9. Yavuz, E., Koç, A. K., Çabuk, U. C., & Dalkılıç, G. (2018, March). Towards secure evoting using Ethereum blockchain. In 2018 6th International Symposium on Digital Forensic and Security (ISDFS) (pp. 1-7). IEEE. 10. Çabuk, U. C., Adıgüzel, E., & Karaarslan, E. A Survey on Feasibility and Suitability of Blockchain Techniques for the E-Voting Systems. 11. Pilkington, M. (2016). 11 Blockchain technology: principles and applications. Research handbook on digital transformations, 225 23