PrivateVotingLib
Title: PrivateVotingLib
Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)
Library implementing anonymous one-person-one-vote polling over Semaphore groups. Each member votes once per poll via a Semaphore proof (scope = poll id, message = choice); the scope-bound nullifier enforces one ballot while the vote stays anonymous.
Three-layer pattern: this library holds the logic + namespaced storage; the stateless PrivateVoting facet forwards to it. Composes SemaphoreLib for the membership + ZK check (the ISemaphore module must be present in the same diamond and the group created there).
Functions
privateVotingStorage
function privateVotingStorage() internal pure returns (PrivateVotingStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | PrivateVotingStorage |
__PrivateVoting_init
Initializes the PrivateVoting module.
Must be called inside a pre/postInitializer block. Registers IPrivateVoting for ERC-165.
function __PrivateVoting_init() internal;registerInterface
Registers support for the IPrivateVoting interface via ERC-165.
function registerInterface() internal;createPoll
Creates a poll over groupId. Only the Semaphore group admin may create it.
function createPoll(uint256 groupId, uint32 numChoices, uint64 startTime, uint64 endTime)
internal
returns (uint256 pollId);Parameters
| Name | Type | Description |
|---|---|---|
| groupId | uint256 | |
| numChoices | uint32 | |
| startTime | uint64 | |
| endTime | uint64 |
Returns
| Name | Type | Description |
|---|---|---|
| pollId | uint256 |
vote
Casts an anonymous ballot. proof.scope must equal pollId; proof.message is the choice.
CEI: the nullifier is spent before the VoteCast event (no external interaction either way).
function vote(uint256 pollId, ISemaphore.SemaphoreProof calldata proof) internal;Parameters
| Name | Type | Description |
|---|---|---|
| pollId | uint256 | |
| proof | ISemaphore.SemaphoreProof |
pollCount
function pollCount() internal view returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getPoll
function getPoll(uint256 pollId) internal view returns (IPrivateVoting.PollView memory view_);Parameters
| Name | Type | Description |
|---|---|---|
| pollId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| view_ | IPrivateVoting.PollView |
getVotes
function getVotes(uint256 pollId, uint256 choice) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| pollId | uint256 | |
| choice | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
hasVoted
function hasVoted(uint256 pollId, uint256 nullifier) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| pollId | uint256 | |
| nullifier | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |