Poll
A representation of the Poll contract.
Implements
IPoll
Table of contents
Constructors
Properties
- MM
- WW
- ballotTree
- ballots
- batchSizes
- cbi
- commands
- coordinatorKeypair
- currentMessageBatchIndex
- emptyBallot
- emptyBallotHash
- encPubKeys
- maciStateRef
- maxValues
- messageTree
- messages
- numBatchesProcessed
- numBatchesTallied
- numSignups
- perVOSpentVoiceCredits
- pollEndTimestamp
- pollId
- preVOSpentVoiceCreditsRootSalts
- rbi
- resultRootSalts
- sbSalts
- spentVoiceCreditSubtotalSalts
- stateCopied
- stateLeaves
- stateTree
- stateTreeDepth
- subsidy
- subsidySalts
- tallyResult
- totalSpentVoiceCredits
- treeDepths
Methods
- coefficientCalculation
- copy
- equals
- genPerVOSpentVoiceCreditsCommitment
- genProcessMessagesCircuitInputsPartial
- genSpentVoiceCreditSubtotalCommitment
- getNumSignups
- hasUnfinishedSubsidyCalculation
- hasUnprocessedMessages
- hasUntalliedBallots
- increaseSubsidyIndex
- previousSubsidyIndexToString
- processAllMessages
- processMessage
- processMessages
- publishMessage
- setCoordinatorKeypair
- setNumSignups
- subsidyCalculation
- subsidyPerBatch
- tallyVotes
- tallyVotesNonQv
- toJSON
- topupMessage
- updatePoll
- fromJSON
Constructors
constructor
• new Poll(pollEndTimestamp
, coordinatorKeypair
, treeDepths
, batchSizes
, maxValues
, maciStateRef
): Poll
Constructs a new Poll object.
Parameters
Name | Type | Description |
---|---|---|
pollEndTimestamp | bigint | The Unix timestamp at which the poll ends. |
coordinatorKeypair | Keypair | The keypair of the coordinator. |
treeDepths | TreeDepths | The depths of the trees used in the poll. |
batchSizes | BatchSizes | The sizes of the batches used in the poll. |
maxValues | MaxValues | The maximum values the MACI circuits can accept. |
maciStateRef | MaciState | The reference to the MACI state. |
Returns
Defined in
Poll.ts:146
Properties
MM
• MM: number
= 50
Defined in
Poll.ts:124
WW
• WW: number
= 4
Defined in
Poll.ts:126
ballotTree
• Optional
ballotTree: IncrementalQuinTree
Defined in
Poll.ts:73
ballots
• ballots: Ballot
[] = []
Defined in
Poll.ts:71
batchSizes
• batchSizes: BatchSizes
Defined in
Poll.ts:62
cbi
• cbi: number
= 0
Defined in
Poll.ts:122
commands
• commands: ICommand
[] = []
Defined in
Poll.ts:79
coordinatorKeypair
• coordinatorKeypair: Keypair
Defined in
Poll.ts:58
currentMessageBatchIndex
• Optional
currentMessageBatchIndex: number
Defined in
Poll.ts:92
emptyBallot
• emptyBallot: Ballot
Defined in
Poll.ts:130
emptyBallotHash
• Optional
emptyBallotHash: bigint
Defined in
Poll.ts:132
encPubKeys
• encPubKeys: PubKey
[] = []
Defined in
Poll.ts:81
maciStateRef
• maciStateRef: MaciState
Defined in
Poll.ts:94
maxValues
• maxValues: MaxValues
Defined in
Poll.ts:64
messageTree
• messageTree: IncrementalQuinTree
Defined in
Poll.ts:77
messages
• messages: Message
[] = []
Defined in
Poll.ts:75
numBatchesProcessed
• numBatchesProcessed: number
= 0
Defined in
Poll.ts:90
numBatchesTallied
• numBatchesTallied: number
= 0
Defined in
Poll.ts:111
numSignups
• Private
numSignups: bigint
Defined in
Poll.ts:135
perVOSpentVoiceCredits
• perVOSpentVoiceCredits: bigint
[] = []
Defined in
Poll.ts:109
pollEndTimestamp
• pollEndTimestamp: bigint
Defined in
Poll.ts:69
pollId
• pollId: bigint
Defined in
Poll.ts:96
preVOSpentVoiceCreditsRootSalts
• preVOSpentVoiceCreditsRootSalts: Record
<string
| number
, bigint
> = {}
Defined in
Poll.ts:102
rbi
• rbi: number
= 0
Defined in
Poll.ts:120
resultRootSalts
• resultRootSalts: Record
<string
| number
, bigint
> = {}
Defined in
Poll.ts:100
sbSalts
• sbSalts: Record
<string
| number
, bigint
> = {}
Defined in
Poll.ts:98
spentVoiceCreditSubtotalSalts
• spentVoiceCreditSubtotalSalts: Record
<string
| number
, bigint
> = {}
Defined in
Poll.ts:104
stateCopied
• stateCopied: boolean
= false
Defined in
Poll.ts:83
stateLeaves
• stateLeaves: StateLeaf
[]
Defined in
Poll.ts:85
stateTree
• Optional
stateTree: IncrementalQuinTree
Defined in
Poll.ts:87
stateTreeDepth
• stateTreeDepth: number
Defined in
Poll.ts:67
subsidy
• subsidy: bigint
[] = []
Defined in
Poll.ts:116
subsidySalts
• subsidySalts: Record
<string
| number
, bigint
> = {}
Defined in
Poll.ts:118
tallyResult
• tallyResult: bigint
[] = []
Defined in
Poll.ts:107
totalSpentVoiceCredits
• totalSpentVoiceCredits: bigint
Defined in
Poll.ts:113
treeDepths
• treeDepths: TreeDepths
Defined in
Poll.ts:60
Methods
coefficientCalculation
▸ coefficientCalculation(rowBallot
, colBallot
): bigint
This method calculates the coefficient for a pair of ballots.
Parameters
Name | Type | Description |
---|---|---|
rowBallot | Ballot | The ballot in the row. |
colBallot | Ballot | The ballot in the column. |
Returns
bigint
Returns the calculated coefficient.
Defined in
Poll.ts:1025
copy
▸ copy(): Poll
Create a deep copy of the Poll object.
Returns
A new instance of the Poll object with the same properties.
Implementation of
IPoll.copy
Defined in
Poll.ts:1454
equals
▸ equals(p
): boolean
Check if the Poll object is equal to another Poll object.
Parameters
Name | Type | Description |
---|---|---|
p | Poll | The Poll object to compare. |
Returns
boolean
True if the two Poll objects are equal, false otherwise.
Implementation of
IPoll.equals
Defined in
Poll.ts:1540
genPerVOSpentVoiceCreditsCommitment
▸ genPerVOSpentVoiceCreditsCommitment(salt
, numBallotsToCount
, useQuadraticVoting?
): bigint
This method generates a commitment to the spent voice credits per vote option.
This is the hash of the Merkle root of the spent voice credits per vote option and a salt, computed as Poseidon([root, _salt]).
Parameters
Name | Type | Default value | Description |
---|---|---|---|
salt | bigint | undefined | The salt used in the hash function. |
numBallotsToCount | number | undefined | The number of ballots to count for the calculation. |
useQuadraticVoting | boolean | true | Whether to use quadratic voting or not. Default is true. |
Returns
bigint
Returns the hash of the Merkle root of the spent voice credits per vote option and a salt, computed as Poseidon([root, _salt]).
Defined in
Poll.ts:1428
genProcessMessagesCircuitInputsPartial
▸ genProcessMessagesCircuitInputsPartial(index
): CircuitInputs
Generates partial circuit inputs for processing a batch of messages
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the partial batch. |
Returns
stringified partial circuit inputs
Defined in
Poll.ts:776
genSpentVoiceCreditSubtotalCommitment
▸ genSpentVoiceCreditSubtotalCommitment(salt
, numBallotsToCount
, useQuadraticVoting?
): bigint
This method generates a commitment to the total spent voice credits.
This is the hash of the total spent voice credits and a salt, computed as Poseidon([totalCredits, _salt]).
Parameters
Name | Type | Default value | Description |
---|---|---|---|
salt | bigint | undefined | The salt used in the hash function. |
numBallotsToCount | number | undefined | The number of ballots to count for the calculation. |
useQuadraticVoting | boolean | true | Whether to use quadratic voting or not. Default is true. |
Returns
bigint
Returns the hash of the total spent voice credits and a salt, computed as Poseidon([totalCredits, _salt]).
Defined in
Poll.ts:1400
getNumSignups
▸ getNumSignups(): bigint
Get the number of signups
Returns
bigint
The number of signups
Defined in
Poll.ts:1665
hasUnfinishedSubsidyCalculation
▸ hasUnfinishedSubsidyCalculation(): boolean
This method checks if there are any unfinished subsidy calculations.
Returns
boolean
Returns true if the product of the row batch index (rbi) and batch size or the product of column batch index (cbi) and batch size is less than the length of the ballots array, indicating that there are still ballots left to be processed. Otherwise, it returns false.
Implementation of
IPoll.hasUnfinishedSubsidyCalculation
Defined in
Poll.ts:906
hasUnprocessedMessages
▸ hasUnprocessedMessages(): boolean
This method checks if there are any unprocessed messages in the Poll instance.
Returns
boolean
Returns true if the number of processed batches is less than the total number of batches, false otherwise.
Implementation of
IPoll.hasUnprocessedMessages
Defined in
Poll.ts:411
hasUntalliedBallots
▸ hasUntalliedBallots(): boolean
Checks whether there are any untallied ballots.
Returns
boolean
Whether there are any untallied ballots
Implementation of
IPoll.hasUntalliedBallots
Defined in
Poll.ts:897
increaseSubsidyIndex
▸ increaseSubsidyIndex(): void
It increases the index for the subsidy calculation.
Returns
void
Defined in
Poll.ts:980
previousSubsidyIndexToString
▸ previousSubsidyIndexToString(): string
This method converts the previous subsidy index to a string.
Returns
string
Returns a string representation of the previous subsidy index. The string is in the format "rbi-cbi", where rbi and cbi are the previous row batch index and column batch index respectively.
Defined in
Poll.ts:997
processAllMessages
▸ processAllMessages(): Object
Process all messages. This function does not update the ballots or state leaves; rather, it copies and then updates them. This makes it possible to test the result of multiple processMessage() invocations.
Returns
Object
The state leaves and ballots of the poll
Name | Type |
---|---|
ballots | Ballot [] |
stateLeaves | StateLeaf [] |
Implementation of
IPoll.processAllMessages
Defined in
Poll.ts:881
processMessage
▸ processMessage(message
, encPubKey
, qv?
): IProcessMessagesOutput
Process one message.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
message | Message | undefined | The message to process. |
encPubKey | PubKey | undefined | The public key associated with the encryption private key. |
qv | boolean | true | - |
Returns
IProcessMessagesOutput
A number of variables which will be used in the zk-SNARK circuit.
Defined in
Poll.ts:225
processMessages
▸ processMessages(pollId
, qv?
, quiet?
): IProcessMessagesCircuitInputs
Process _batchSize messages starting from the saved index. This function will process messages even if the number of messages is not an exact multiple of _batchSize. e.g. if there are 10 messages, index is 8, and _batchSize is 4, this function will only process the last two messages in this.messages, and finally update the zeroth state leaf. Note that this function will only process as many state leaves as there are ballots to prevent accidental inclusion of a new user after this poll has concluded.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
pollId | bigint | undefined | The ID of the poll associated with the messages to process |
qv | boolean | true | - |
quiet | boolean | true | Whether to log errors or not |
Returns
stringified circuit inputs
Implementation of
IPoll.processMessages
Defined in
Poll.ts:437
publishMessage
▸ publishMessage(message
, encPubKey
): void
Inserts a Message and the corresponding public key used to generate the ECDH shared key which was used to encrypt said message.
Parameters
Name | Type | Description |
---|---|---|
message | Message | The message to insert |
encPubKey | PubKey | The public key used to encrypt the message |
Returns
void
Implementation of
IPoll.publishMessage
Defined in
Poll.ts:372
setCoordinatorKeypair
▸ setCoordinatorKeypair(serializedPrivateKey
): void
Set the coordinator's keypair
Parameters
Name | Type | Description |
---|---|---|
serializedPrivateKey | string | the serialized private key |
Returns
void
Implementation of
IPoll.setCoordinatorKeypair
Defined in
Poll.ts:1649
setNumSignups
▸ setNumSignups(numSignups
): void
Set the number of signups to match the ones from the contract
Parameters
Name | Type | Description |
---|---|---|
numSignups | bigint | the number of signups |
Returns
void
Defined in
Poll.ts:1657
subsidyCalculation
▸ subsidyCalculation(rowStartIndex
, colStartIndex
): Ballot
[][]
This method calculates the subsidy for a batch of ballots.
Parameters
Name | Type | Description |
---|---|---|
rowStartIndex | number | The starting index for the row ballots. |
colStartIndex | number | The starting index for the column ballots. |
Returns
Ballot
[][]
Returns a 2D array of ballots. The first array contains the row ballots and the second array contains the column ballots.
Defined in
Poll.ts:1040
subsidyPerBatch
▸ subsidyPerBatch(): ISubsidyCircuitInputs
This method calculates the subsidy per batch.
Returns
Returns an array of big integers which represent the circuit inputs for the subsidy calculation.
Implementation of
IPoll.subsidyPerBatch
Defined in
Poll.ts:915
tallyVotes
▸ tallyVotes(): ITallyCircuitInputs
This method tallies a ballots and updates the tally results.
Returns
the circuit inputs for the TallyVotes circuit.
Implementation of
IPoll.tallyVotes
Defined in
Poll.ts:1079
tallyVotesNonQv
▸ tallyVotesNonQv(): ITallyCircuitInputs
Returns
Defined in
Poll.ts:1254
toJSON
▸ toJSON(): IJsonPoll
Serialize the Poll object to a JSON object
Returns
IJsonPoll
a JSON object
Implementation of
IPoll.toJSON
Defined in
Poll.ts:1576
topupMessage
▸ topupMessage(message
): void
Top up the voice credit balance of a user.
Parameters
Name | Type | Description |
---|---|---|
message | Message | The message to top up the voice credit balance |
Returns
void
Implementation of
IPoll.topupMessage
Defined in
Poll.ts:342
updatePoll
▸ updatePoll(numSignups
): void
Update a Poll with data from MaciState. This is the step where we copy the state from the MaciState instance, and set the number of signups we have so far.
Parameters
Name | Type |
---|---|
numSignups | bigint |
Returns
void
Defined in
Poll.ts:184
fromJSON
▸ fromJSON(json
, maciState
): Poll
Deserialize a json object into a Poll instance
Parameters
Name | Type | Description |
---|---|---|
json | IJsonPoll | the json object to deserialize |
maciState | MaciState | the reference to the MaciState Class |
Returns
a new Poll instance
Defined in
Poll.ts:1600