ZK Vote Architecture

Vote

group

contract IGroup group

signal

contract ISignal signal

VoteAdded

event VoteAdded(uint256 groupId, bytes32 voteMsg)

JoinRequested

event JoinRequested(uint256 groupId, uint256 identityCommitment)

voteStat

mapping(uint256 => mapping(bytes32 => uint256)) voteStat

GROUP_ID

uint256 GROUP_ID

idInGroup

mapping(uint256 => mapping(uint256 => bool)) idInGroup

admins

mapping(uint256 => address) admins

onlyAdmin

modifier onlyAdmin(uint256 id)

groupDesc

mapping(uint256 => string) groupDesc

groupIcon

mapping(uint256 => string) groupIcon

groupPrivacy

mapping(uint256 => string) groupPrivacy

groupName

mapping(uint256 => string) groupName

PRIVACY

enum PRIVACY {
  ANYONE,
  NFT,
  TOKEN
}

groupInfo

struct groupInfo {
  uint256 id;
  string name;
  string desc;
  string icon;
  enum Vote.PRIVACY privacy;
  address asset;
}

GroupInfo

event GroupInfo(uint256 groupId, string name, string desc, string icon, enum Vote.PRIVACY privacy, address asset)

groups

mapping(uint256 => struct Vote.groupInfo) groups

groupPolls

mapping(uint256 => mapping(uint256 => struct Poll)) groupPolls

groupPollNum

mapping(uint256 => uint256) groupPollNum

pollVoteStat

mapping(uint256 => mapping(uint256 => mapping(string => uint256))) pollVoteStat

PoolVoteAdded

event PoolVoteAdded(uint256 groupId, uint256 poolId, string voteMsg)

MemberAdded

event MemberAdded(uint256 groupId, uint256 identityCommitment)

initialize

function initialize(contract IGroup _group, contract ISignal _signal) external

createGroup

function createGroup(uint256 merkleTreeDepth, address admin) public returns (uint256)

CreateGroupExtra

function CreateGroupExtra(uint256 merkleTreeDepth, address admin, string name, string description, string privacy, string icon) public returns (uint256 groupId)

CreateGroupWithAssetDemand

function CreateGroupWithAssetDemand(uint256 merkleTreeDepth, address admin, string name, string description, enum Vote.PRIVACY privacy, string icon, address asset) public returns (uint256 groupId)

JoinRequest

function JoinRequest(uint256 groupId, uint256 identityCommitment) public

addMember

function addMember(uint256 groupId, uint256 identityCommitment) public

checkPrivacy

function checkPrivacy(uint256 groupId) public

PollAdded

event PollAdded(uint256 groupId, uint256 pollId, string title, string[] voteMsgs)

createPollInGroup

function createPollInGroup(uint256 groupId, string[] voteMsgs, string title) public returns (uint256 pollId)

votePollInGroup

function votePollInGroup(uint256 rc, uint256 groupId, uint256[8] group_proof, uint256 pollId, string voteMsg, uint256 nullifierHash, uint256 externalNullifier, uint256[8] signal_proof) public

voteInPoll

function voteInPoll(uint256 rc, uint256 groupId, uint256[8] group_proof, uint256 pollId, string voteMsg, uint256 nullifierHash, uint256[8] signal_proof) public

stringToBytes32

function stringToBytes32(string source) public pure returns (bytes32 result)

vote

function vote(uint256 rc, uint256 groupId, uint256[8] group_proof, bytes32 voteMsg, uint256 nullifierHash, uint256 externalNullifier, uint256[8] signal_proof) public

Decrypt

constructor

constructor() public

Example

verifier

address verifier

mulResult

uint256 mulResult

constructor

constructor(address verifier_) public

joinGameWithProof

function joinGameWithProof(uint256[2] a, uint256[2][2] b, uint256[2] c, uint256[2] input) external view

IVerifier

verifyProof

function verifyProof(uint256[2] a, uint256[2][2] b, uint256[2] c, uint256[2] input) external view

Group

verifiers

mapping(uint256 => contract IVerifier) verifiers

admins

mapping(uint256 => address) admins

onlyAdmin

modifier onlyAdmin(uint256 id)

updateGroupAdmin

function updateGroupAdmin(uint256 groupId, address newAdmin) external

constructor

constructor(struct IGroup.Verifier[] _verifiers) public

createGroup

function createGroup(uint256 groupId, uint256 merkleTreeDepth, address admin) public

addMember

function addMember(uint256 groupId, uint256 identityCommitment) public

updateMember

function updateMember(uint256 groupId, uint256 identityCommitment, uint256 newIdentityCommitment, uint256[] proofSiblings, uint8[] proofPathIndices) public

removeMember

function removeMember(uint256 groupId, uint256 identityCommitment, uint256[] proofSiblings, uint8[] proofPathIndices) public

verifyProof

function verifyProof(uint256 rc, uint256 groupId, uint256[8] proof) external view returns (bool)