I want to do something similar to a pet popularity contest dapp. From what I understand, it would involve non-interactive zero-knowledge proof.
There is an application with a list of pets competing in a popularity contest. Each pet has a popularity counter attached.
// Pseudo-code
petList = [Cobra, Elephant, Lion, Vulture]
petList[0].popularityMeasure = 0;
petList[1].popularityMeasure = 0;
petList[2].popularityMeasure = 0;
petList[3].popularityMeasure = 0;
Every person expresses a choice by calling a smart contract function like:
function sayMyChoice(witness) // witness is some sort of proof containing the name of the animal I'm opting for
Then the smart contract checks
function sayMyChoice(witness) {
for(int i=0; i<petList.length. i++) {
if(witness == petList[i])
petList[i].popularityMeasure+=1;
}
}
The counters should be public but you'd have no idea who opted for which pet.
My question is comprised of several parts:
- Is this possible with smart contracts and zk-snarks?
- If no, how could I do it?
- If yes, is there any tutorial implementing something similar using Solidity & JavaScript?
I guess the proof should be computed client-side, but the verification has to take place in a smart contract.