-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contracts): add registry integration
- [x] Add deploy poll task - [x] Add init poll task - [x] Link registry and poll - [x] Add deploy poll registry method for MACI
- Loading branch information
Showing
15 changed files
with
547 additions
and
16 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
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 |
---|---|---|
|
@@ -4,18 +4,32 @@ pragma solidity ^0.8.20; | |
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { Poll as BasePoll } from "maci-contracts/contracts/Poll.sol"; | ||
|
||
import { ICommon } from "../interfaces/ICommon.sol"; | ||
|
||
/// @title Poll | ||
/// @notice A Poll contract allows voters to submit encrypted messages | ||
/// which can be either votes or key change messages. | ||
/// @dev Do not deploy this directly. Use PollFactory.deploy() which performs some | ||
/// checks on the Poll constructor arguments. | ||
contract Poll is Ownable, BasePoll { | ||
contract Poll is Ownable, BasePoll, ICommon { | ||
/// @notice Poll specific registry | ||
address public registry; | ||
|
||
/// @notice events | ||
event SetRegistry(address indexed registry); | ||
|
||
/// @notice custom errors | ||
error RegistryAlreadyInitialized(); | ||
error RegistryNotInitialized(); | ||
error PollNotInitialized(); | ||
|
||
/// @notice Each MACI instance can have multiple Polls. | ||
/// When a Poll is deployed, its voting period starts immediately. | ||
/// @param duration The duration of the voting period, in seconds | ||
/// @param treeDepths The depths of the merkle trees | ||
/// @param coordinatorPubKey The coordinator's public key | ||
/// @param extContracts The external contracts | ||
/// @param emptyBallotRoot The empty ballot root | ||
constructor( | ||
uint256 duration, | ||
TreeDepths memory treeDepths, | ||
|
@@ -28,8 +42,56 @@ contract Poll is Ownable, BasePoll { | |
BasePoll(duration, treeDepths, coordinatorPubKey, extContracts, emptyBallotRoot) | ||
{} | ||
|
||
/// @notice Check if poll is initialized | ||
modifier isPollInitialized() { | ||
if (!isInit) { | ||
revert PollNotInitialized(); | ||
} | ||
|
||
_; | ||
} | ||
|
||
/// @notice Check if registry is initialized | ||
modifier isRegistryInitialized() { | ||
if (address(registry) == address(0)) { | ||
revert RegistryNotInitialized(); | ||
} | ||
|
||
_; | ||
} | ||
|
||
/// @notice Check if registry is valid and not initialized | ||
/// @param registryAddress Registry address | ||
modifier isRegistryNotInitialized(address registryAddress) { | ||
if (registryAddress == address(0)) { | ||
revert InvalidAddress(); | ||
} | ||
|
||
if (address(registry) != address(0)) { | ||
revert RegistryAlreadyInitialized(); | ||
} | ||
|
||
_; | ||
} | ||
|
||
/// @notice Set poll registry. | ||
/// @param registryAddress The registry address | ||
function setRegistry(address registryAddress) public onlyOwner isRegistryNotInitialized(registryAddress) { | ||
registry = registryAddress; | ||
|
||
emit SetRegistry(registryAddress); | ||
} | ||
|
||
/// @notice The initialization function. | ||
function init() public override onlyOwner { | ||
function init() public override onlyOwner isRegistryInitialized { | ||
super.init(); | ||
} | ||
|
||
/// @inheritdoc BasePoll | ||
function publishMessage( | ||
Message memory message, | ||
PubKey calldata encPubKey | ||
) public override isPollInitialized isWithinVotingDeadline { | ||
super.publishMessage(message, encPubKey); | ||
} | ||
} | ||
Check warning Code scanning / Slither Contracts that lock Ether Medium
Contract locking ether found:
Contract Poll has payable functions: - Poll.constructor(uint256,Params.TreeDepths,DomainObjs.PubKey,Params.ExtContracts,uint256) But does not have a function to withdraw the ether |
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
Oops, something went wrong.