2022-09-22 01:59:33 +03:00
|
|
|
<!-- # 🗳️ Vote -->
|
2023-07-24 20:33:41 +03:00
|
|
|
|
|
|
|
[//]: # (<img alt="workshop/vote" width="1412" src="../.resources/vote.png">)
|
2022-09-20 00:52:55 +03:00
|
|
|
|
|
|
|
## Summary
|
|
|
|
|
|
|
|
`vote.leo` is a general vote program.
|
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
Anyone can issue new proposals,
|
|
|
|
proposers can issue tickets to the voters,
|
|
|
|
and voters can vote without exposing their identity.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
|
|
|
This example is inspired by the [aleo-vote](https://github.com/zkprivacy/aleo-vote) example written by the Aleo community.
|
|
|
|
|
|
|
|
## Noteworthy Features
|
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
Voter identity is concealed by privately passing a voter's ballot into a function.
|
|
|
|
Proposal information and voting results are revealed using the public `mapping` datatype in Leo.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
|
|
|
## How to Run
|
|
|
|
|
|
|
|
To compile this Leo program, run:
|
|
|
|
```bash
|
2023-07-20 04:04:09 +03:00
|
|
|
leo run <function_name> <input_1> <input_2>
|
2022-09-20 00:52:55 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Make changes to `vote/inputs/vote.in` before running each command.
|
|
|
|
|
|
|
|
### Propose
|
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
Anyone can issue a new proposal publicly by calling `propose` function.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
|
|
|
Run `propose`:
|
|
|
|
|
|
|
|
```
|
|
|
|
leo run propose
|
|
|
|
```
|
|
|
|
|
|
|
|
Output sample:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
owner: aleo1kkk52quhnxgn2nfrcd9jqk7c9x27c23f2wvw7fyzcze56yahvcgszgttu2.private,
|
|
|
|
id: 2805252584833208809872967597325381727971256629741137995614832105537063464740field.private,
|
|
|
|
info: {
|
|
|
|
title: 2077160157502449938194577302446444field.private,
|
|
|
|
content: 1452374294790018907888397545906607852827800436field.private,
|
|
|
|
proposer: aleo1kkk52quhnxgn2nfrcd9jqk7c9x27c23f2wvw7fyzcze56yahvcgszgttu2.private
|
|
|
|
},
|
|
|
|
_nonce: 1639660347839832220966145410710039205878572956621820215177036061076060242021group.public
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Create Ticket
|
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
Proposers can create new tickets for proposed proposals.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
Ticket is a record with `owner` and `pid`,
|
|
|
|
it can be used to vote for the specific proposal - `pid`,
|
|
|
|
and can only be used(voted) by the ticket `owner`.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
|
|
|
Run `new_ticket`:
|
|
|
|
|
|
|
|
```
|
2022-09-22 01:59:33 +03:00
|
|
|
leo run new_ticket
|
2022-09-20 00:52:55 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Output sample:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
owner: aleo1kkk52quhnxgn2nfrcd9jqk7c9x27c23f2wvw7fyzcze56yahvcgszgttu2.private,
|
|
|
|
pid: 2264670486490520844857553240576860973319410481267184439818180411609250173817field.private,
|
|
|
|
_nonce: 1637267040221574073903539416642641433705357302885235345311606754421919550724group.public
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Vote
|
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
A ticket owner can use their ticket record to vote `agree` / `disagree` with the specific proposal - `pid`.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
2022-09-20 10:09:14 +03:00
|
|
|
Since the ticket record can be used as an input privately, the voter's privacy is protected.
|
2022-09-20 00:52:55 +03:00
|
|
|
|
|
|
|
Run `agree`:
|
|
|
|
|
|
|
|
```
|
|
|
|
leo run agree
|
|
|
|
```
|
|
|
|
|
|
|
|
Run `disagree`:
|
|
|
|
|
|
|
|
```
|
|
|
|
leo run disagree
|
|
|
|
```
|