diff --git a/packages/contracts/contracts/Poll.sol b/packages/contracts/contracts/Poll.sol index fe4430307..d30ef9376 100644 --- a/packages/contracts/contracts/Poll.sol +++ b/packages/contracts/contracts/Poll.sol @@ -16,9 +16,6 @@ import { CurveBabyJubJub } from "./crypto/BabyJubJub.sol"; /// @dev Do not deploy this directly. Use PollFactory.deploy() which performs some /// checks on the Poll constructor arguments. contract Poll is Params, Utilities, SnarkCommon, IPoll { - /// @notice Whether the Poll has been initialized - bool internal isInit; - /// @notice The coordinator's public key PubKey public coordinatorPubKey; @@ -163,6 +160,25 @@ contract Poll is Params, Utilities, SnarkCommon, IPoll { emptyBallotRoot = _emptyBallotRoot; // store the poll id pollId = _pollId; + + unchecked { + numMessages++; + } + + // init chainHash here by inserting placeholderLeaf + uint256[2] memory dat; + dat[0] = NOTHING_UP_MY_SLEEVE; + dat[1] = 0; + + (Message memory _message, PubKey memory _padKey, uint256 placeholderLeaf) = padAndHashMessage(dat); + chainHash = NOTHING_UP_MY_SLEEVE; + batchHashes.push(NOTHING_UP_MY_SLEEVE); + updateChainHash(placeholderLeaf); + + InternalLazyIMT._init(pollStateTree, extContracts.maci.stateTreeDepth()); + InternalLazyIMT._insert(pollStateTree, BLANK_STATE_LEAF_HASH); + + emit PublishMessage(_message, _padKey); } /// @notice A modifier that causes the function to revert if the voting period is @@ -186,33 +202,6 @@ contract Poll is Params, Utilities, SnarkCommon, IPoll { _; } - /// @notice The initialization function. - /// @dev Should be called immediately after Poll creation - function init() public virtual { - if (isInit) revert PollAlreadyInit(); - // set to true so it cannot be called again - isInit = true; - - unchecked { - numMessages++; - } - - // init chainHash here by inserting placeholderLeaf - uint256[2] memory dat; - dat[0] = NOTHING_UP_MY_SLEEVE; - dat[1] = 0; - - (Message memory _message, PubKey memory _padKey, uint256 placeholderLeaf) = padAndHashMessage(dat); - chainHash = NOTHING_UP_MY_SLEEVE; - batchHashes.push(NOTHING_UP_MY_SLEEVE); - updateChainHash(placeholderLeaf); - - InternalLazyIMT._init(pollStateTree, extContracts.maci.stateTreeDepth()); - InternalLazyIMT._insert(pollStateTree, BLANK_STATE_LEAF_HASH); - - emit PublishMessage(_message, _padKey); - } - // get all batch hash array elements function getBatchHashes() external view returns (uint256[] memory) { return batchHashes; diff --git a/packages/contracts/contracts/PollFactory.sol b/packages/contracts/contracts/PollFactory.sol index e2ce4d27a..b68c0a8bb 100644 --- a/packages/contracts/contracts/PollFactory.sol +++ b/packages/contracts/contracts/PollFactory.sol @@ -35,9 +35,6 @@ contract PollFactory is Params, DomainObjs, IPollFactory { _pollId ); - // init Poll - poll.init(); - pollAddr = address(poll); } } diff --git a/packages/contracts/tests/Poll.test.ts b/packages/contracts/tests/Poll.test.ts index 935a73180..a5648bc42 100644 --- a/packages/contracts/tests/Poll.test.ts +++ b/packages/contracts/tests/Poll.test.ts @@ -132,10 +132,6 @@ describe("Poll", () => { ); }); - it("should not be possible to init the Poll contract twice", async () => { - await expect(pollContract.init()).to.be.revertedWithCustomError(pollContract, "PollAlreadyInit"); - }); - it("should have the correct coordinator public key set", async () => { const coordinatorPubKey = await pollContract.coordinatorPubKey(); expect(coordinatorPubKey[0].toString()).to.eq(coordinator.pubKey.rawPubKey[0].toString());