Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move add tally results args struct to interface #1877

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions packages/contracts/contracts/Tally.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,6 @@
bool flag;
}

/// @notice tally result args
struct AddTallyResultsArgs {
/// @param voteOptionIndices Vote option index.
uint256[] voteOptionIndices;
/// @param tallyResults The results of vote tally for the recipients.
uint256[] tallyResults;
/// @param tallyResultProofs Proofs of correctness of the vote tally results.
uint256[][][] tallyResultProofs;
/// @param totalSpent spent field retrieved in the totalSpentVoiceCredits object
uint256 totalSpent;
/// @param totalSpentSalt spent salt
uint256 totalSpentSalt;
/// @param tallyResultSalt the respective salt in the results object in the tally.json
uint256 tallyResultSalt;
/// @param newResultsCommitment The salted commitment of the vote tally for this batch of leaves plus the vote tally from currentResults
uint256 newResultsCommitment;
/// @param spentVoiceCreditsHash hashLeftRight(number of spent voice credits, spent salt)
uint256 spentVoiceCreditsHash;
/// @param perVOSpentVoiceCreditsHash hashLeftRight(merkle root of the no spent voice credits per vote option, perVOSpentVoiceCredits salt)
uint256 perVOSpentVoiceCreditsHash;
}

/// @notice The commitment to the tally results. Its initial value is 0, but after
/// the tally of each batch is proven on-chain via a zk-SNARK, it should be
/// updated to:
Expand Down Expand Up @@ -390,43 +368,43 @@
* @notice Add and verify tally results by batch.
* @param args add tally result args
*/
function addTallyResults(AddTallyResultsArgs calldata args) public virtual onlyOwner {
function addTallyResults(ITally.AddTallyResultsArgs calldata args) public virtual onlyOwner {
if (!isTallied()) {
revert VotesNotTallied();
}

(, , , uint8 voteOptionTreeDepth) = poll.treeDepths();
uint256 voteOptionsLength = args.voteOptionIndices.length;

for (uint256 i = 0; i < voteOptionsLength; ) {
addTallyResult(
args.voteOptionIndices[i],
args.tallyResults[i],
args.tallyResultProofs[i],
args.tallyResultSalt,
args.spentVoiceCreditsHash,
args.perVOSpentVoiceCreditsHash,
voteOptionTreeDepth
);

unchecked {
i++;
}
}

bool verified = verifySpentVoiceCredits(
args.totalSpent,
args.totalSpentSalt,
args.newResultsCommitment,
args.perVOSpentVoiceCreditsHash
);

if (!verified) {
revert IncorrectSpentVoiceCredits();
}

totalSpent = args.totalSpent;
}

Check warning

Code scanning / Slither

Unused return Medium


/**
* @dev Add and verify tally votes and calculate sum of tally squares for alpha calculation.
Expand Down
22 changes: 22 additions & 0 deletions packages/contracts/contracts/interfaces/ITally.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ pragma solidity ^0.8.10;
/// @title ITally
/// @notice Tally interface
interface ITally {
/// @notice tally result args
struct AddTallyResultsArgs {
/// @param voteOptionIndices Vote option index.
uint256[] voteOptionIndices;
/// @param tallyResults The results of vote tally for the recipients.
uint256[] tallyResults;
/// @param tallyResultProofs Proofs of correctness of the vote tally results.
uint256[][][] tallyResultProofs;
/// @param totalSpent spent field retrieved in the totalSpentVoiceCredits object
uint256 totalSpent;
/// @param totalSpentSalt spent salt
uint256 totalSpentSalt;
/// @param tallyResultSalt the respective salt in the results object in the tally.json
uint256 tallyResultSalt;
/// @param newResultsCommitment The salted commitment of the vote tally for this batch of leaves plus the vote tally from currentResults
uint256 newResultsCommitment;
/// @param spentVoiceCreditsHash hashLeftRight(number of spent voice credits, spent salt)
uint256 spentVoiceCreditsHash;
/// @param perVOSpentVoiceCreditsHash hashLeftRight(merkle root of the no spent voice credits per vote option, perVOSpentVoiceCredits salt)
uint256 perVOSpentVoiceCreditsHash;
}

/// @notice Verify the number of spent voice credits per vote option from the tally.json
/// @param _voteOptionIndex the index of the vote option where credits were spent
/// @param _spent the spent voice credits for a given vote option index
Expand Down
Loading