-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tally): remove ballotsTallied event and add view function
- Loading branch information
Showing
2 changed files
with
29 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,9 +49,6 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher { | |
error BatchStartIndexTooLarge(); | ||
error TallyBatchSizeTooLarge(); | ||
|
||
/// @notice events | ||
event BallotsTallied(address poll); | ||
|
||
/// @notice Create a new Tally contract | ||
/// @param _verifier The Verifier contract | ||
/// @param _vkRegistry The VkRegistry contract | ||
|
@@ -81,6 +78,16 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher { | |
result = (_batchStartIndex / _tallyBatchSize) + (_numSignUps << uint256(50)); | ||
} | ||
|
||
/// @notice Check if all ballots are tallied | ||
/// @return tallied whether all ballots are tallied | ||
function isTallied() external view returns (bool tallied) { | ||
(uint8 intStateTreeDepth, , , ) = poll.treeDepths(); | ||
(uint256 numSignUps, ) = poll.numSignUpsAndMessages(); | ||
|
||
// Require that there are untallied ballots left | ||
tallied = tallyBatchNum * (TREE_ARITY ** intStateTreeDepth) >= numSignUps; | ||
} | ||
Check warning Code scanning / Slither Unused return Medium
Tally.isTallied() ignores return value by (intStateTreeDepth) = poll.treeDepths()
Check warning Code scanning / Slither Unused return Medium
Tally.isTallied() ignores return value by (numSignUps) = poll.numSignUpsAndMessages()
|
||
|
||
/// @notice generate hash of public inputs for tally circuit | ||
/// @param _numSignUps: number of signups | ||
/// @param _batchStartIndex: the start index of given batch | ||
|
@@ -121,20 +128,19 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher { | |
_votingPeriodOver(poll); | ||
updateSbCommitment(); | ||
|
||
uint256 cachedBatchNum = tallyBatchNum; | ||
// get the batch size and start index | ||
(uint8 intStateTreeDepth, , , ) = poll.treeDepths(); | ||
uint256 tallyBatchSize = TREE_ARITY ** intStateTreeDepth; | ||
uint256 batchStartIndex = tallyBatchNum * tallyBatchSize; | ||
|
||
// save some gas because we won't overflow uint256 | ||
unchecked { | ||
tallyBatchNum++; | ||
} | ||
|
||
// get the batch size and start index | ||
(uint8 intStateTreeDepth, , , ) = poll.treeDepths(); | ||
uint256 tallyBatchSize = TREE_ARITY ** intStateTreeDepth; | ||
uint256 batchStartIndex = cachedBatchNum * tallyBatchSize; | ||
|
||
(uint256 numSignUps, ) = poll.numSignUpsAndMessages(); | ||
|
||
// Require that there are untalied ballots left | ||
// Require that there are untallied ballots left | ||
if (batchStartIndex >= numSignUps) { | ||
revert AllBallotsTallied(); | ||
} | ||
|
@@ -147,10 +153,6 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher { | |
|
||
// Update the tally commitment and the tally batch num | ||
tallyCommitment = _newTallyCommitment; | ||
|
||
if ((cachedBatchNum + 1) * tallyBatchSize >= numSignUps) { | ||
emit BallotsTallied(address(poll)); | ||
} | ||
} | ||
|
||
/// @notice Verify the tally proof using the verifying key | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters