Skip to main content
Version: v3.x

ITally

Complete Tally interface

TallyResult​

Tally result

struct TallyResult {
uint256 value;
bool isSet;
}

AddTallyResultsArgs​

tally result args

struct AddTallyResultsArgs {
uint256[] voteOptionIndices;
uint256[] tallyResults;
uint256[][][] tallyResultProofs;
uint256 totalSpent;
uint256 totalSpentSalt;
uint256 tallyResultSalt;
uint256 newResultsCommitment;
uint256 spentVoiceCreditsHash;
uint256 perVOSpentVoiceCreditsHash;
}

addTallyResults​

function addTallyResults(struct ITally.AddTallyResultsArgs args) external

Add and verify tally results by batch.

Parameters​

NameTypeDescription
argsstruct ITally.AddTallyResultsArgsadd tally result args

updateSbCommitment​

function updateSbCommitment() external

Update the state and ballot root commitment

tallyVotes​

function tallyVotes(uint256 _newTallyCommitment, uint256[8] _proof) external

Verify the result of a tally batch

Parameters​

NameTypeDescription
_newTallyCommitmentuint256the new tally commitment to be verified
_proofuint256[8]the proof generated after tallying this batch

isTallied​

function isTallied() external view returns (bool tallied)

Check if all ballots are tallied

Return Values​

NameTypeDescription
talliedboolwhether all ballots are tallied

tallyCommitment​

function tallyCommitment() external view returns (uint256)

Get the tally commitment

Return Values​

NameTypeDescription
[0]uint256The current tally commitment

tallyBatchNum​

function tallyBatchNum() external view returns (uint256)

Get the tally batch number

Return Values​

NameTypeDescription
[0]uint256The current tally batch number

sbCommitment​

function sbCommitment() external view returns (uint256)

Get the final state and ballot commitment

Return Values​

NameTypeDescription
[0]uint256The sb commitment

getTallyResults​

function getTallyResults(uint256 index) external view returns (struct ITally.TallyResult)

Get tally results for a specific index

Parameters​

NameTypeDescription
indexuint256The index to query

Return Values​

NameTypeDescription
[0]struct ITally.TallyResultThe tally result

totalTallyResults​

function totalTallyResults() external view returns (uint256)

Get the total number of tally results

Return Values​

NameTypeDescription
[0]uint256The total tally results count

totalSpent​

function totalSpent() external view returns (uint256)

Get the total spent voice credits

Return Values​

NameTypeDescription
[0]uint256The total spent amount

getPublicCircuitInputs​

function getPublicCircuitInputs(uint256 _batchStartIndex, uint256 _newTallyCommitment) external view returns (uint256[] publicInputs)

Get public circuit inputs.

Parameters​

NameTypeDescription
_batchStartIndexuint256the batch start index
_newTallyCommitmentuint256the new tally commitment to be verified

Return Values​

NameTypeDescription
publicInputsuint256[]public circuit inputs

verifyTallyProof​

function verifyTallyProof(uint256 _batchStartIndex, uint256 _newTallyCommitment, uint256[8] _proof) external view returns (bool isValid)

Verify the tally proof using the verifying key

Parameters​

NameTypeDescription
_batchStartIndexuint256the batch start index
_newTallyCommitmentuint256the new tally commitment to be verified
_proofuint256[8]the proof generated after processing all messages

Return Values​

NameTypeDescription
isValidboolwhether the proof is valid

verifyPerVoteOptionSpentVoiceCredits​

function verifyPerVoteOptionSpentVoiceCredits(uint256 _voteOptionIndex, uint256 _spent, uint256[][] _spentProof, uint256 _spentSalt, uint8 _voteOptionTreeDepth, uint256 _spentVoiceCreditsHash, uint256 _resultCommitment) external view returns (bool isValid)

Return Values​

NameTypeDescription
isValidboolWhether the provided proof is valid

verifySpentVoiceCredits​

function verifySpentVoiceCredits(uint256 _totalSpent, uint256 _totalSpentSalt, uint256 _resultCommitment, uint256 _perVoteOptionSpentVoiceCreditsHash) external view returns (bool isValid)

Verify the number of spent voice credits from the tally.json

Parameters​

NameTypeDescription
_totalSpentuint256spent field retrieved in the totalSpentVoiceCredits object
_totalSpentSaltuint256the corresponding salt in the totalSpentVoiceCredit object
_resultCommitmentuint256hashLeftRight(merkle root of the results.tally, results.salt) in tally.json file
_perVoteOptionSpentVoiceCreditsHashuint256only for QV - hashLeftRight(merkle root of the no spent voice credits, salt)

Return Values​

NameTypeDescription
isValidboolWhether the provided values are valid

verifyTallyResult​

function verifyTallyResult(uint256 _voteOptionIndex, uint256 _tallyResult, uint256[][] _tallyResultProof, uint256 _tallyResultSalt, uint8 _voteOptionTreeDepth, uint256 _spentVoiceCreditsHash, uint256 _perVoteOptionSpentVoiceCreditsHash) external view returns (bool isValid)

Verify the result generated from the tally.json

Parameters​

NameTypeDescription
_voteOptionIndexuint256the index of the vote option to verify the correctness of the tally
_tallyResultuint256Flattened array of the tally
_tallyResultProofuint256[][]Corresponding proof of the tally result
_tallyResultSaltuint256the respective salt in the results object in the tally.json
_voteOptionTreeDepthuint8depth of the vote option tree
_spentVoiceCreditsHashuint256hashLeftRight(number of spent voice credits, spent salt)
_perVoteOptionSpentVoiceCreditsHashuint256hashLeftRight(merkle root of the no spent voice credits per vote option, perVoteOptionSpentVoiceCredits salt)

Return Values​

NameTypeDescription
isValidboolWhether the provided proof is valid