A few weeks ago, we added the Voting Tutorial to the Cairo Docs – you may remember it from the Cairo & Storage post that referenced it as an example of how Cairo solves storage costs on Ethereum. If you didn’t have a chance to go through this tutorial yet, now would be a good time to do so. In this post, we will talk about what other use cases can be implemented with the same mechanism.
First, a quick review: We are implementing a dApp of a simple voting mechanism that can be used for secure (non-private) voting with a lot of users (i.e. voters) on a blockchain. Each user can vote once – either Yes or No. The dApp will collect the votes, verify the signature of each vote, tally the votes, and update the Merkle tree that holds its state. It will create a STARK proof attesting to the validity of this round of votes, and a commitment to the new (post-round) state. These will be sent on-chain to be verified (by a STARK Verifier smart contract) and stamped (in the Fact-Registry smart contract). The dApp’s smart contract will then check this stamp, and update its state accordingly. (if you need to refresh your memory on how it all works together, check out our “Cairo for Blockchain Developers” post)
That’s all very nice, and many a DAO can benefit from implementing this simple mechanism. But there’s more that can be achieved with the same basic code.
Signature Aggregation for Consensus
Say you are a sidechain. You have 150 validators and you need the signatures of at least 100 of them to achieve consensus. You want Ethereum to acknowledge that consensus has been reached on the latest block in your sidechain. For example, in order to construct a trustless bridge between tokens on your bridge and on Ethereum. The Cairo voting mechanism, which can record its results on Ethereum mainnet, is the perfect solution for you, after applying one small modification to it.
All you need to do is change the way the subject of the vote is handled: Instead of it being hard-coded, you make it a variable. Validators are then sent a message with the subject of the vote, which they can sign on, like, the latest block header of your sidechain. Yes votes are tallied in order to establish whether consensus on this subject has been reached. You got yourself a scaleable, trustless, signature aggregator, and built a trustless bridge to Ethereum.
What else will you build with a voting system? Join our discord server and share your ideas