Breaking down the Aleo example: Voting

Kaylej
3 min readMar 20, 2023

--

In this article, we will analyze an example of a program that allows you to implement a primitive voting process on the Aleo blockchain. Since Aleo is a private environment, it is obvious that the principle of operation here is not similar to other programs operating in public blockchains. Let’s look at the main differences:

  • Specifically in the example below, no one can know who the voter voted for. However, the addresses of the voters is known to the one who created the vote, since he is the one who provided the addresses with the opportunity to vote.
  • This is not a DAO. Basically, relying on the experience of public blockchains, we can see how owners of any tokens participate in votes where the weight of the vote is commensurate with the number of tokens the voter has. In our case, however, all votes have the same weight, and the example below should not be compared to a DAO.

Let’s proceed with the basis of the contract:

Let’s create a “Proposal” template. There will be 4 variables with information where one of them is complex (ProposalInfo contains 3 variables, we will add this structure to the mapping separately and make it public).

Then we will create a mapping for displaying public information, we will also make a template for the ticket and public mapping for counting votes:

Now let’s move on to a separate function that can be called by anyone.

The code itself
Inputs

The function propose authenticates (checks) the person who creates the proposal, then generates an id for the offer and creates a new field in the public mapping tickets.

Then the function new_ticket which creates a ticket for the specified address (who can then vote):

Next the functions for voting:

It is important to note that the addresses of those who voted “for” or “against” are not saved to any public mappings, the “agree” and “disagree” functions only increase the number in the counter by 1.

It is important to note that this is a demo for implementing voting on the Aleo blockchain, and it is not suitable for real-world use. Here, for example, there is still no check for repeated votes from the same address.

Original version: https://medium.com/@kaylej/dea05105d653

--

--