-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(poll): put verifier and vkRegistry into extContracts
- Loading branch information
Showing
11 changed files
with
48 additions
and
49 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
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import { Params } from "./utilities/Params.sol"; | |
import { SnarkCommon } from "./crypto/SnarkCommon.sol"; | ||
import { EmptyBallotRoots } from "./trees/EmptyBallotRoots.sol"; | ||
import { LazyIMTData, InternalLazyIMT } from "./trees/LazyIMT.sol"; | ||
import { IMACI } from "./interfaces/IMACI.sol"; | ||
import { IPoll } from "./interfaces/IPoll.sol"; | ||
import { IVerifier } from "./interfaces/IVerifier.sol"; | ||
import { IVkRegistry } from "./interfaces/IVkRegistry.sol"; | ||
|
@@ -71,11 +72,6 @@ contract Poll is Params, Utilities, SnarkCommon, EmptyBallotRoots, IPoll { | |
/// @notice The contracts used by the Poll | ||
ExtContracts public extContracts; | ||
|
||
/// @notice The verifier | ||
IVerifier public immutable verifier; | ||
/// @notice The verification registry | ||
IVkRegistry public immutable vkRegistry; | ||
|
||
/// @notice The array for chain hash checkpoints | ||
uint256[] public batchHashes; | ||
|
||
|
@@ -127,8 +123,6 @@ contract Poll is Params, Utilities, SnarkCommon, EmptyBallotRoots, IPoll { | |
/// @param _extContracts The external contracts | ||
|
||
constructor( | ||
address _verifier, | ||
address _vkRegistry, | ||
uint256 _duration, | ||
uint256 _maxVoteOptions, | ||
TreeDepths memory _treeDepths, | ||
|
@@ -141,10 +135,6 @@ contract Poll is Params, Utilities, SnarkCommon, EmptyBallotRoots, IPoll { | |
revert InvalidPubKey(); | ||
} | ||
|
||
// store verifier | ||
verifier = IVerifier(_verifier); | ||
// store vkRegistry | ||
vkRegistry = IVkRegistry(_vkRegistry); | ||
// store the pub key as object then calculate the hash | ||
coordinatorPubKey = _coordinatorPubKey; | ||
// we hash it ourselves to ensure we store the correct value | ||
|
@@ -325,7 +315,10 @@ contract Poll is Params, Utilities, SnarkCommon, EmptyBallotRoots, IPoll { | |
uint256[8] memory _proof | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter Poll.verifyPollProof(uint256,uint256,uint256,DomainObjs.PubKey,uint256[8])._proof is not in mixedCase
|
||
) internal returns (bool isValid) { | ||
// Get the verifying key from the VkRegistry | ||
VerifyingKey memory vk = vkRegistry.getPollVk(extContracts.maci.stateTreeDepth(), treeDepths.voteOptionTreeDepth); | ||
VerifyingKey memory vk = extContracts.vkRegistry.getPollVk( | ||
extContracts.maci.stateTreeDepth(), | ||
treeDepths.voteOptionTreeDepth | ||
); | ||
|
||
// Generate the circuit public input | ||
uint256[] memory input = new uint256[](5); | ||
|
@@ -336,7 +329,7 @@ contract Poll is Params, Utilities, SnarkCommon, EmptyBallotRoots, IPoll { | |
input[4] = _pubKey.y; | ||
uint256 publicInputHash = sha256Hash(input); | ||
|
||
isValid = verifier.verify(_proof, vk, publicInputHash); | ||
isValid = extContracts.verifier.verify(_proof, vk, publicInputHash); | ||
} | ||
|
||
/// @inheritdoc IPoll | ||
|
@@ -384,4 +377,9 @@ contract Poll is Params, Utilities, SnarkCommon, EmptyBallotRoots, IPoll { | |
numSUps = numSignups; | ||
numMsgs = numMessages; | ||
} | ||
|
||
/// @inheritdoc IPoll | ||
function getMaciContract() public view returns (IMACI maci) { | ||
return extContracts.maci; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -20,14 +20,12 @@ contract PollFactory is Params, DomainObjs, IPollFactory { | |
|
||
/// @inheritdoc IPollFactory | ||
function deploy( | ||
address _verifier, | ||
address _vkRegistry, | ||
uint256 _duration, | ||
uint256 _maxVoteOptions, | ||
TreeDepths calldata _treeDepths, | ||
uint8 _messageBatchSize, | ||
PubKey calldata _coordinatorPubKey, | ||
address _maci | ||
ExtContracts calldata _extContracts | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter PollFactory.deploy(uint256,uint256,Params.TreeDepths,uint8,DomainObjs.PubKey,Params.ExtContracts)._extContracts is not in mixedCase
|
||
) public virtual returns (address pollAddr) { | ||
/// @notice Validate _maxVoteOptions | ||
/// maxVoteOptions must be less than 2 ** 50 due to circuit limitations; | ||
|
@@ -37,20 +35,8 @@ contract PollFactory is Params, DomainObjs, IPollFactory { | |
revert InvalidMaxVoteOptions(); | ||
} | ||
|
||
/// @notice the smart contracts that a Poll would interact with | ||
ExtContracts memory extContracts = ExtContracts({ maci: IMACI(_maci) }); | ||
|
||
// deploy the poll | ||
Poll poll = new Poll( | ||
_verifier, | ||
_vkRegistry, | ||
_duration, | ||
_maxVoteOptions, | ||
_treeDepths, | ||
_messageBatchSize, | ||
_coordinatorPubKey, | ||
extContracts | ||
); | ||
Poll poll = new Poll(_duration, _maxVoteOptions, _treeDepths, _messageBatchSize, _coordinatorPubKey, _extContracts); | ||
|
||
// init Poll | ||
poll.init(); | ||
|
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
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
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
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
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
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
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