-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
- [x] Allow to add tally results and keep them onchain - [x] Update cli commands
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,12 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher, DomainObjs, ITa | |
IMessageProcessor public immutable messageProcessor; | ||
Mode public immutable mode; | ||
|
||
// The tally results | ||
mapping(uint256 => uint256) public tallyResults; | ||
|
||
// The total tally results number | ||
uint256 public totalTallyResults; | ||
|
||
/// @notice custom errors | ||
error ProcessingNotComplete(); | ||
error InvalidTallyVotesProof(); | ||
|
@@ -60,6 +66,7 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher, DomainObjs, ITa | |
error BatchStartIndexTooLarge(); | ||
error TallyBatchSizeTooLarge(); | ||
error NotSupported(); | ||
error VotesNotTallied(); | ||
|
||
/// @notice Create a new Tally contract | ||
/// @param _verifier The Verifier contract | ||
|
@@ -344,4 +351,73 @@ contract Tally is Ownable, SnarkCommon, CommonUtilities, Hasher, DomainObjs, ITa | |
isValid = hash2(tally) == tallyCommitment; | ||
} | ||
} | ||
|
||
/** | ||
* @notice Add and verify tally results by batch. | ||
* @param _voteOptionIndices Vote option index. | ||
* @param _tallyResults The results of vote tally for the recipients. | ||
* @param _tallyResultProofs Proofs of correctness of the vote tally results. | ||
* @param _tallyResultSalt the respective salt in the results object in the tally.json | ||
* @param _spentVoiceCreditsHashes hashLeftRight(number of spent voice credits, spent salt) | ||
* @param _perVOSpentVoiceCreditsHashes hashLeftRight(merkle root of the no spent voice credits per vote option, perVOSpentVoiceCredits salt) | ||
*/ | ||
function addTallyResults( | ||
uint256[] calldata _voteOptionIndices, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResults(uint256[],uint256[],uint256[][][],uint256,uint256,uint256)._voteOptionIndices is not in mixedCase
|
||
uint256[] calldata _tallyResults, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResults(uint256[],uint256[],uint256[][][],uint256,uint256,uint256)._tallyResults is not in mixedCase
|
||
uint256[][][] calldata _tallyResultProofs, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResults(uint256[],uint256[],uint256[][][],uint256,uint256,uint256)._tallyResultProofs is not in mixedCase
|
||
uint256 _tallyResultSalt, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResults(uint256[],uint256[],uint256[][][],uint256,uint256,uint256)._tallyResultSalt is not in mixedCase
|
||
uint256 _spentVoiceCreditsHashes, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResults(uint256[],uint256[],uint256[][][],uint256,uint256,uint256)._spentVoiceCreditsHashes is not in mixedCase
|
||
uint256 _perVOSpentVoiceCreditsHashes | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResults(uint256[],uint256[],uint256[][][],uint256,uint256,uint256)._perVOSpentVoiceCreditsHashes is not in mixedCase
|
||
) public virtual onlyOwner { | ||
if (!isTallied()) { | ||
revert VotesNotTallied(); | ||
} | ||
|
||
for (uint256 i = 0; i < _voteOptionIndices.length; i++) { | ||
addTallyResult( | ||
_voteOptionIndices[i], | ||
_tallyResults[i], | ||
_tallyResultProofs[i], | ||
_tallyResultSalt, | ||
_spentVoiceCreditsHashes, | ||
_perVOSpentVoiceCreditsHashes | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Add and verify tally votes and calculate sum of tally squares for alpha calculation. | ||
* @param _voteOptionIndex Vote option index. | ||
* @param _tallyResult The results of vote tally for the recipients. | ||
* @param _tallyResultProof Proofs of correctness of the vote tally results. | ||
* @param _tallyResultSalt the respective salt in the results object in the tally.json | ||
* @param _spentVoiceCreditsHash hashLeftRight(number of spent voice credits, spent salt) | ||
* @param _perVOSpentVoiceCreditsHash hashLeftRight(merkle root of the no spent voice credits per vote option, perVOSpentVoiceCredits salt) | ||
*/ | ||
function addTallyResult( | ||
uint256 _voteOptionIndex, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256)._voteOptionIndex is not in mixedCase
|
||
uint256 _tallyResult, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256)._tallyResult is not in mixedCase
|
||
uint256[][] calldata _tallyResultProof, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256)._tallyResultProof is not in mixedCase
|
||
uint256 _tallyResultSalt, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256)._tallyResultSalt is not in mixedCase
|
||
uint256 _spentVoiceCreditsHash, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256)._spentVoiceCreditsHash is not in mixedCase
|
||
uint256 _perVOSpentVoiceCreditsHash | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256)._perVOSpentVoiceCreditsHash is not in mixedCase
|
||
) internal virtual { | ||
(, , , uint8 voteOptionTreeDepth) = poll.treeDepths(); | ||
bool isValid = verifyTallyResult( | ||
_voteOptionIndex, | ||
_tallyResult, | ||
_tallyResultProof, | ||
_tallyResultSalt, | ||
voteOptionTreeDepth, | ||
_spentVoiceCreditsHash, | ||
_perVOSpentVoiceCreditsHash | ||
); | ||
|
||
if (!isValid) { | ||
revert InvalidTallyVotesProof(); | ||
} | ||
|
||
tallyResults[_voteOptionIndex] = _tallyResult; | ||
totalTallyResults++; | ||
} | ||
Check warning Code scanning / Slither Unused return Medium Check notice Code scanning / Slither Calls inside a loop Low
Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256) has external calls inside a loop: (None,None,None,voteOptionTreeDepth) = poll.treeDepths()
Check warning Code scanning / Slither Costly operations inside a loop Warning
Tally.addTallyResult(uint256,uint256,uint256[][],uint256,uint256,uint256) has costly operations inside a loop:
- totalTallyResults ++ |
||
} |