From 1f5d8cbb0afc3b625e6ee4b3f4cfb2e3d3459439 Mon Sep 17 00:00:00 2001 From: yu-zhen Date: Thu, 4 Jan 2024 12:41:55 +0900 Subject: [PATCH] feat: update contracts/tests, but the deployPoll would fail due to deploy Tally too large --- contracts/contracts/MACI.sol | 20 ++- .../contracts/MessageProcessorFactory.sol | 4 + contracts/contracts/SubsidyFactory.sol | 5 + contracts/contracts/TallyFactory.sol | 5 + contracts/tests/MACI.test.ts | 20 ++- contracts/tests/MaciOverflow.test.ts | 10 +- contracts/tests/MessageProcessor.test.ts | 50 +++--- contracts/tests/Poll.test.ts | 18 +- contracts/tests/Tally.test.ts | 76 ++++----- contracts/tests/utils.ts | 27 +-- contracts/ts/deploy.ts | 159 +++--------------- contracts/ts/index.ts | 4 - contracts/ts/types.ts | 4 - 13 files changed, 161 insertions(+), 241 deletions(-) diff --git a/contracts/contracts/MACI.sol b/contracts/contracts/MACI.sol index b8947cd413..bb6a500ca2 100644 --- a/contracts/contracts/MACI.sol +++ b/contracts/contracts/MACI.sol @@ -5,7 +5,9 @@ import { Poll } from "./Poll.sol"; import { PollFactory } from "./PollFactory.sol"; import { MessageProcessor } from "./MessageProcessor.sol"; import { MessageProcessorFactory } from "./MessageProcessorFactory.sol"; +import { Tally } from "./Tally.sol"; import { TallyFactory } from "./TallyFactory.sol"; +import { Subsidy } from "./Subsidy.sol"; import { SubsidyFactory } from "./SubsidyFactory.sol"; import { InitialVoiceCreditProxy } from "./initialVoiceCreditProxy/InitialVoiceCreditProxy.sol"; import { SignUpGatekeeper } from "./gatekeepers/SignUpGatekeeper.sol"; @@ -86,7 +88,14 @@ contract MACI is IMACI, Params, Utilities, Ownable { // Events event SignUp(uint256 _stateIndex, PubKey _userPubKey, uint256 _voiceCreditBalance, uint256 _timestamp); - event DeployPoll(uint256 _pollId, address _pollAddr, PubKey _pubKey); + event DeployPoll( + uint256 _pollId, + address _pollAddr, + PubKey _pubKey, + address _mpAddr, + address _tallyAddr, + address _subsidyAddr + ); /// @notice Only allow a Poll contract to call the modified function. modifier onlyPoll(uint256 _pollId) { @@ -233,15 +242,18 @@ contract MACI is IMACI, Params, Utilities, Ownable { MessageProcessor mp = messageProcessorFactory.deploy(_verifier, _vkRegistry, p); - tallyFactory.deploy(_verifier, _vkRegistry, p, mp); + Tally tally = tallyFactory.deploy(_verifier, _vkRegistry, p, mp); - subsidyFactory.deploy(_verifier, _vkRegistry, p, mp); + Subsidy subsidy = subsidyFactory.deploy(_verifier, _vkRegistry, p, mp); polls[pollId] = p; pollAddr = address(p); + address mpAddr = address(mp); + address tallyAddr = address(tally); + address subsidyAddr = address(subsidy); - emit DeployPoll(pollId, pollAddr, _coordinatorPubKey); + emit DeployPoll(pollId, pollAddr, _coordinatorPubKey, mpAddr, tallyAddr, subsidyAddr); } /// @notice Allow Poll contracts to merge the state subroots diff --git a/contracts/contracts/MessageProcessorFactory.sol b/contracts/contracts/MessageProcessorFactory.sol index d4cf1616ac..cb01e53e8b 100644 --- a/contracts/contracts/MessageProcessorFactory.sol +++ b/contracts/contracts/MessageProcessorFactory.sol @@ -12,6 +12,10 @@ import { VkRegistry } from "./VkRegistry.sol"; /// @notice A factory contract which deploys MessageProcessor contracts. contract MessageProcessorFactory is Params, DomainObjs { /// @notice Deploy a new MessageProcessor contract and return the address. + /// @param _verifier Verifier contract + /// @param _vkRegistry VkRegistry contract + /// @param _poll Poll contract + /// @return messageProcessor The deployed MessageProcessor contract function deploy( Verifier _verifier, VkRegistry _vkRegistry, diff --git a/contracts/contracts/SubsidyFactory.sol b/contracts/contracts/SubsidyFactory.sol index 7493c4d837..1bd57f56c6 100644 --- a/contracts/contracts/SubsidyFactory.sol +++ b/contracts/contracts/SubsidyFactory.sol @@ -13,6 +13,11 @@ import { VkRegistry } from "./VkRegistry.sol"; /// @notice A factory contract which deploys Subsidy contracts. contract SubsidyFactory is Params, DomainObjs { /// @notice Deploy a new Subsidy contract and return the address. + /// @param _verifier Verifier contract + /// @param _vkRegistry VkRegistry contract + /// @param _poll Poll contract + /// @param _messageProcessor MessageProcessor contract + /// @return subsidy The deployed Subsidy contract function deploy( Verifier _verifier, VkRegistry _vkRegistry, diff --git a/contracts/contracts/TallyFactory.sol b/contracts/contracts/TallyFactory.sol index 31bd5b3738..ef1e6678e5 100644 --- a/contracts/contracts/TallyFactory.sol +++ b/contracts/contracts/TallyFactory.sol @@ -13,6 +13,11 @@ import { VkRegistry } from "./VkRegistry.sol"; /// @notice A factory contract which deploys Tally contracts. contract TallyFactory is Params, DomainObjs { /// @notice Deploy a new Tally contract and return the address. + /// @param _verifier Verifier contract + /// @param _vkRegistry VkRegistry contract + /// @param _poll Poll contract + /// @param _messageProcessor MessageProcessor contract + /// @return tally The deployed Tally contract function deploy( Verifier _verifier, VkRegistry _vkRegistry, diff --git a/contracts/tests/MACI.test.ts b/contracts/tests/MACI.test.ts index 96fbc50b7e..05e11e907b 100644 --- a/contracts/tests/MACI.test.ts +++ b/contracts/tests/MACI.test.ts @@ -10,7 +10,7 @@ import type { IVerifyingKeyStruct } from "../ts/types"; import { parseArtifact } from "../ts/abi"; import { getDefaultSigner } from "../ts/utils"; -import { AccQueueQuinaryMaci, MACI, VkRegistry, Poll as PollContract } from "../typechain-types"; +import { AccQueueQuinaryMaci, MACI, VkRegistry, Poll as PollContract, Verifier } from "../typechain-types"; import { duration, @@ -28,6 +28,7 @@ describe("MACI", () => { let maciContract: MACI; let stateAqContract: AccQueueQuinaryMaci; let vkRegistryContract: VkRegistry; + let verifierContract: Verifier; let pollId: number; const coordinator = new Keypair(); @@ -47,6 +48,7 @@ describe("MACI", () => { maciContract = r.maciContract; stateAqContract = r.stateAqContract; vkRegistryContract = r.vkRegistryContract; + verifierContract = r.mockVerifierContract; }); it("MACI.stateTreeDepth should be correct", async () => { @@ -201,6 +203,8 @@ describe("MACI", () => { maxValues, treeDepths, coordinator.pubKey.asContractParam() as { x: BigNumberish; y: BigNumberish }, + verifierContract, + vkRegistryContract, { gasLimit: 8000000 }, ); receipt = await tx.wait(); @@ -286,9 +290,17 @@ describe("MACI", () => { it("should prevent deploying a second poll before the first has finished", async () => { await expect( - maciContract.deployPoll(duration, maxValues, treeDepths, coordinator.pubKey.asContractParam(), { - gasLimit: 8000000, - }), + maciContract.deployPoll( + duration, + maxValues, + treeDepths, + coordinator.pubKey.asContractParam(), + verifierContract, + vkRegistryContract, + { + gasLimit: 8000000, + }, + ), ) .to.be.revertedWithCustomError(maciContract, "PreviousPollNotCompleted") .withArgs(1); diff --git a/contracts/tests/MaciOverflow.test.ts b/contracts/tests/MaciOverflow.test.ts index 9db5eecfe3..42a6c5485c 100644 --- a/contracts/tests/MaciOverflow.test.ts +++ b/contracts/tests/MaciOverflow.test.ts @@ -4,13 +4,15 @@ import { MaxValues, STATE_TREE_DEPTH, TreeDepths } from "maci-core"; import { Keypair } from "maci-domainobjs"; import { getDefaultSigner } from "../ts/utils"; -import { MACI } from "../typechain-types"; +import { MACI, Verifier, VkRegistry } from "../typechain-types"; import { duration, initialVoiceCreditBalance, maxValues, treeDepths } from "./constants"; import { deployTestContracts } from "./utils"; describe("Overflow testing", () => { let maciContract: MACI; + let verifierContract: Verifier; + let vkRigistryContract: VkRegistry; const coordinator = new Keypair(); const users = [new Keypair(), new Keypair(), new Keypair()]; @@ -18,6 +20,8 @@ describe("Overflow testing", () => { beforeEach(async () => { const r = await deployTestContracts(initialVoiceCreditBalance, STATE_TREE_DEPTH, await getDefaultSigner(), true); maciContract = r.maciContract; + verifierContract = r.mockVerifierContract; + vkRigistryContract = r.vkRegistryContract; }); it("MACI.stateTreeDepth should be correct", async () => { @@ -39,6 +43,8 @@ describe("Overflow testing", () => { maxValues, treeDepths, coordinator.pubKey.asContractParam() as { x: BigNumberish; y: BigNumberish }, + verifierContract, + vkRigistryContract, ); }); @@ -60,6 +66,8 @@ describe("Overflow testing", () => { values, depths, coordinator.pubKey.asContractParam() as { x: BigNumberish; y: BigNumberish }, + verifierContract, + vkRigistryContract, ); const receipt = await tx.wait(); diff --git a/contracts/tests/MessageProcessor.test.ts b/contracts/tests/MessageProcessor.test.ts index efe9be6ccc..b4759c1428 100644 --- a/contracts/tests/MessageProcessor.test.ts +++ b/contracts/tests/MessageProcessor.test.ts @@ -9,7 +9,7 @@ import { Keypair, Message, PubKey } from "maci-domainobjs"; import { parseArtifact } from "../ts/abi"; import { IVerifyingKeyStruct } from "../ts/types"; import { getDefaultSigner } from "../ts/utils"; -import { MACI, MessageProcessor, Poll as PollContract } from "../typechain-types"; +import { MACI, MessageProcessor, Poll as PollContract, Verifier, VkRegistry } from "../typechain-types"; import { duration, @@ -26,8 +26,11 @@ describe("MessageProcessor", () => { // contracts let maciContract: MACI; let pollContract: PollContract; + let verifierContract: Verifier; + let vkRegistryContract: VkRegistry; let mpContract: MessageProcessor; const [pollAbi] = parseArtifact("Poll"); + const [mpAbi] = parseArtifact("MessageProcessor"); let pollId: number; @@ -47,12 +50,21 @@ describe("MessageProcessor", () => { const r = await deployTestContracts(initialVoiceCreditBalance, STATE_TREE_DEPTH, signer, true); maciContract = r.maciContract; signer = await getDefaultSigner(); - mpContract = r.mpContract; + verifierContract = r.mockVerifierContract; + vkRegistryContract = r.vkRegistryContract; // deploy on chain poll - const tx = await maciContract.deployPoll(duration, maxValues, treeDepths, coordinator.pubKey.asContractParam(), { - gasLimit: 8000000, - }); + const tx = await maciContract.deployPoll( + duration, + maxValues, + treeDepths, + coordinator.pubKey.asContractParam(), + verifierContract, + vkRegistryContract, + { + gasLimit: 8000000, + }, + ); let receipt = await tx.wait(); // extract poll id @@ -60,13 +72,15 @@ describe("MessageProcessor", () => { const iface = maciContract.interface; const logs = receipt!.logs[receipt!.logs.length - 1]; const event = iface.parseLog(logs as unknown as { topics: string[]; data: string }) as unknown as { - args: { _pollId: number }; + args: { _pollId: number; _mpAddr: string }; }; pollId = event.args._pollId; const pollContractAddress = await maciContract.getPoll(pollId); pollContract = new BaseContract(pollContractAddress, pollAbi, signer) as PollContract; + mpContract = new BaseContract(event.args._mpAddr, mpAbi, signer) as MessageProcessor; + const block = await signer.provider!.getBlock(receipt!.blockHash); const deployTime = block!.timestamp; @@ -90,8 +104,7 @@ describe("MessageProcessor", () => { generatedInputs = poll.processMessages(pollId) as typeof generatedInputs; // set the verification keys on the vk smart contract - const vkContract = r.vkRegistryContract; - await vkContract.setVerifyingKeys( + await vkRegistryContract.setVerifyingKeys( STATE_TREE_DEPTH, treeDepths.intStateTreeDepth, treeDepths.messageTreeDepth, @@ -111,11 +124,10 @@ describe("MessageProcessor", () => { }); it("processMessages() should fail if the state AQ has not been merged", async () => { - const pollContractAddress = await maciContract.getPoll(pollId); - - await expect( - mpContract.processMessages(pollContractAddress, 0, [0, 0, 0, 0, 0, 0, 0, 0]), - ).to.be.revertedWithCustomError(mpContract, "StateAqNotMerged"); + await expect(mpContract.processMessages(0, [0, 0, 0, 0, 0, 0, 0, 0])).to.be.revertedWithCustomError( + mpContract, + "StateAqNotMerged", + ); }); }); @@ -135,21 +147,13 @@ describe("MessageProcessor", () => { 0, poll.messages.length, ); - const onChainPackedVals = BigInt( - await mpContract.genProcessMessagesPackedVals(await pollContract.getAddress(), 0, users.length), - ); + const onChainPackedVals = BigInt(await mpContract.genProcessMessagesPackedVals(0, users.length)); expect(packedVals.toString(16)).to.eq(onChainPackedVals.toString(16)); }); it("processMessages() should update the state and ballot root commitment", async () => { - const pollContractAddress = await maciContract.getPoll(pollId); - // Submit the proof - const tx = await mpContract.processMessages( - pollContractAddress, - generatedInputs.newSbCommitment, - [0, 0, 0, 0, 0, 0, 0, 0], - ); + const tx = await mpContract.processMessages(generatedInputs.newSbCommitment, [0, 0, 0, 0, 0, 0, 0, 0]); const receipt = await tx.wait(); expect(receipt?.status).to.eq(1); diff --git a/contracts/tests/Poll.test.ts b/contracts/tests/Poll.test.ts index e25970287a..d41c333356 100644 --- a/contracts/tests/Poll.test.ts +++ b/contracts/tests/Poll.test.ts @@ -8,7 +8,7 @@ import { Keypair, Message, PCommand, PubKey } from "maci-domainobjs"; import { parseArtifact } from "../ts/abi"; import { getDefaultSigner } from "../ts/utils"; -import { AccQueue, MACI, Poll as PollContract } from "../typechain-types"; +import { AccQueue, MACI, Poll as PollContract, Verifier, VkRegistry } from "../typechain-types"; import { MESSAGE_TREE_DEPTH, @@ -25,6 +25,8 @@ describe("Poll", () => { let maciContract: MACI; let pollId: number; let pollContract: PollContract; + let verifierContract: Verifier; + let vkRegistryContract: VkRegistry; let signer: Signer; let deployTime: number; const coordinator = new Keypair(); @@ -39,9 +41,17 @@ describe("Poll", () => { maciContract = r.maciContract; // deploy on chain poll - const tx = await maciContract.deployPoll(duration, maxValues, treeDepths, coordinator.pubKey.asContractParam(), { - gasLimit: 8000000, - }); + const tx = await maciContract.deployPoll( + duration, + maxValues, + treeDepths, + coordinator.pubKey.asContractParam(), + verifierContract, + vkRegistryContract, + { + gasLimit: 8000000, + }, + ); const receipt = await tx.wait(); const block = await signer.provider!.getBlock(receipt!.blockHash); diff --git a/contracts/tests/Tally.test.ts b/contracts/tests/Tally.test.ts index 20e21c5170..e17bf376a3 100644 --- a/contracts/tests/Tally.test.ts +++ b/contracts/tests/Tally.test.ts @@ -9,7 +9,7 @@ import { Keypair, Message, PubKey } from "maci-domainobjs"; import { parseArtifact } from "../ts/abi"; import { IVerifyingKeyStruct } from "../ts/types"; import { getDefaultSigner } from "../ts/utils"; -import { Tally, MACI, Poll as PollContract, MessageProcessor } from "../typechain-types"; +import { Tally, MACI, Poll as PollContract, MessageProcessor, Verifier, VkRegistry } from "../typechain-types"; import { STATE_TREE_DEPTH, @@ -29,12 +29,16 @@ describe("TallyVotes", () => { let pollContract: PollContract; let tallyContract: Tally; let mpContract: MessageProcessor; + let verifierContract: Verifier; + let vkRegistryContract: VkRegistry; const coordinator = new Keypair(); const users = [new Keypair(), new Keypair()]; const maciState = new MaciState(STATE_TREE_DEPTH); const [pollAbi] = parseArtifact("Poll"); + const [mpAbi] = parseArtifact("MessageProcessor"); + const [tallyAbi] = parseArtifact("Tally"); let pollId: number; let poll: Poll; @@ -46,14 +50,22 @@ describe("TallyVotes", () => { const r = await deployTestContracts(100, STATE_TREE_DEPTH, signer, true); maciContract = r.maciContract; - mpContract = r.mpContract; - tallyContract = r.tallyContract; + verifierContract = r.mockVerifierContract; + vkRegistryContract = r.vkRegistryContract; // deploy a poll // deploy on chain poll - const tx = await maciContract.deployPoll(duration, maxValues, treeDepths, coordinator.pubKey.asContractParam(), { - gasLimit: 8000000, - }); + const tx = await maciContract.deployPoll( + duration, + maxValues, + treeDepths, + coordinator.pubKey.asContractParam(), + verifierContract, + vkRegistryContract, + { + gasLimit: 8000000, + }, + ); let receipt = await tx.wait(); const block = await signer.provider!.getBlock(receipt!.blockHash); @@ -63,13 +75,16 @@ describe("TallyVotes", () => { const iface = maciContract.interface; const logs = receipt!.logs[receipt!.logs.length - 1]; const event = iface.parseLog(logs as unknown as { topics: string[]; data: string }) as unknown as { - args: { _pollId: number }; + args: { _pollId: number; _mpAddr: string; _tallyAddr: string }; }; pollId = event.args._pollId; const pollContractAddress = await maciContract.getPoll(pollId); pollContract = new BaseContract(pollContractAddress, pollAbi, signer) as PollContract; + mpContract = new BaseContract(event.args._mpAddr, mpAbi, signer) as MessageProcessor; + tallyContract = new BaseContract(event.args._tallyAddr, tallyAbi, signer) as Tally; + // deploy local poll const p = maciState.deployPoll(BigInt(deployTime + duration), maxValues, treeDepths, messageBatchSize, coordinator); expect(p.toString()).to.eq(pollId.toString()); @@ -92,8 +107,7 @@ describe("TallyVotes", () => { generatedInputs = poll.processMessages(pollId) as typeof generatedInputs; // set the verification keys on the vk smart contract - const vkContract = r.vkRegistryContract; - await vkContract.setVerifyingKeys( + await vkRegistryContract.setVerifyingKeys( STATE_TREE_DEPTH, treeDepths.intStateTreeDepth, treeDepths.messageTreeDepth, @@ -108,14 +122,10 @@ describe("TallyVotes", () => { }); it("should not be possible to tally votes before the poll has ended", async () => { - await expect( - tallyContract.tallyVotes( - await pollContract.getAddress(), - await mpContract.getAddress(), - 0, - [0, 0, 0, 0, 0, 0, 0, 0], - ), - ).to.be.revertedWithCustomError(tallyContract, "VOTING_PERIOD_NOT_PASSED"); + await expect(tallyContract.tallyVotes(0, [0, 0, 0, 0, 0, 0, 0, 0])).to.be.revertedWithCustomError( + tallyContract, + "VOTING_PERIOD_NOT_PASSED", + ); }); it("genTallyVotesPackedVals() should generate the correct value", async () => { @@ -128,17 +138,17 @@ describe("TallyVotes", () => { // go forward in time await timeTravel(signer.provider! as unknown as EthereumProvider, duration + 1); - await expect(tallyContract.updateSbCommitment(await mpContract.getAddress())).to.be.revertedWithCustomError( + await expect(tallyContract.updateSbCommitment()).to.be.revertedWithCustomError( tallyContract, "ProcessingNotComplete", ); }); it("tallyVotes() should fail as the messages have not been processed yet", async () => { - const pollContractAddress = await maciContract.getPoll(pollId); - await expect( - tallyContract.tallyVotes(pollContractAddress, await mpContract.getAddress(), 0, [0, 0, 0, 0, 0, 0, 0, 0]), - ).to.be.revertedWithCustomError(tallyContract, "ProcessingNotComplete"); + await expect(tallyContract.tallyVotes(0, [0, 0, 0, 0, 0, 0, 0, 0])).to.be.revertedWithCustomError( + tallyContract, + "ProcessingNotComplete", + ); }); describe("after merging acc queues", () => { @@ -153,18 +163,9 @@ describe("TallyVotes", () => { }); it("tallyVotes() should update the tally commitment", async () => { // do the processing on the message processor contract - await mpContract.processMessages( - await pollContract.getAddress(), - generatedInputs.newSbCommitment, - [0, 0, 0, 0, 0, 0, 0, 0], - ); - - const tx = await tallyContract.tallyVotes( - await pollContract.getAddress(), - await mpContract.getAddress(), - tallyGeneratedInputs.newTallyCommitment, - [0, 0, 0, 0, 0, 0, 0, 0], - ); + await mpContract.processMessages(generatedInputs.newSbCommitment, [0, 0, 0, 0, 0, 0, 0, 0]); + + const tx = await tallyContract.tallyVotes(tallyGeneratedInputs.newTallyCommitment, [0, 0, 0, 0, 0, 0, 0, 0]); const receipt = await tx.wait(); expect(receipt?.status).to.eq(1); @@ -175,12 +176,7 @@ describe("TallyVotes", () => { }); it("tallyVotes() should revert when votes have already been tallied", async () => { await expect( - tallyContract.tallyVotes( - await pollContract.getAddress(), - await mpContract.getAddress(), - tallyGeneratedInputs.newTallyCommitment, - [0, 0, 0, 0, 0, 0, 0, 0], - ), + tallyContract.tallyVotes(tallyGeneratedInputs.newTallyCommitment, [0, 0, 0, 0, 0, 0, 0, 0]), ).to.be.revertedWithCustomError(tallyContract, "AllBallotsTallied"); }); }); diff --git a/contracts/tests/utils.ts b/contracts/tests/utils.ts index be77a4ccbe..9580271986 100644 --- a/contracts/tests/utils.ts +++ b/contracts/tests/utils.ts @@ -11,10 +11,8 @@ import { deployConstantInitialVoiceCreditProxy, deployFreeForAllSignUpGatekeeper, deployMaci, - deployMessageProcessor, deployMockVerifier, deployPoseidonContracts, - deployTally, deployTopupCredit, deployVkRegistry, linkPoseidonLibraries, @@ -508,7 +506,6 @@ export const deployTestContracts = async ( gatekeeperContractAddress, mockVerifierContractAddress, constantIntialVoiceCreditProxyContractAddress, - vkRegistryContractAddress, topupCreditContractAddress, ] = await Promise.all([ gatekeeperContract.getAddress(), @@ -518,7 +515,7 @@ export const deployTestContracts = async ( topupCreditContract.getAddress(), ]); - const { maciContract, stateAqContract, poseidonAddrs } = await deployMaci( + const { maciContract, stateAqContract } = await deployMaci( gatekeeperContractAddress, constantIntialVoiceCreditProxyContractAddress, mockVerifierContractAddress, @@ -527,26 +524,6 @@ export const deployTestContracts = async ( stateTreeDepth, quiet, ); - const mpContract = await deployMessageProcessor( - mockVerifierContractAddress, - vkRegistryContractAddress, - poseidonAddrs[0], - poseidonAddrs[1], - poseidonAddrs[2], - poseidonAddrs[3], - signer, - true, - ); - const tallyContract = await deployTally( - mockVerifierContractAddress, - vkRegistryContractAddress, - poseidonAddrs[0], - poseidonAddrs[1], - poseidonAddrs[2], - poseidonAddrs[3], - signer, - true, - ); return { mockVerifierContract, @@ -555,7 +532,5 @@ export const deployTestContracts = async ( maciContract, stateAqContract, vkRegistryContract, - mpContract, - tallyContract, }; }; diff --git a/contracts/ts/deploy.ts b/contracts/ts/deploy.ts index 7951868e58..db2049d4b1 100644 --- a/contracts/ts/deploy.ts +++ b/contracts/ts/deploy.ts @@ -1,4 +1,4 @@ -import { type Contract, type ContractFactory, BaseContract, Signer } from "ethers"; +import { type ContractFactory, BaseContract, Signer } from "ethers"; // eslint-disable-next-line // @ts-ignore typedoc doesn't want to get types from toolbox import { ethers } from "hardhat"; @@ -8,17 +8,17 @@ import { ConstantInitialVoiceCreditProxy, FreeForAllGatekeeper, MACI, - MessageProcessor, MockVerifier, PollFactory, + MessageProcessorFactory, + SubsidyFactory, + TallyFactory, PoseidonT3, PoseidonT4, PoseidonT5, PoseidonT6, SignUpToken, SignUpTokenGatekeeper, - Subsidy, - Tally, TopupCredit, Verifier, VkRegistry, @@ -187,15 +187,6 @@ export const deployPoseidonContracts = async (signer?: Signer, quiet = false): P }; }; -/** - * Deploy a PollFactory contract - * @param signer - the signer to use to deploy the contract - * @param quiet - whether to suppress console output - * @returns the deployed PollFactory contract - */ -export const deployPollFactory = async (signer?: Signer, quiet = false): Promise => - deployContract("PollFactory", signer, quiet); - /** * Deploy a contract with linked libraries * @param contractFactory - the contract factory to use @@ -219,122 +210,6 @@ export const deployContractWithLinkedLibraries = async ( return contract as T; }; -/** - * Deploy a MessageProcessor contract - * @param verifierAddress - the address of the Verifier contract - * @param poseidonT3Address - the address of the PoseidonT3 contract - * @param poseidonT4Address - the address of the PoseidonT4 contract - * @param poseidonT5Address - the address of the PoseidonT5 contract - * @param poseidonT6Address - the address of the PoseidonT6 contract - * @param signer - the signer to use to deploy the contract - * @param quiet - whether to suppress console output - * @returns the deployed MessageProcessor contract - */ -export const deployMessageProcessor = async ( - verifierAddress: string, - vkRegistryAddress: string, - poseidonT3Address: string, - poseidonT4Address: string, - poseidonT5Address: string, - poseidonT6Address: string, - signer?: Signer, - quiet = false, -): Promise => { - // Link Poseidon contracts to MessageProcessor - const mpFactory = await linkPoseidonLibraries( - "MessageProcessor", - poseidonT3Address, - poseidonT4Address, - poseidonT5Address, - poseidonT6Address, - signer, - quiet, - ); - - return deployContractWithLinkedLibraries( - mpFactory, - "MessageProcessor", - quiet, - verifierAddress, - vkRegistryAddress, - ); -}; - -/** - * Deploy a Tally contract - * @param verifierAddress - the address of the Verifier contract - * @param poseidonT3Address - the address of the PoseidonT3 contract - * @param poseidonT4Address - the address of the PoseidonT4 contract - * @param poseidonT5Address - the address of the PoseidonT5 contract - * @param poseidonT6Address - the address of the PoseidonT6 contract - * @param signer - the signer to use to deploy the contract - * @param quiet - whether to suppress console output - * @returns the deployed Tally contract - */ -export const deployTally = async ( - verifierAddress: string, - vkRegistryAddress: string, - poseidonT3Address: string, - poseidonT4Address: string, - poseidonT5Address: string, - poseidonT6Address: string, - signer?: Signer, - quiet = false, -): Promise => { - // Link Poseidon contracts to Tally - const tallyFactory = await linkPoseidonLibraries( - "Tally", - poseidonT3Address, - poseidonT4Address, - poseidonT5Address, - poseidonT6Address, - signer, - quiet, - ); - - return deployContractWithLinkedLibraries(tallyFactory, "Tally", quiet, verifierAddress, vkRegistryAddress); -}; - -/** - * Depoloy a Subsidy contract - * @param verifierAddress - the address of the Verifier contract - * @param poseidonT3Address - the address of the PoseidonT3 contract - * @param poseidonT4Address - the address of the PoseidonT4 contract - * @param poseidonT5Address - the address of the PoseidonT5 contract - * @param poseidonT6Address - the address of the PoseidonT6 contract - * @param quiet - whether to suppress console output - * @returns the deployed Subsidy contract - */ -export const deploySubsidy = async ( - verifierAddress: string, - vkRegistryAddress: string, - poseidonT3Address: string, - poseidonT4Address: string, - poseidonT5Address: string, - poseidonT6Address: string, - signer?: Signer, - quiet = false, -): Promise => { - // Link Poseidon contracts to Subsidy - const subsidyFactory = await linkPoseidonLibraries( - "Subsidy", - poseidonT3Address, - poseidonT4Address, - poseidonT5Address, - poseidonT6Address, - signer, - quiet, - ); - - return deployContractWithLinkedLibraries( - subsidyFactory, - "Subsidy", - quiet, - verifierAddress, - vkRegistryAddress, - ); -}; - /** * Deploy a MACI contract * @param signUpTokenGatekeeperContractAddress - the address of the SignUpTokenGatekeeper contract @@ -366,7 +241,7 @@ export const deployMaci = async ( PoseidonT6Contract.getAddress(), ]); - const contractsToLink = ["MACI", "PollFactory"]; + const contractsToLink = ["MACI", "PollFactory", "MessageProcessorFactory", "TallyFactory", "SubsidyFactory"]; // Link Poseidon contracts to MACI const linkedContractFactories = await Promise.all( @@ -383,7 +258,8 @@ export const deployMaci = async ( ), ); - const [maciContractFactory, pollFactoryContractFactory] = await Promise.all(linkedContractFactories); + const [maciContractFactory, pollFactoryContractFactory, messageProcessorFactory, tallyFactory, subsidyFactory] = + await Promise.all(linkedContractFactories); const pollFactoryContract = await deployContractWithLinkedLibraries( pollFactoryContractFactory, @@ -391,11 +267,32 @@ export const deployMaci = async ( quiet, ); + const messageProcessorFactoryContract = await deployContractWithLinkedLibraries( + messageProcessorFactory, + "MessageProcessorFactory", + quiet, + ); + + const tallyFactoryContract = await deployContractWithLinkedLibraries( + tallyFactory, + "TallyFactory", + quiet, + ); + + const subsidyFactoryContract = await deployContractWithLinkedLibraries( + subsidyFactory, + "SubsidyFactory", + quiet, + ); + const maciContract = await deployContractWithLinkedLibraries( maciContractFactory, "MACI", quiet, await pollFactoryContract.getAddress(), + await messageProcessorFactoryContract.getAddress(), + await tallyFactoryContract.getAddress(), + await subsidyFactoryContract.getAddress(), signUpTokenGatekeeperContractAddress, initialVoiceCreditBalanceAddress, topupCreditContractAddress, diff --git a/contracts/ts/index.ts b/contracts/ts/index.ts index 8f83d11f2c..a70f0bb9c1 100644 --- a/contracts/ts/index.ts +++ b/contracts/ts/index.ts @@ -3,15 +3,11 @@ export { deployTopupCredit, deployVkRegistry, deployMaci, - deployMessageProcessor, - deployTally, - deploySubsidy, deployContract, deploySignupToken, deploySignupTokenGatekeeper, deployConstantInitialVoiceCreditProxy, deployFreeForAllSignUpGatekeeper, - deployPollFactory, linkPoseidonLibraries, deployPoseidonContracts, deployVerifier, diff --git a/contracts/ts/types.ts b/contracts/ts/types.ts index 5199358ea0..1bdc4b8e33 100644 --- a/contracts/ts/types.ts +++ b/contracts/ts/types.ts @@ -5,14 +5,12 @@ import type { ConstantInitialVoiceCreditProxy, FreeForAllGatekeeper, MACI, - MessageProcessor, MockVerifier, PollFactory, PoseidonT3, PoseidonT4, PoseidonT5, PoseidonT6, - Tally, VkRegistry, } from "../typechain-types"; import type { BigNumberish, Fragment, JsonFragment } from "ethers"; @@ -65,8 +63,6 @@ export interface IDeployedTestContracts { maciContract: MACI; stateAqContract: AccQueueQuinaryMaci; vkRegistryContract: VkRegistry; - mpContract: MessageProcessor; - tallyContract: Tally; } /**