Skip to content

Anonymous voting with homomorphic encryption #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Apr 16, 2025
Merged

Anonymous voting with homomorphic encryption #182

merged 38 commits into from
Apr 16, 2025

Conversation

tupui
Copy link
Owner

@tupui tupui commented Mar 23, 2025

Closes #128

Add an anonymous voting feature to the smart contract.

This PR also refactor the existing public voting logic as to accommodate for the private voting part. There is a new enum to specify a vote and its type can either be public or private. The respective enum/struct are specific to the vote type.

To maintain the privacy of votes, a commitment using the BLS12-381 is created. This requires that we keep the voting tally in a scalar field. As going back and forth the scalar field is possible, a seed is used to obfuscate the vote. This value encrypted using an asymmetric key and is stored on-chain (handling of the private key is out of scope for this PR as it has to be done on the frontend. We just store the public key on-chain so that anyone can vote.)

At the end of the voting process, we use the private key to decrypt all seeds and with the running tally of the votes we can recover the voting result.

For convenience, we store three tallies to represent the three possible voting states. The alternative was to use a middle point and do some +- but that's not straightforward and leads to some overflows, etc. TLDR; I think the 3 tally solution is a good alternative and actually does not restrict to 2 states. Imaging going with 4 states just with a single integer field. That would get quite messy, if even doable.

Since we have commitments for all votes, we can sum up the commitments and prove that we correctly decrypted the seeds and have the correct voting seed and voting tallies.

@tupui tupui added enhancement New feature or request rust Rust stuff soroban Stellar smart contract dao ODHack12 Non-Rewarded labels Mar 23, 2025
Copy link

netlify bot commented Mar 23, 2025

Deploy Preview for tansu canceled.

Name Link
🔨 Latest commit aa29c6a
🔍 Latest deploy log https://app.netlify.com/sites/tansu/deploys/680032d7fa275600086126f8

@tupui tupui moved this to In progress in SCF Journey - Tansu Mar 23, 2025
Copy link

netlify bot commented Mar 23, 2025

Deploy Preview for testnet-tansu ready!

Name Link
🔨 Latest commit aa29c6a
🔍 Latest deploy log https://app.netlify.com/sites/testnet-tansu/deploys/680032d72a399f0008dedade
😎 Deploy Preview https://deploy-preview-182--testnet-tansu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 63
Accessibility: 88
Best Practices: 83
SEO: 92
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@tupui tupui marked this pull request as draft March 24, 2025 19:38
@tupui
Copy link
Owner Author

tupui commented Apr 1, 2025

For now I pushed some code which only handles a single tally. I will add some tests and the full flow first and then add the other tallies once I am sure this is the way.

@tupui tupui marked this pull request as ready for review April 7, 2025 22:10
@tupui
Copy link
Owner Author

tupui commented Apr 8, 2025

Rebased and everything. Now I need to fix the public voting and could get this merged.

@tupui tupui merged commit 85b3bc5 into main Apr 16, 2025
12 checks passed
@tupui tupui deleted the anonimous_votes branch April 16, 2025 22:53
@github-project-automation github-project-automation bot moved this from In progress to Done in SCF Journey - Tansu Apr 16, 2025
@tupui
Copy link
Owner Author

tupui commented Apr 16, 2025

Ok giving this a go for v1 🚀 I will iterate now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dao enhancement New feature or request Non-Rewarded ODHack12 rust Rust stuff soroban Stellar smart contract
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Anonymous voting system - smart contract
2 participants