Is zk-snarks implementable in this use case-scenario?

108 views Asked by At

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:

  1. Is this possible with smart contracts and zk-snarks?
  2. If no, how could I do it?
  3. 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.

0

There are 0 answers