## 5 Proposed Solution
### Submitting Anonymous and Encrypted Votes  
Each voter encrypts his/her vote using the \(Enc\) algorithm, discussed in Section 4.2, using \(PP,t,x_{i},sk_{i},PP\) as an input, as follows. The voting ballot is shown in Figure 2. Each ballot \(B_{v_{i}}\) is divided into elements, where each element corresponds to one candidate and each voter selects the candidates by putting 1 in the element corresponding to this candidate. For instance, if the message size is 1000 bits and the number of candidates is five, the message is then divided into five elements, each of them a size of 200 bits. A voter \(v_{i}\) chooses \(d_{v_{i}}\stackrel{{\xi}}{{\leftarrow}}\mathbb{Z}_{p}\) and then computes \(\mathrm{vk}_{v_{i}}:=g_{1}^{d_{v_{i}}}\), and computes  
\[C_{B_{v_{i}}}=g_{1}^{B_{v_{i}}}H_{1}(\tau)^{s_{i}}H_{2}(\tau)^{t_{i}}\]  
and  
\[\sigma_{i}=h^{B_{v_{i}}}H_{3}(\tau)^{s_{i}}H_{4}(\tau)^{t_{i}}H_{5}(\tau)^{v_{ i}}\]The smart contract handles all of the necessary election logic and the smart contract voting scheme is summarized in Algorithm 1. To then cast a vote, the voters need to use the anonymous tokens described in Section 5.2 to be able to vote for their specific candidates, as follows. The voter uses the private key that corresponds to the token \(TP_{v_{i}}\) to sign and broadcast the following message to the blockchain:  
\[msg_{5}=\left(C_{B_{v_{i}}},\sigma_{i},vk_{i},sig_{O}(TP_{v_{i}}),\sigma(v_{i })\right),\]  
where \(\sigma(v_{i})\) is the signature on the whole message. Then, the blockchain should first verify if the voter is authenticated by checking the organizer's signature on the \(TP_{v_{i}}\) (\(sig_{O}(TP)\)), as follows. The _blockchain_ first computes \(A=c\cdot P\ +\ s\cdot G\). Then, it computes \(t=x\bmod n\), where \(x\) is the \(x\)-coordinate of point \(A\). The verifier checks if \(c\stackrel{{?}}{{=}}H(msg_{5}|t)\bmod n\). If the verification succeeds, then the blockchain continues to execute the smart contract Algorithm 1. In the example, the vote will only be written as a valid transaction if the voter has not cast a ballot already, the current time lies within the election start and end times, and the voter has their anonymous tokens described in Section 5.2. This logic solely utilizes the smart contract and data stored on the ledger, eliminating the need for external centralized databases during the election process.  
```
1 contractvoterContract
2 functionInitLedger(ctx)
3 WS\(\leftarrow\) voters//AddsvoterstoWorldState
4 WS\(\leftarrow\)votableItems//AddsvotableItemstoWorldState
5 WS\(\leftarrow\)election//AddsElectiontoWorldState
6 functionCastVote(ctx,voterID,electionID,votableItems)
7 newBallot(voterID,electionID,votableItems)//generateballotwithchoices ofvoter
8 logBallot()//Linktheballottothevoter
9//incrementcountofpickeditems
10 functionGetResults(ctx,electionID)
11//setresultsforallcandidatesto0
12 for\(s\gets 0\)toCandidates.lengthdo
13\(\big{|}\)Candidate[s].count=0
14 end//loopthroughallvoters
15//foreveryvotableItemonvoter'sballot,increasecandidate'scount
16 for\(s\gets 0\)tovoters.lengthdo
17 curBallot=voters[s].ballotfor\(v\gets 0\)tocurBallot.votableItems.lengthdo
18 curBallot.votableItems[v]+=len(election.VotableItems)-i
19 end
20 end
```  
**Algorithm 1** Pseudocode for _voterContract_ (Author's own processing)