GithubHelp home page GithubHelp logo

secretballot's Introduction

Secret Ballot

We implement a private voting zkapp. The idea was to try to implement single stage private voting, say like on Twitter- one where participants do not need to register to vote first, as was done in Minataur. In a voting procedure with a registration step, users are required to make sure that sufficiently many people have signed up for voting before them but not voted and also that sufficient time has passed between their registration and voting transactions, so that their vote may be private. This can be difficult. Further, it seemed like bad UX. We also allow for the aggregation of user votes off-chain, which ensures a high voting throughput for the users.

Single stage voting

In our implementation, a centralized party (let's assume honest for now) sets up the voting contract (called secretBallot), which includes as state variables:

  1. a randomly chosen ballot_ID
  2. the root of the Merkle tree containing the hash of public keys contained in the list of voters
  3. the root of a Merkle tree storing the votes for different options
  4. a MerkleMap storing nullifiers (hash(private_key, ballot_ID)), which record whether a key has been used for voting or not.

In order, to vote, the user controlling the key pair (sk, pk) (secret/private key, public key) proves to the contract that:

  1. hash(pk) belongs in the voter list
  2. pk is derived from sk
  3. the hash(sk, ballot_ID) has not been used to vote before: nullifierMap[hash(sk, ballot_ID)] = 0.

Together these three imply that the user controls a sk which is eligible to vote but has not been used to vote yet (Note that we are placing some assumption on the amount of information that is leaked by these hashes, especially if the same sk is used for multiple votes; also see this for more information on nullifiers).

The user also needs to provide the correct witness and the number of votes for the option, he chooses to vote for.

The zkapp is implemented in secretBallot.ts and an example program using the vote function described above is in singleVote-main.ts.

Vote aggregation

We also provide the functionality to aggregate the votes of multiple voters into a single proof and use that to modify the on-chain state. This is achieved using the recursion feature of zk proofs on MINA. We follow the idea for implementing rollups described here.

The Structs and ZKPrograms required for aggregation are implemented and described in voteAggregation.ts. An example program, which generates multiple votes and aggregates them is presented in voteAggr-main.ts.

Best way to run

  1. Set the inputs in inputs.ts.

  2. Build the project

npm run build
  1. Create new keys
node build/src/createKeys.js
  1. Run the desired example file
node build/src/singleVote-main.js

or

node build/src/voteAggr-main.js

secretballot's People

Contributors

goforashutosh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.