From 68e03bd61c55b4fb5aecb887f759628fa03a9102 Mon Sep 17 00:00:00 2001 From: Yash Goyal Date: Mon, 29 Apr 2024 14:16:23 +0530 Subject: [PATCH] clean up --- package.json | 3 +- packages/nextjs/app/api/polls/[id]/route.ts | 56 - packages/nextjs/utils/coordinator.ts | 66 - packages/nextjs/utils/genLocalState.ts | 0 packages/nextjs/utils/genMaciState.ts | 658 ---- packages/nextjs/utils/mergeMessages.ts | 83 - packages/nextjs/utils/mergeSignups.ts | 105 - packages/nextjs/utils/useGenerateProof.ts | 21 - packages/nextjs/utils/useMergeMessages.ts | 134 - packages/nextjs/utils/useMergeSignups.ts | 131 - packages/prover/.env.template | 0 packages/prover/.gitignore | 2 - packages/prover/README.md | 1 - packages/prover/package.json | 25 - packages/prover/src/abi/AccQueue.ts | 496 --- packages/prover/src/abi/MACI.ts | 0 packages/prover/src/abi/Poll.ts | 966 ----- packages/prover/src/config.ts | 55 - packages/prover/src/contract.ts | 441 --- packages/prover/src/deployedContracts.ts | 3646 ------------------- packages/prover/src/index.ts | 368 -- packages/prover/src/types/hardhat.d.ts | 3 - packages/prover/src/types/snarkjs.d.ts | 50 - packages/prover/src/utils.ts | 45 - packages/prover/tsconfig.json | 15 - 25 files changed, 1 insertion(+), 7369 deletions(-) delete mode 100644 packages/nextjs/app/api/polls/[id]/route.ts delete mode 100644 packages/nextjs/utils/coordinator.ts delete mode 100644 packages/nextjs/utils/genLocalState.ts delete mode 100644 packages/nextjs/utils/genMaciState.ts delete mode 100644 packages/nextjs/utils/mergeMessages.ts delete mode 100644 packages/nextjs/utils/mergeSignups.ts delete mode 100644 packages/nextjs/utils/useGenerateProof.ts delete mode 100644 packages/nextjs/utils/useMergeMessages.ts delete mode 100644 packages/nextjs/utils/useMergeSignups.ts delete mode 100644 packages/prover/.env.template delete mode 100644 packages/prover/.gitignore delete mode 100644 packages/prover/README.md delete mode 100644 packages/prover/package.json delete mode 100644 packages/prover/src/abi/AccQueue.ts delete mode 100644 packages/prover/src/abi/MACI.ts delete mode 100644 packages/prover/src/abi/Poll.ts delete mode 100644 packages/prover/src/config.ts delete mode 100644 packages/prover/src/contract.ts delete mode 100644 packages/prover/src/deployedContracts.ts delete mode 100644 packages/prover/src/index.ts delete mode 100644 packages/prover/src/types/hardhat.d.ts delete mode 100644 packages/prover/src/types/snarkjs.d.ts delete mode 100644 packages/prover/src/utils.ts delete mode 100644 packages/prover/tsconfig.json diff --git a/package.json b/package.json index a836781..3e026f1 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "workspaces": { "packages": [ "packages/hardhat", - "packages/nextjs", - "packages/prover" + "packages/nextjs" ] }, "scripts": { diff --git a/packages/nextjs/app/api/polls/[id]/route.ts b/packages/nextjs/app/api/polls/[id]/route.ts deleted file mode 100644 index 7d2e732..0000000 --- a/packages/nextjs/app/api/polls/[id]/route.ts +++ /dev/null @@ -1,56 +0,0 @@ -"use server"; - -import { NextResponse } from "next/server"; - -// import { execSync } from "child_process"; -// import fs from "fs"; -// import { pollManagerContract } from "~~/constants"; -// import { mergeMessages } from "~~/utils/mergeMessages"; -// import { mergeSignups } from "~~/utils/mergeSignups"; - -export async function POST(req: Request) { - let pollId: string; - try { - pollId = (await req.json()).pollId; - } catch (err) { - return NextResponse.json({ error: "invalid body" }, { status: 409 }); - } - - if (!pollId) { - return NextResponse.json({ error: "invalid body" }, { status: 409 }); - } - - // try { - // const poll = await pollManagerContract.read.fetchPoll([BigInt(pollId)]); - - // await mergeSignups({ pollContractAddress: poll.pollContracts.poll }); - // await mergeMessages({ pollContractAddress: poll.pollContracts.poll }); - - // const cliDirectory = "/Users/yash/Development/buidlguidl/maci/cli"; - // const dataFile = `${cliDirectory}/tally-${poll.maciPollId.toString()}.json`; - // execSync( - // `node ${cliDirectory}/build/ts/index.js genProofs \ - // --privkey ${process.env.COORDINATOR_PRIVATE_KEY} \ - // --poll-id ${poll.maciPollId.toString()} \ - // --process-zkey ${cliDirectory}/zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey \ - // --tally-zkey ${cliDirectory}/zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey \ - // --tally-file ${dataFile} \ - // --output proofs1/ \ - // -tw ${cliDirectory}/zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test_js/TallyVotes_10-1-2_test.wasm \ - // -pw ${cliDirectory}/zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test_js/ProcessMessages_10-2-1-2_test.wasm \ - // -w true`, - // { encoding: "utf-8" }, - // ); // the default is 'buffer' - - // const data = JSON.parse(fs.readFileSync(dataFile).toString("utf-8")); - - // const votesSerialized = JSON.stringify(data.results.tally.slice(0, 10).map((v: any) => (v ? parseInt(v) || 0 : 0))); - - // console.log(votesSerialized); - // } catch (err) { - // console.log(err); - // return NextResponse.json({ error: "something went wrong" }, { status: 500 }); - // } - - return NextResponse.json({ message: "finalized the poll successfully" }); -} diff --git a/packages/nextjs/utils/coordinator.ts b/packages/nextjs/utils/coordinator.ts deleted file mode 100644 index 84afd35..0000000 --- a/packages/nextjs/utils/coordinator.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { genMACIState } from "./genMaciState"; -import { mergeMessages } from "./mergeMessages"; -import { mergeSignups } from "./mergeSignups"; -import { Keypair, PrivKey } from "@se-2/hardhat/maci-ts/domainobjs"; -import { Address, PublicClient, createPublicClient, getContract, http } from "viem"; -import deployedContracts from "~~/contracts/deployedContracts"; -import scaffoldConfig from "~~/scaffold.config"; - -class Coordinator { - closing: Record = {}; - targetNetwork = scaffoldConfig.targetNetworks[0]; - publicClient: PublicClient; - - constructor() { - this.publicClient = createPublicClient({ chain: this.targetNetwork, transport: http() }); - } - - async closePoll(pollId: number) { - if (this.closing[pollId]) { - return; - } - - const { address: pollManagerAddress, abi: pollManagerAbi } = deployedContracts[this.targetNetwork.id].PollManager; - - const pollManager = getContract({ - abi: pollManagerAbi, - address: pollManagerAddress, - publicClient: this.publicClient, - }); - - if (Number(await pollManager.read.totalPolls()) < pollId) { - return null; - } - - const poll = await pollManager.read.fetchPoll([BigInt(pollId)]); - - if (new Date(Number(poll.endTime) * 1000) > new Date()) { - return null; - } - - // console.log(poll); - - // TODO: check if the poll is already closed - - // const provider = this.publicClient.provider(); - const coordinatorPrivateKey = new PrivKey(process.env.COORDINATOR_PRIVATE_KEY as string); - - console.log(process.env.COORDINATOR_PRIVATE_KEY); - - const coordinatorKeypair = new Keypair(coordinatorPrivateKey); - - await mergeSignups({ pollContractAddress: poll.pollContracts.poll as Address }); - await mergeMessages({ pollContractAddress: poll.pollContracts.poll as Address }); - - await genMACIState({ pollContractAddress: poll.pollContracts.poll as Address, coordinatorKeypair }); - - // console.log(poll); - - this.closing[pollId] = true; - - // Close the poll - console.log(`Closing poll ${pollId}`); - } -} - -export const coordinator = new Coordinator(); diff --git a/packages/nextjs/utils/genLocalState.ts b/packages/nextjs/utils/genLocalState.ts deleted file mode 100644 index e69de29..0000000 diff --git a/packages/nextjs/utils/genMaciState.ts b/packages/nextjs/utils/genMaciState.ts deleted file mode 100644 index dd285a0..0000000 --- a/packages/nextjs/utils/genMaciState.ts +++ /dev/null @@ -1,658 +0,0 @@ -import { MaciState, STATE_TREE_ARITY } from "@se-2/hardhat/maci-ts/core"; -import { Keypair, Message, PubKey } from "@se-2/hardhat/maci-ts/domainobjs"; -import assert from "assert"; -import { Address, createPublicClient, getContract, http } from "viem"; -import PollAbi from "~~/abi/Poll"; -import deployedContracts from "~~/contracts/deployedContracts"; -import scaffoldConfig from "~~/scaffold.config"; - -export interface Action { - type: string; - data: Partial<{ - pubKey: PubKey; - encPubKey: PubKey; - message: Message; - voiceCreditBalance: number; - timestamp: number; - stateIndex: number; - numSrQueueOps: number; - pollId: bigint; - pollAddr: string; - stateRoot: bigint; - messageRoot: bigint; - }>; - blockNumber: bigint; - transactionIndex: number; -} - -export function sortActions(actions: Action[]): Action[] { - return actions.slice().sort((a, b) => { - if (a.blockNumber > b.blockNumber) { - return 1; - } - - if (a.blockNumber < b.blockNumber) { - return -1; - } - - if (a.transactionIndex > b.transactionIndex) { - return 1; - } - - if (a.transactionIndex < b.transactionIndex) { - return -1; - } - - return 0; - }); -} - -export async function genMACIState({ - pollContractAddress, - coordinatorKeypair, -}: { - pollContractAddress: Address; - coordinatorKeypair: Keypair; -}) { - const chain = scaffoldConfig.targetNetworks[0]; - const publicClient = createPublicClient({ chain, transport: http() }); - const { address: MaciAddress, abi: MaciAbi, deploymentBlockNumber } = deployedContracts[chain.id].MACI; - - console.log(deploymentBlockNumber); - - const maciContract = getContract({ abi: MaciAbi, address: MaciAddress, publicClient }); - const stateTreeDepth = await maciContract.read.stateTreeDepth(); - - const maciState = new MaciState(stateTreeDepth); - - assert(stateTreeDepth === maciState.stateTreeDepth); - - const lastBlock = await publicClient.getBlockNumber(); - const startBlock = BigInt(0); - const blocksPerRequest = 50; - - const deployPollLogs = await maciContract.getEvents.DeployPoll({}, { fromBlock: startBlock, toBlock: lastBlock }); - const signUpLogs = await maciContract.getEvents.SignUp({}, { fromBlock: startBlock, toBlock: lastBlock }); - - let actions: Action[] = []; - - signUpLogs.forEach(log => { - actions.push({ - type: "SignUp", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - stateIndex: Number(log.args._stateIndex), - pubKey: new PubKey([log.args._userPubKeyX || 0n, log.args._userPubKeyY || 0n]), - voiceCreditBalance: Number(log.args._voiceCreditBalance), - timestamp: Number(log.args._timestamp), - }, - }); - }); - - const pollContractAddresses = new Map(); - let includesPollAddress = false; - let pollId = 0n; - - deployPollLogs.forEach(log => { - const pollAddr = log.args.pollAddr?.poll; - actions.push({ - type: "DeployPoll", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - pollId: log.args._pollId, - pollAddr, - pubKey: new PubKey([log.args._coordinatorPubKeyX || 0n, log.args._coordinatorPubKeyY || 0n]), - }, - }); - - if (pollContractAddress.toLowerCase() === pollAddr?.toLowerCase()) { - includesPollAddress = true; - pollId = log.args._pollId as bigint; - } - - pollContractAddresses.set(log.args._pollId, pollAddr); - }); - - assert(includesPollAddress, "Error: the specified pollId does not exist on-chain"); - - // const pollContractAddress = pollContractAddresses.get(0n); - const pollContract = getContract({ abi: PollAbi, address: pollContractAddress, publicClient }); - - const coordinatorPubKeyOnChain = await pollContract.read.coordinatorPubKey(); - - // assert(coordinatorPubKeyOnChain[0].toString() === coordinatorKeypair.pubKey.rawPubKey[0].toString()); - // assert(coordinatorPubKeyOnChain[1].toString() === coordinatorKeypair.pubKey.rawPubKey[1].toString()); - - const dd = await pollContract.read.getDeployTimeAndDuration(); - const deployTime = Number(dd[0]); - const duration = Number(dd[1]); - const onChainMaxValues = await pollContract.read.maxValues(); - const onChainTreeDepths = await pollContract.read.treeDepths(); - - const maxValues = { - maxMessages: Number(onChainMaxValues[0]), - maxVoteOptions: Number(onChainMaxValues[1]), - }; - const treeDepths = { - intStateTreeDepth: Number(onChainTreeDepths[0]), - messageTreeDepth: Number(onChainTreeDepths[1]), - messageTreeSubDepth: Number(onChainTreeDepths[2]), - voteOptionTreeDepth: Number(onChainTreeDepths[3]), - }; - const batchSizes = { - tallyBatchSize: STATE_TREE_ARITY ** Number(onChainTreeDepths[0]), - subsidyBatchSize: STATE_TREE_ARITY ** Number(onChainTreeDepths[0]), - messageBatchSize: STATE_TREE_ARITY ** Number(onChainTreeDepths[2]), - }; - - const publishMessageLogs = await pollContract.getEvents.PublishMessage({ fromBlock: startBlock }); - const topupLogs = await pollContract.getEvents.TopupMessage({ fromBlock: startBlock }); - const mergeMaciStateAqSubRootsLogs = await pollContract.getEvents.MergeMaciStateAqSubRoots({ fromBlock: startBlock }); - const mergeMaciStateAqLogs = await pollContract.getEvents.MergeMaciStateAq({ fromBlock: startBlock }); - const mergeMessageAqSubRootsLogs = await pollContract.getEvents.MergeMessageAqSubRoots({ fromBlock: startBlock }); - const mergeMessageAqLogs = await pollContract.getEvents.MergeMessageAq({ fromBlock: startBlock }); - - publishMessageLogs.forEach(log => { - if (log.args._message && log.args._encPubKey) { - const message = new Message(BigInt(log.args._message.msgType), log.args._message.data as any); - const encPubKey = new PubKey([log.args._encPubKey.x, log.args._encPubKey.y]); - - actions.push({ - type: "PublishMessage", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - message, - encPubKey, - }, - }); - } - }); - - topupLogs.forEach(log => { - if (log.args._message) { - const message = new Message(BigInt(log.args._message.msgType), log.args._message.data as any); - actions.push({ - type: "TopupMessage", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - message, - }, - }); - } - }); - - mergeMessageAqSubRootsLogs.forEach(log => { - if (log.args._numSrQueueOps) { - const numSrQueueOps = Number(log.args._numSrQueueOps); - actions.push({ - type: "MergeMessageAqSubRoots", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - numSrQueueOps, - }, - }); - } - }); - - // mergeMessageAqSubRootsLogs.forEach(log => { - // assert(!!log); - // const mutableLogs = { ...log, topics: [...log.topics] }; - // const event = pollIface.parseLog(mutableLogs) as unknown as { args: { _numSrQueueOps: string } }; - - // const numSrQueueOps = Number(event.args._numSrQueueOps); - // actions.push({ - // type: "MergeMessageAqSubRoots", - // blockNumber: log.blockNumber, - // transactionIndex: log.transactionIndex, - // data: { - // numSrQueueOps, - // }, - // }); - // }); - - mergeMessageAqLogs.forEach(log => { - if (log.args._messageRoot) { - const messageRoot = BigInt(log.args._messageRoot); - actions.push({ - type: "MergeMessageAq", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { messageRoot }, - }); - } - }); - - // mergeMessageAqLogs.forEach(log => { - // assert(!!log); - // const mutableLogs = { ...log, topics: [...log.topics] }; - // const event = pollIface.parseLog(mutableLogs); - - // const messageRoot = BigInt((event?.args as unknown as { _messageRoot: string })._messageRoot); - // actions.push({ - // type: "MergeMessageAq", - // blockNumber: log.blockNumber, - // transactionIndex: log.transactionIndex, - // data: { messageRoot }, - // }); - // }); - - // // Sort actions - actions = sortActions(actions); - - console.log(actions); - - // // Reconstruct MaciState in order - actions.forEach(action => { - // console.log("action: ", action); - switch (true) { - case action.type === "SignUp": { - const { pubKey, voiceCreditBalance, timestamp } = action.data; - - maciState.signUp(pubKey!, BigInt(voiceCreditBalance!), BigInt(timestamp!)); - break; - } - - case action.type === "DeployPoll" && action.data.pollAddr === pollContractAddress: { - maciState.deployPoll( - BigInt(deployTime + duration), - maxValues, - treeDepths, - batchSizes.messageBatchSize, - coordinatorKeypair, - ); - break; - } - - case action.type === "DeployPoll" && action.data.pollAddr !== pollContractAddress: { - maciState.deployNullPoll(); - break; - } - - case action.type === "PublishMessage": { - const { encPubKey, message } = action.data; - maciState.polls.get(pollId)?.publishMessage(message!, encPubKey!); - break; - } - - case action.type === "TopupMessage": { - const { message } = action.data; - maciState.polls.get(pollId)?.topupMessage(message!); - break; - } - - // ensure that the message root is correct (i.e. all messages have been published offchain) - case action.type === "MergeMessageAq": { - assert(maciState.polls.get(pollId)?.messageTree.root.toString() === action.data.messageRoot?.toString()); - break; - } - - default: - break; - } - }); - - // // Set numSignUps - const numSignUpsAndMessages = await pollContract.read.numSignUpsAndMessages(); - console.log(numSignUpsAndMessages); - - const poll = maciState.polls.get(pollId); - - // // ensure all messages were recorded - assert(Number(numSignUpsAndMessages[1]) === poll?.messages.length); - // set the number of signups - poll.updatePoll(numSignUpsAndMessages[0]); - - // // we need to ensure that the stateRoot is correct - assert(poll.stateTree?.root.toString() === (await pollContract.read.mergedStateRoot()).toString()); - - maciState.polls.set(pollId, poll); - - return maciState; -} - -// async function (provider: Provider, -// address: string, -// coordinatorKeypair: Keypair, -// pollId: bigint, -// fromBlock = 0, -// blocksPerRequest = 50, -// endBlock: number | undefined = undefined, -// sleepAmount: number | undefined = undefined, -// ): Promise { -// // ensure the pollId is valid -// assert(pollId >= 0); - -// const [pollContractAbi] = parseArtifact("Poll"); -// const [maciContractAbi] = parseArtifact("MACI"); - -// const maciContract = new BaseContract(address, maciContractAbi, provider) as MACI; - -// const maciIface = new Interface(maciContractAbi); -// const pollIface = new Interface(pollContractAbi); - -// // Check stateTreeDepth -// const stateTreeDepth = await maciContract.stateTreeDepth(); - -// // we need to pass the stateTreeDepth -// const maciState = new MaciState(Number(stateTreeDepth)); -// // ensure it is set correctly -// assert(stateTreeDepth === BigInt(maciState.stateTreeDepth)); - -// let signUpLogs: Log[] = []; -// let deployPollLogs: Log[] = []; - -// // if no last block is set then we fetch until the current block number -// const lastBlock = endBlock || (await provider.getBlockNumber()); - -// // Fetch event logs in batches (lastBlock inclusive) -// for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) { -// // the last block batch will be either current iteration block + blockPerRequest -// // or the end block if it is set -// const toBlock = i + blocksPerRequest >= lastBlock ? lastBlock : i + blocksPerRequest; - -// const [tmpSignUpLogs, tmpDeployPollLogs] = -// // eslint-disable-next-line no-await-in-loop -// await Promise.all([ -// maciContract.queryFilter(maciContract.filters.SignUp(), i, toBlock), -// maciContract.queryFilter(maciContract.filters.DeployPoll(), i, toBlock), -// ]); - -// signUpLogs = signUpLogs.concat(tmpSignUpLogs); -// deployPollLogs = deployPollLogs.concat(tmpDeployPollLogs); - -// if (sleepAmount) { -// // eslint-disable-next-line no-await-in-loop -// await sleep(sleepAmount); -// } -// } - -// let actions: Action[] = []; - -// signUpLogs.forEach(log => { -// assert(!!log); -// const mutableLog = { ...log, topics: [...log.topics] }; -// const event = maciIface.parseLog(mutableLog) as unknown as { -// args: { -// _stateIndex: number; -// _userPubKeyX: string; -// _userPubKeyY: string; -// _voiceCreditBalance: number; -// _timestamp: number; -// }; -// }; - -// actions.push({ -// type: "SignUp", -// blockNumber: log.blockNumber, -// transactionIndex: log.transactionIndex, -// data: { -// stateIndex: Number(event.args._stateIndex), -// pubKey: new PubKey([BigInt(event.args._userPubKeyX), BigInt(event.args._userPubKeyY)]), -// voiceCreditBalance: Number(event.args._voiceCreditBalance), -// timestamp: Number(event.args._timestamp), -// }, -// }); -// }); - -// let index = 0n; -// const foundPollIds: number[] = []; -// const pollContractAddresses = new Map(); - -// deployPollLogs.forEach(log => { -// assert(!!log); -// const mutableLogs = { ...log, topics: [...log.topics] }; -// const event = maciIface.parseLog(mutableLogs) as unknown as { -// args: { -// _coordinatorPubKeyX: string; -// _coordinatorPubKeyY: string; -// _pollId: bigint; -// pollAddr: { -// poll: string; -// messageProcessor: string; -// tally: string; -// }; -// }; -// }; - -// const pubKey = new PubKey([BigInt(event.args._coordinatorPubKeyX), BigInt(event.args._coordinatorPubKeyY)]); - -// const p = event.args._pollId; -// assert(p === index); - -// const pollAddr = event.args.pollAddr.poll; -// actions.push({ -// type: "DeployPoll", -// blockNumber: log.blockNumber, -// transactionIndex: log.transactionIndex, -// data: { pollId: p, pollAddr, pubKey }, -// }); - -// foundPollIds.push(Number(p)); -// pollContractAddresses.set(BigInt(p), pollAddr); -// index += 1n; -// }); - -// Check whether each pollId exists -// assert(foundPollIds.includes(Number(pollId)), "Error: the specified pollId does not exist on-chain"); - -// const pollContractAddress = pollContractAddresses.get(pollId)!; -// const pollContract = new BaseContract(pollContractAddress, pollContractAbi, provider) as Poll; - -// const coordinatorPubKeyOnChain = await pollContract.coordinatorPubKey(); -// assert(coordinatorPubKeyOnChain[0].toString() === coordinatorKeypair.pubKey.rawPubKey[0].toString()); -// assert(coordinatorPubKeyOnChain[1].toString() === coordinatorKeypair.pubKey.rawPubKey[1].toString()); - -// const dd = await pollContract.getDeployTimeAndDuration(); -// const deployTime = Number(dd[0]); -// const duration = Number(dd[1]); -// const onChainMaxValues = await pollContract.maxValues(); -// const onChainTreeDepths = await pollContract.treeDepths(); - -// const maxValues = { -// maxMessages: Number(onChainMaxValues.maxMessages), -// maxVoteOptions: Number(onChainMaxValues.maxVoteOptions), -// }; -// const treeDepths = { -// intStateTreeDepth: Number(onChainTreeDepths.intStateTreeDepth), -// messageTreeDepth: Number(onChainTreeDepths.messageTreeDepth), -// messageTreeSubDepth: Number(onChainTreeDepths.messageTreeSubDepth), -// voteOptionTreeDepth: Number(onChainTreeDepths.voteOptionTreeDepth), -// }; -// const batchSizes = { -// tallyBatchSize: STATE_TREE_ARITY ** Number(onChainTreeDepths.intStateTreeDepth), -// subsidyBatchSize: STATE_TREE_ARITY ** Number(onChainTreeDepths.intStateTreeDepth), -// messageBatchSize: STATE_TREE_ARITY ** Number(onChainTreeDepths.messageTreeSubDepth), -// }; - -// // fetch poll contract logs -// let publishMessageLogs: Log[] = []; -// let topupLogs: Log[] = []; -// let mergeMaciStateAqSubRootsLogs: Log[] = []; -// let mergeMaciStateAqLogs: Log[] = []; -// let mergeMessageAqSubRootsLogs: Log[] = []; -// let mergeMessageAqLogs: Log[] = []; - -// for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) { -// const toBlock = i + blocksPerRequest >= lastBlock ? lastBlock : i + blocksPerRequest; - -// const [ -// tmpPublishMessageLogs, -// tmpTopupLogs, -// tmpMergeMaciStateAqSubRootsLogs, -// tmpMergeMaciStateAqLogs, -// tmpMergeMessageAqSubRootsLogs, -// tmpMergeMessageAqLogs, -// // eslint-disable-next-line no-await-in-loop -// ] = await Promise.all([ -// pollContract.queryFilter(pollContract.filters.PublishMessage(), i, toBlock), -// pollContract.queryFilter(pollContract.filters.TopupMessage(), i, toBlock), -// pollContract.queryFilter(pollContract.filters.MergeMaciStateAqSubRoots(), i, toBlock), -// pollContract.queryFilter(pollContract.filters.MergeMaciStateAq(), i, toBlock), -// pollContract.queryFilter(pollContract.filters.MergeMessageAqSubRoots(), i, toBlock), -// pollContract.queryFilter(pollContract.filters.MergeMessageAq(), i, toBlock), -// ]); - -// publishMessageLogs = publishMessageLogs.concat(tmpPublishMessageLogs); -// topupLogs = topupLogs.concat(tmpTopupLogs); -// mergeMaciStateAqSubRootsLogs = mergeMaciStateAqSubRootsLogs.concat(tmpMergeMaciStateAqSubRootsLogs); -// mergeMaciStateAqLogs = mergeMaciStateAqLogs.concat(tmpMergeMaciStateAqLogs); -// mergeMessageAqSubRootsLogs = mergeMessageAqSubRootsLogs.concat(tmpMergeMessageAqSubRootsLogs); -// mergeMessageAqLogs = mergeMessageAqLogs.concat(tmpMergeMessageAqLogs); - -// if (sleepAmount) { -// // eslint-disable-next-line no-await-in-loop -// await sleep(sleepAmount); -// } -// } - -// publishMessageLogs.forEach(log => { -// assert(!!log); -// const mutableLogs = { ...log, topics: [...log.topics] }; -// const event = pollIface.parseLog(mutableLogs) as unknown as { -// args: { _message: [string, string[]]; _encPubKey: string[] }; -// }; - -// const message = new Message( -// BigInt(event.args._message[0]), - -// event.args._message[1].map(x => BigInt(x)), -// ); - -// const encPubKey = new PubKey(event.args._encPubKey.map(x => BigInt(x.toString())) as [bigint, bigint]); - -// actions.push({ -// type: "PublishMessage", -// blockNumber: log.blockNumber, -// transactionIndex: log.transactionIndex, -// data: { -// message, -// encPubKey, -// }, -// }); -// }); - -// topupLogs.forEach(log => { -// assert(!!log); -// const mutableLog = { ...log, topics: [...log.topics] }; -// const event = pollIface.parseLog(mutableLog) as unknown as { -// args: { _message: [string, string[]] }; -// }; -// const message = new Message( -// BigInt(event.args._message[0]), -// event.args._message[1].map(x => BigInt(x)), -// ); - -// actions.push({ -// type: "TopupMessage", -// blockNumber: log.blockNumber, -// transactionIndex: log.transactionIndex, -// data: { -// message, -// }, -// }); -// }); - -// mergeMessageAqSubRootsLogs.forEach(log => { -// assert(!!log); -// const mutableLogs = { ...log, topics: [...log.topics] }; -// const event = pollIface.parseLog(mutableLogs) as unknown as { args: { _numSrQueueOps: string } }; - -// const numSrQueueOps = Number(event.args._numSrQueueOps); -// actions.push({ -// type: "MergeMessageAqSubRoots", -// blockNumber: log.blockNumber, -// transactionIndex: log.transactionIndex, -// data: { -// numSrQueueOps, -// }, -// }); -// }); - -// mergeMessageAqLogs.forEach(log => { -// assert(!!log); -// const mutableLogs = { ...log, topics: [...log.topics] }; -// const event = pollIface.parseLog(mutableLogs); - -// const messageRoot = BigInt((event?.args as unknown as { _messageRoot: string })._messageRoot); -// actions.push({ -// type: "MergeMessageAq", -// blockNumber: log.blockNumber, -// transactionIndex: log.transactionIndex, -// data: { messageRoot }, -// }); -// }); - -// // Sort actions -// actions = sortActions(actions); - -// // Reconstruct MaciState in order -// actions.forEach(action => { -// switch (true) { -// case action.type === "SignUp": { -// const { pubKey, voiceCreditBalance, timestamp } = action.data; - -// maciState.signUp(pubKey!, BigInt(voiceCreditBalance!), BigInt(timestamp!)); -// break; -// } - -// case action.type === "DeployPoll" && action.data.pollId?.toString() === pollId.toString(): { -// maciState.deployPoll( -// BigInt(deployTime + duration), -// maxValues, -// treeDepths, -// batchSizes.messageBatchSize, -// coordinatorKeypair, -// ); -// break; -// } - -// case action.type === "DeployPoll" && action.data.pollId?.toString() !== pollId.toString(): { -// maciState.deployNullPoll(); -// break; -// } - -// case action.type === "PublishMessage": { -// const { encPubKey, message } = action.data; -// maciState.polls.get(pollId)?.publishMessage(message!, encPubKey!); -// break; -// } - -// case action.type === "TopupMessage": { -// const { message } = action.data; -// maciState.polls.get(pollId)?.topupMessage(message!); -// break; -// } - -// // ensure that the message root is correct (i.e. all messages have been published offchain) -// case action.type === "MergeMessageAq": { -// assert(maciState.polls.get(pollId)?.messageTree.root.toString() === action.data.messageRoot?.toString()); -// break; -// } - -// default: -// break; -// } -// }); - -// // Set numSignUps -// const numSignUpsAndMessages = await pollContract.numSignUpsAndMessages(); - -// const poll = maciState.polls.get(pollId); - -// // ensure all messages were recorded -// assert(Number(numSignUpsAndMessages[1]) === poll?.messages.length); -// // set the number of signups -// poll.updatePoll(numSignUpsAndMessages[0]); - -// // we need to ensure that the stateRoot is correct -// assert(poll.stateTree?.root.toString() === (await pollContract.mergedStateRoot()).toString()); - -// maciState.polls.set(pollId, poll); - -// return maciState; -// } diff --git a/packages/nextjs/utils/mergeMessages.ts b/packages/nextjs/utils/mergeMessages.ts deleted file mode 100644 index cbe42bd..0000000 --- a/packages/nextjs/utils/mergeMessages.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { DEFAULT_SR_QUEUE_OPS } from "./mergeSignups"; -import { getContract } from "viem"; -import AccQueueAbi from "~~/abi/AccQueue"; -import PollAbi from "~~/abi/Poll"; -import { publicClient, serverWalletClient } from "~~/constants"; - -export const mergeMessages = async ({ - pollContractAddress, - numQueueOps, -}: { - pollContractAddress: string; - numQueueOps?: number; -}): Promise => { - const pollContract = getContract({ - abi: PollAbi, - address: pollContractAddress, - publicClient, - walletClient: serverWalletClient, - }); - - const extContracts = await pollContract.read.extContracts(); - const messageAqContractAddr = extContracts[1]; - - const accQueueContract = getContract({ - abi: AccQueueAbi, - address: messageAqContractAddr, - publicClient, - walletClient: serverWalletClient, - }); - - // check if it's time to merge the message AQ - const dd = await pollContract.read.getDeployTimeAndDuration(); - const deadline = Number(dd[0]) + Number(dd[1]); - const { timestamp: now } = await publicClient.getBlock(); - - if (now < deadline) { - console.error("Voting period is not over"); - return; - } - - let subTreesMerged = false; - - // infinite loop to merge the sub trees - while (!subTreesMerged) { - // eslint-disable-next-line no-await-in-loop - subTreesMerged = await accQueueContract.read.subTreesMerged(); - - if (subTreesMerged) { - console.log("All message subtrees have been merged."); - } else { - // eslint-disable-next-line no-await-in-loop - await accQueueContract.read - .getSrIndices() - .then(data => data.map(x => Number(x))) - .then(indices => { - console.log(`Merging message subroots ${indices[0] + 1} / ${indices[1] + 1}`); - }); - - // eslint-disable-next-line no-await-in-loop - const tx = await pollContract.write.mergeMessageAqSubRoots([BigInt(numQueueOps || DEFAULT_SR_QUEUE_OPS)]); - // eslint-disable-next-line no-await-in-loop - - console.log(`Transaction hash: ${tx}`); - } - } - - // check if the message AQ has been fully merged - const messageTreeDepth = (await pollContract.read.treeDepths())[2]; - - // check if the main root was not already computed - const mainRoot = await accQueueContract.read.getMainRoot([BigInt(messageTreeDepth)]); - if (mainRoot === 0n) { - // go and merge the message tree - - console.log("Merging subroots to a main message root..."); - const tx = await pollContract.write.mergeMessageAq(); - - console.log(`Executed mergeMessageAq(); Transaction hash: ${tx}`); - console.log("The message tree has been merged."); - } else { - console.log("The message tree has already been merged."); - } -}; diff --git a/packages/nextjs/utils/mergeSignups.ts b/packages/nextjs/utils/mergeSignups.ts deleted file mode 100644 index 9e45d7e..0000000 --- a/packages/nextjs/utils/mergeSignups.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { getContract } from "viem"; -import AccQueueAbi from "~~/abi/AccQueue"; -import PollAbi from "~~/abi/Poll"; -import { maciContract, publicClient, serverWalletClient } from "~~/constants"; - -export const DEFAULT_SR_QUEUE_OPS = 4; - -export const mergeSignups = async ({ - pollContractAddress, - numQueueOps, -}: { - pollContractAddress: string; - numQueueOps?: number; -}): Promise => { - const pollId = await maciContract.read.getPollId([pollContractAddress]); - - const pollContract = getContract({ - abi: PollAbi, - address: pollContractAddress, - publicClient, - walletClient: serverWalletClient, - }); - - // if (pollId < 0) { - // logError("Invalid poll id"); - // } - - // const pollAddress = await maciContract.polls(pollId); - - const accQueueContract = getContract({ - abi: AccQueueAbi, - address: await maciContract.read.stateAq(), - publicClient, - walletClient: serverWalletClient, - }); - - // const accQueueContract = AccQueueFactory.connect(await maciContract.stateAq(), signer); - - // check if it's time to merge the message AQ - const dd = await pollContract.read.getDeployTimeAndDuration(); - const deadline = Number(dd[0]) + Number(dd[1]); - const { timestamp: now } = await publicClient.getBlock(); - - if (now < deadline) { - console.error("Voting period is not over"); - } - - let subTreesMerged = false; - - // infinite loop to merge the sub trees - while (!subTreesMerged) { - // eslint-disable-next-line no-await-in-loop - subTreesMerged = await accQueueContract.read.subTreesMerged(); - - if (subTreesMerged) { - console.log("All state subtrees have been merged."); - } else { - // eslint-disable-next-line no-await-in-loop - await accQueueContract.read - .getSrIndices() - .then(data => data.map(x => Number(x))) - .then(indices => { - console.log(`Merging state subroots ${indices[0] + 1} / ${indices[1] + 1}`); - }); - - // first merge the subroots - // eslint-disable-next-line no-await-in-loop - const tx = await pollContract.write.mergeMaciStateAqSubRoots([ - BigInt(numQueueOps || DEFAULT_SR_QUEUE_OPS), - pollId, - ]); - - console.log(`Transaction hash: ${tx}`); - // eslint-disable-next-line no-await-in-loop - // const receipt = await tx.wait(); - - // if (receipt?.status !== 1) { - // logError("Error merging state subroots"); - // } - - // logYellow(quiet, info(`Transaction hash: ${receipt!.hash}`)); - // logGreen(quiet, success(`Executed mergeMaciStateAqSubRoots(); gas used: ${receipt!.gasUsed.toString()}`)); - } - } - - // check if the state AQ has been fully merged - const stateTreeDepth = await maciContract.read.stateTreeDepth(); - - const mainRoot = await accQueueContract.read.getMainRoot([BigInt(stateTreeDepth)]); - - if (mainRoot === 0n || pollId > 0n) { - // go and merge the state tree - console.log("Merging subroots to a main state root..."); - try { - const tx = await pollContract.write.mergeMaciStateAq([pollId]); - - console.log(`Transaction hash: ${tx}`); - } catch (err) { - console.log("error here"); - // console.log(err); - } - } else { - console.log("The state tree has already been merged."); - } -}; diff --git a/packages/nextjs/utils/useGenerateProof.ts b/packages/nextjs/utils/useGenerateProof.ts deleted file mode 100644 index fb0acbc..0000000 --- a/packages/nextjs/utils/useGenerateProof.ts +++ /dev/null @@ -1,21 +0,0 @@ -"use server"; - -import { zKey } from "snarkjs"; - -export const cleanThreads = async (): Promise => { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (!globalThis) { - return; - } - - const curves = ["curve_bn128", "curve_bls12381"]; - await Promise.all( - curves.map(curve => (globalThis as any)[curve as "curve_bn128" | "curve_bls12381"]?.terminate()).filter(Boolean), - ); -}; - -export const extractVk = async (zkeyPath: string): Promise => { - const vk = await zKey.exportVerificationKey(zkeyPath); - await cleanThreads(); - return vk; -}; diff --git a/packages/nextjs/utils/useMergeMessages.ts b/packages/nextjs/utils/useMergeMessages.ts deleted file mode 100644 index 1a2efc7..0000000 --- a/packages/nextjs/utils/useMergeMessages.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { DEFAULT_SR_QUEUE_OPS } from "./useMergeSignups"; -import { getContract } from "viem"; -import { useContractRead, useContractWrite, usePublicClient } from "wagmi"; -import AccQueueAbi from "~~/abi/AccQueue"; -import PollAbi from "~~/abi/Poll"; -import { useScaffoldContractRead } from "~~/hooks/scaffold-eth"; - -export function useMergeMessages({ - pollContractAddress, - numQueueOps, - refresh, -}: { - pollContractAddress?: string; - numQueueOps?: number; - refresh: () => void; -}) { - const { data: dd, isFetched: deployTimeFetched } = useContractRead({ - abi: PollAbi, - address: pollContractAddress, - functionName: "getDeployTimeAndDuration", - }); - - const { data: extContracts, isFetched: extContractsFetched } = useContractRead({ - abi: PollAbi, - address: pollContractAddress, - functionName: "extContracts", - }); - - const { data: pollId, isFetched: pollIdFetched } = useScaffoldContractRead({ - contractName: "MACI", - functionName: "getPollId", - args: [pollContractAddress], - }); - - const messageAqContractAddr = extContracts?.[1]; - - const { writeAsync: mergeMessageAqSubRoots, isLoading: mergeMessageAqSubRootsLoading } = useContractWrite({ - abi: PollAbi, - address: pollContractAddress, - functionName: "mergeMessageAqSubRoots", - args: [BigInt(numQueueOps || DEFAULT_SR_QUEUE_OPS)], - }); - const { writeAsync: mergeMessageAq, isLoading: mergeMessageAqLoading } = useContractWrite({ - abi: PollAbi, - address: pollContractAddress, - functionName: "mergeMessageAq", - }); - - const publicClient = usePublicClient(); - - async function merge() { - if (!pollContractAddress || pollId === undefined || !dd || !messageAqContractAddr || !publicClient) { - return; - } - - // check if it's time to merge the message AQ - const deadline = Number(dd[0]) + Number(dd[1]); - const { timestamp: now } = await publicClient.getBlock(); - - if (now < deadline) { - console.error("Voting period is not over"); - return; - } - - const pollContract = getContract({ - abi: PollAbi, - address: pollContractAddress, - publicClient, - }); - - const accQueueContract = getContract({ - abi: AccQueueAbi, - address: messageAqContractAddr, - publicClient, - }); - - let subTreesMerged = false; - - console.log("I am here"); - - // infinite loop to merge the sub trees - while (!subTreesMerged) { - // eslint-disable-next-line no-await-in-loop - subTreesMerged = await accQueueContract.read.subTreesMerged(); - - if (subTreesMerged) { - console.log("All message subtrees have been merged."); - } else { - // eslint-disable-next-line no-await-in-loop - await accQueueContract.read - .getSrIndices() - .then(data => data.map(x => Number(x))) - .then(indices => { - console.log(`Merging message subroots ${indices[0] + 1} / ${indices[1] + 1}`); - }); - - // eslint-disable-next-line no-await-in-loop - const { hash: tx } = await mergeMessageAqSubRoots(); - // eslint-disable-next-line no-await-in-loop - - console.log(`Transaction hash: ${tx}`); - } - } - - // check if the message AQ has been fully merged - const messageTreeDepth = (await pollContract.read.treeDepths())[2]; - - // check if the main root was not already computed - const mainRoot = await accQueueContract.read.getMainRoot([BigInt(messageTreeDepth)]); - if (mainRoot === 0n) { - // go and merge the message tree - - console.log("Merging subroots to a main message root..."); - const { hash: tx } = await mergeMessageAq(); - - console.log(`Executed mergeMessageAq(); Transaction hash: ${tx}`); - console.log("The message tree has been merged."); - } else { - console.log("The message tree has already been merged."); - } - - refresh(); - } - - const loadingData = { - deployTimeFetched, - extContractsFetched, - pollIdFetched, - mergeMessageAqLoading, - mergeMessageAqSubRootsLoading, - }; - - return { merge, loadingData }; -} diff --git a/packages/nextjs/utils/useMergeSignups.ts b/packages/nextjs/utils/useMergeSignups.ts deleted file mode 100644 index 054999e..0000000 --- a/packages/nextjs/utils/useMergeSignups.ts +++ /dev/null @@ -1,131 +0,0 @@ -import { useState } from "react"; -import { getContract } from "viem"; -import { useContractRead, useContractWrite, usePublicClient } from "wagmi"; -import AccQueueAbi from "~~/abi/AccQueue"; -import PollAbi from "~~/abi/Poll"; -import { useScaffoldContract, useScaffoldContractRead } from "~~/hooks/scaffold-eth"; - -export const DEFAULT_SR_QUEUE_OPS = 4; - -export function useMergeSignups({ - pollContractAddress, - numQueueOps, - refresh, -}: { - pollContractAddress?: string; - numQueueOps?: number; - refresh: () => void; -}) { - const { data: dd, isFetched: deployTimeFetched } = useContractRead({ - abi: PollAbi, - address: pollContractAddress, - functionName: "getDeployTimeAndDuration", - }); - const { data: pollId, isFetched: pollIdFetched } = useScaffoldContractRead({ - contractName: "MACI", - functionName: "getPollId", - args: [pollContractAddress], - }); - const { data: accQueueContractAddress, isFetched: accQueueContractAddressFetched } = useScaffoldContractRead({ - contractName: "MACI", - functionName: "stateAq", - }); - const publicClient = usePublicClient(); - const { data: maci } = useScaffoldContract({ contractName: "MACI" }); - const { writeAsync: mergeMaciStateAqSubRoots, isLoading: mergeMaciStateAqSubRootsLoading } = useContractWrite({ - abi: PollAbi, - address: pollContractAddress, - functionName: "mergeMaciStateAqSubRoots", - args: pollId !== undefined ? [BigInt(numQueueOps || DEFAULT_SR_QUEUE_OPS), pollId] : undefined, - }); - const { writeAsync: mergeMaciStateAq, isLoading: mergeMaciStateAqLoading } = useContractWrite({ - abi: PollAbi, - address: pollContractAddress, - functionName: "mergeMaciStateAq", - args: pollId !== undefined ? [pollId] : undefined, - }); - - const [mergeLoading, setMergeLoading] = useState(false); - - async function merge() { - if (!pollContractAddress || pollId === undefined || !dd || !accQueueContractAddress || !maci) { - return; - } - - const deadline = Number(dd[0]) + Number(dd[1]); - const { timestamp: now } = await publicClient.getBlock(); - - if (now < deadline) { - console.error("Voting period is not over"); - return; - } - - setMergeLoading(true); - - const accQueueContract = getContract({ - abi: AccQueueAbi, - address: accQueueContractAddress, - publicClient, - }); - - let subTreesMerged = false; - - // infinite loop to merge the sub trees - while (!subTreesMerged) { - // eslint-disable-next-line no-await-in-loop - subTreesMerged = await accQueueContract.read.subTreesMerged(); - - if (subTreesMerged) { - console.log("All state subtrees have been merged."); - } else { - // eslint-disable-next-line no-await-in-loop - await accQueueContract.read - .getSrIndices() - .then(data => data.map(x => Number(x))) - .then(indices => { - console.log(`Merging state subroots ${indices[0] + 1} / ${indices[1] + 1}`); - }); - - // first merge the subroots - // eslint-disable-next-line no-await-in-loop - const { hash: tx } = await mergeMaciStateAqSubRoots(); - - console.log(`Transaction hash: ${tx}`); - } - } - - const stateTreeDepth = await maci.read.stateTreeDepth(); - - const mainRoot = await accQueueContract.read.getMainRoot([BigInt(stateTreeDepth)]); - - if (mainRoot !== 0n && !pollId) { - console.log("The state tree has already been merged."); - return; - } - - // go and merge the state tree - console.log("Merging subroots to a main state root..."); - try { - const { hash: tx } = await mergeMaciStateAq(); - - console.log(`Transaction hash: ${tx}`); - } catch (err) { - console.log("error here"); - } - - setMergeLoading(false); - - refresh(); - } - - const loadingData = { - deployTimeFetched, - pollIdFetched, - accQueueContractAddressFetched, - mergeMaciStateAqSubRootsLoading, - mergeMaciStateAqLoading, - mergeLoading, - }; - - return { merge, loadingData }; -} diff --git a/packages/prover/.env.template b/packages/prover/.env.template deleted file mode 100644 index e69de29..0000000 diff --git a/packages/prover/.gitignore b/packages/prover/.gitignore deleted file mode 100644 index 40d81dd..0000000 --- a/packages/prover/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.env -zkeys diff --git a/packages/prover/README.md b/packages/prover/README.md deleted file mode 100644 index e5278a3..0000000 --- a/packages/prover/README.md +++ /dev/null @@ -1 +0,0 @@ -# prover diff --git a/packages/prover/package.json b/packages/prover/package.json deleted file mode 100644 index b9d100e..0000000 --- a/packages/prover/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "prover", - "packageManager": "yarn@3.2.3", - "scripts": { - "start": "ts-node src/index.ts" - }, - "dependencies": { - "@se-2/hardhat": "*", - "@se-2/nextjs": "*", - "cors": "^2.8.5", - "dotenv": "^16.4.5", - "ethers": "^6.10.0", - "express": "^4.19.2", - "snarkjs": "^0.7.3" - }, - "devDependencies": { - "@types/cors": "^2", - "@types/express": "^4", - "@types/node": "^20.12.7", - "@types/snarkjs": "^0", - "ts-node": "^10.9.2", - "tsc": "^2.0.4", - "typescript": "^5.4.5" - } -} diff --git a/packages/prover/src/abi/AccQueue.ts b/packages/prover/src/abi/AccQueue.ts deleted file mode 100644 index 9d85e37..0000000 --- a/packages/prover/src/abi/AccQueue.ts +++ /dev/null @@ -1,496 +0,0 @@ -export default [ - { - inputs: [], - name: "DepthCannotBeZero", - type: "error", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_depth", - type: "uint256", - }, - { - internalType: "uint256", - name: "max", - type: "uint256", - }, - ], - name: "DepthTooLarge", - type: "error", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_depth", - type: "uint256", - }, - { - internalType: "uint256", - name: "min", - type: "uint256", - }, - ], - name: "DepthTooSmall", - type: "error", - }, - { - inputs: [], - name: "InvalidHashLength", - type: "error", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_index", - type: "uint256", - }, - ], - name: "InvalidIndex", - type: "error", - }, - { - inputs: [], - name: "InvalidLevel", - type: "error", - }, - { - inputs: [], - name: "NothingToMerge", - type: "error", - }, - { - inputs: [], - name: "SubDepthCannotBeZero", - type: "error", - }, - { - inputs: [], - name: "SubTreesAlreadyMerged", - type: "error", - }, - { - inputs: [], - name: "SubTreesNotMerged", - type: "error", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_subDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "max", - type: "uint256", - }, - ], - name: "SubdepthTooLarge", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - inputs: [], - name: "MAX_DEPTH", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "calcMinHeight", - outputs: [ - { - internalType: "uint256", - name: "depth", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_leaf", - type: "uint256", - }, - ], - name: "enqueue", - outputs: [ - { - internalType: "uint256", - name: "leafIndex", - type: "uint256", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "fill", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_depth", - type: "uint256", - }, - ], - name: "getMainRoot", - outputs: [ - { - internalType: "uint256", - name: "mainRoot", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getSmallSRTroot", - outputs: [ - { - internalType: "uint256", - name: "smallSubTreeRoot", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getSrIndices", - outputs: [ - { - internalType: "uint256", - name: "next", - type: "uint256", - }, - { - internalType: "uint256", - name: "current", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_index", - type: "uint256", - }, - ], - name: "getSubRoot", - outputs: [ - { - internalType: "uint256", - name: "subRoot", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[2]", - name: "array", - type: "uint256[2]", - }, - ], - name: "hash2", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[3]", - name: "array", - type: "uint256[3]", - }, - ], - name: "hash3", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[4]", - name: "array", - type: "uint256[4]", - }, - ], - name: "hash4", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[5]", - name: "array", - type: "uint256[5]", - }, - ], - name: "hash5", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "left", - type: "uint256", - }, - { - internalType: "uint256", - name: "right", - type: "uint256", - }, - ], - name: "hashLeftRight", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_level", - type: "uint256", - }, - { - internalType: "uint256", - name: "_leaf", - type: "uint256", - }, - ], - name: "hashLevelLeaf", - outputs: [ - { - internalType: "uint256", - name: "_hash", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_subRoot", - type: "uint256", - }, - ], - name: "insertSubTree", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_depth", - type: "uint256", - }, - ], - name: "merge", - outputs: [ - { - internalType: "uint256", - name: "root", - type: "uint256", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_numSrQueueOps", - type: "uint256", - }, - ], - name: "mergeSubRoots", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "numLeaves", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[]", - name: "array", - type: "uint256[]", - }, - ], - name: "sha256Hash", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [], - name: "subTreesMerged", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "treeMerged", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, -] as const; diff --git a/packages/prover/src/abi/MACI.ts b/packages/prover/src/abi/MACI.ts deleted file mode 100644 index e69de29..0000000 diff --git a/packages/prover/src/abi/Poll.ts b/packages/prover/src/abi/Poll.ts deleted file mode 100644 index 1f33906..0000000 --- a/packages/prover/src/abi/Poll.ts +++ /dev/null @@ -1,966 +0,0 @@ -export default [ - { - inputs: [ - { - internalType: "uint256", - name: "_duration", - type: "uint256", - }, - { - components: [ - { - internalType: "uint256", - name: "maxMessages", - type: "uint256", - }, - { - internalType: "uint256", - name: "maxVoteOptions", - type: "uint256", - }, - ], - internalType: "struct Params.MaxValues", - name: "_maxValues", - type: "tuple", - }, - { - components: [ - { - internalType: "uint8", - name: "intStateTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeSubDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "voteOptionTreeDepth", - type: "uint8", - }, - ], - internalType: "struct Params.TreeDepths", - name: "_treeDepths", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_coordinatorPubKey", - type: "tuple", - }, - { - components: [ - { - internalType: "contract IMACI", - name: "maci", - type: "address", - }, - { - internalType: "contract AccQueue", - name: "messageAq", - type: "address", - }, - { - internalType: "contract TopupCredit", - name: "topupCredit", - type: "address", - }, - ], - internalType: "struct Params.ExtContracts", - name: "_extContracts", - type: "tuple", - }, - ], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [], - name: "InvalidBatchLength", - type: "error", - }, - { - inputs: [], - name: "InvalidMessage", - type: "error", - }, - { - inputs: [], - name: "MaciPubKeyLargerThanSnarkFieldSize", - type: "error", - }, - { - inputs: [], - name: "PollAlreadyInit", - type: "error", - }, - { - inputs: [], - name: "StateAqAlreadyMerged", - type: "error", - }, - { - inputs: [], - name: "StateAqSubtreesNeedMerge", - type: "error", - }, - { - inputs: [], - name: "TooManyMessages", - type: "error", - }, - { - inputs: [], - name: "VotingPeriodNotOver", - type: "error", - }, - { - inputs: [], - name: "VotingPeriodOver", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "uint256", - name: "_stateRoot", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "_numSignups", - type: "uint256", - }, - ], - name: "MergeMaciStateAq", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "uint256", - name: "_numSrQueueOps", - type: "uint256", - }, - ], - name: "MergeMaciStateAqSubRoots", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "uint256", - name: "_messageRoot", - type: "uint256", - }, - ], - name: "MergeMessageAq", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "uint256", - name: "_numSrQueueOps", - type: "uint256", - }, - ], - name: "MergeMessageAqSubRoots", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - indexed: false, - internalType: "struct DomainObjs.Message", - name: "_message", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - indexed: false, - internalType: "struct DomainObjs.PubKey", - name: "_encPubKey", - type: "tuple", - }, - ], - name: "PublishMessage", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - indexed: false, - internalType: "struct DomainObjs.Message", - name: "_message", - type: "tuple", - }, - ], - name: "TopupMessage", - type: "event", - }, - { - inputs: [], - name: "MESSAGE_DATA_LENGTH", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "coordinatorPubKey", - outputs: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "coordinatorPubKeyHash", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "currentSbCommitment", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "extContracts", - outputs: [ - { - internalType: "contract IMACI", - name: "maci", - type: "address", - }, - { - internalType: "contract AccQueue", - name: "messageAq", - type: "address", - }, - { - internalType: "contract TopupCredit", - name: "topupCredit", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getDeployTimeAndDuration", - outputs: [ - { - internalType: "uint256", - name: "pollDeployTime", - type: "uint256", - }, - { - internalType: "uint256", - name: "pollDuration", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[2]", - name: "array", - type: "uint256[2]", - }, - ], - name: "hash2", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[3]", - name: "array", - type: "uint256[3]", - }, - ], - name: "hash3", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[4]", - name: "array", - type: "uint256[4]", - }, - ], - name: "hash4", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[5]", - name: "array", - type: "uint256[5]", - }, - ], - name: "hash5", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "left", - type: "uint256", - }, - { - internalType: "uint256", - name: "right", - type: "uint256", - }, - ], - name: "hashLeftRight", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - internalType: "struct DomainObjs.Message", - name: "_message", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_encPubKey", - type: "tuple", - }, - ], - name: "hashMessageAndEncPubKey", - outputs: [ - { - internalType: "uint256", - name: "msgHash", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "pubKey", - type: "tuple", - }, - { - internalType: "uint256", - name: "voiceCreditBalance", - type: "uint256", - }, - { - internalType: "uint256", - name: "timestamp", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.StateLeaf", - name: "_stateLeaf", - type: "tuple", - }, - ], - name: "hashStateLeaf", - outputs: [ - { - internalType: "uint256", - name: "ciphertext", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [], - name: "init", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "maxValues", - outputs: [ - { - internalType: "uint256", - name: "maxMessages", - type: "uint256", - }, - { - internalType: "uint256", - name: "maxVoteOptions", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - ], - name: "mergeMaciStateAq", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_numSrQueueOps", - type: "uint256", - }, - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - ], - name: "mergeMaciStateAqSubRoots", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "mergeMessageAq", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_numSrQueueOps", - type: "uint256", - }, - ], - name: "mergeMessageAqSubRoots", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "mergedStateRoot", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "numMessages", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "numSignUpsAndMessages", - outputs: [ - { - internalType: "uint256", - name: "numSUps", - type: "uint256", - }, - { - internalType: "uint256", - name: "numMsgs", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "numSignups", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[2]", - name: "dataToPad", - type: "uint256[2]", - }, - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - ], - name: "padAndHashMessage", - outputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - internalType: "struct DomainObjs.Message", - name: "message", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "padKey", - type: "tuple", - }, - { - internalType: "uint256", - name: "msgHash", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - internalType: "struct DomainObjs.Message", - name: "_message", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_encPubKey", - type: "tuple", - }, - ], - name: "publishMessage", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - internalType: "struct DomainObjs.Message[]", - name: "_messages", - type: "tuple[]", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey[]", - name: "_encPubKeys", - type: "tuple[]", - }, - ], - name: "publishMessageBatch", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[]", - name: "array", - type: "uint256[]", - }, - ], - name: "sha256Hash", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [], - name: "stateAqMerged", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "stateIndex", - type: "uint256", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "topup", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "treeDepths", - outputs: [ - { - internalType: "uint8", - name: "intStateTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeSubDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "voteOptionTreeDepth", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, -] as const; diff --git a/packages/prover/src/config.ts b/packages/prover/src/config.ts deleted file mode 100644 index 240b75a..0000000 --- a/packages/prover/src/config.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { extractVk } from "./utils"; -import { Keypair, PrivKey } from "@se-2/hardhat/maci-ts/domainobjs"; -import { ethers } from "ethers"; -import "dotenv/config"; -import deployedContracts from "./deployedContracts"; - -const coordinatorPrivKey = process.env.COORDINATOR_PRIV_KEY || ""; -export const processZkeyPath = process.env.PROCESS_ZKEY_PATH || ""; -export const processWasmPath = process.env.PROCESS_WASM_PATH || ""; -export const tallyZkeyPath = process.env.TALLY_ZKEY_PATH || ""; -export const tallyWasmPath = process.env.TALLY_WASM_PATH || ""; -export const useQuadraticVoting = false; -const rpcUrl = process.env.RPC_URL || ""; -const signerPrivateKey = process.env.SIGNER_PRIVATE_KEY || ""; -const maciPrivKey = PrivKey.deserialize(coordinatorPrivKey); - -// the coordinator's MACI private key -if (!PrivKey.isValidSerializedPrivKey(coordinatorPrivKey)) { - throw "Invalid MACI private key"; -} - -const chainId = Number(process.env.CHAIN_ID || 31337); - -export const { MACI: maciContractDetails } = (deployedContracts as any)[ - chainId -]; -export const { PollManager: pollManagerContractDetails } = ( - deployedContracts as any -)[chainId]; - -export const blocksPerBatch = 50; -export const deploymentBlockNumber = maciContractDetails.deploymentBlockNumber; -export const provider = new ethers.JsonRpcProvider(rpcUrl); -export let processVk: any, tallyVk: any; -export let coordinatorKeypair = new Keypair(maciPrivKey); -export const signer = new ethers.Wallet(signerPrivateKey, provider); -export const maciContract = new ethers.Contract( - maciContractDetails.address, - maciContractDetails.abi, - signer -); -export const pollManagerContract = new ethers.Contract( - pollManagerContractDetails.address, - pollManagerContractDetails.abi, - signer -); -export const PORT = 8000; - -export async function configure() { - console.log("Configuring..."); - // extract the rest of the verifying keys - processVk = await extractVk(processZkeyPath); - tallyVk = await extractVk(tallyZkeyPath); - console.log("Configured!!!"); -} diff --git a/packages/prover/src/contract.ts b/packages/prover/src/contract.ts deleted file mode 100644 index e757fc0..0000000 --- a/packages/prover/src/contract.ts +++ /dev/null @@ -1,441 +0,0 @@ -import { MaciState, STATE_TREE_ARITY } from "@se-2/hardhat/maci-ts/core"; -import assert from "assert"; -import { maciContract, maciContractDetails } from "./config"; -import { BaseContract, Interface, Log, Provider } from "ethers"; -import { sleep, sortActions } from "@se-2/hardhat/maci-ts/ts/utils"; -import { Action } from "@se-2/hardhat/maci-ts/ts/types"; -import { Keypair, Message, PubKey } from "@se-2/hardhat/maci-ts/domainobjs"; -import { Poll } from "@se-2/hardhat/typechain-types"; -import pollContractAbi from "./abi/Poll"; - -export const genMaciStateFromContract = async ( - provider: Provider, - coordinatorKeypair: Keypair, - pollId: bigint, - fromBlock = 0, - blocksPerRequest = 50, - endBlock: number | undefined = undefined, - sleepAmount: number | undefined = undefined -): Promise => { - // ensure the pollId is valid - assert(pollId >= 0); - - const maciIface = new Interface(maciContractDetails.abi); - const pollIface = new Interface(pollContractAbi); - - // Check stateTreeDepth - const stateTreeDepth = await maciContract.stateTreeDepth(); - - // we need to pass the stateTreeDepth - const maciState = new MaciState(Number(stateTreeDepth)); - // ensure it is set correctly - assert(stateTreeDepth === BigInt(maciState.stateTreeDepth)); - - let signUpLogs: Log[] = []; - let deployPollLogs: Log[] = []; - - // if no last block is set then we fetch until the current block number - const lastBlock = endBlock || (await provider.getBlockNumber()); - - // Fetch event logs in batches (lastBlock inclusive) - for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) { - // the last block batch will be either current iteration block + blockPerRequest - // or the end block if it is set - const toBlock = - i + blocksPerRequest >= lastBlock ? lastBlock : i + blocksPerRequest; - - const [tmpSignUpLogs, tmpDeployPollLogs] = - // eslint-disable-next-line no-await-in-loop - await Promise.all([ - maciContract.queryFilter(maciContract.filters.SignUp(), i, toBlock), - maciContract.queryFilter(maciContract.filters.DeployPoll(), i, toBlock), - ]); - - signUpLogs = signUpLogs.concat(tmpSignUpLogs); - deployPollLogs = deployPollLogs.concat(tmpDeployPollLogs); - - if (sleepAmount) { - // eslint-disable-next-line no-await-in-loop - await sleep(sleepAmount); - } - } - - let actions: Action[] = []; - - signUpLogs.forEach((log) => { - assert(!!log); - const mutableLog = { ...log, topics: [...log.topics] }; - const event = maciIface.parseLog(mutableLog) as unknown as { - args: { - _stateIndex: number; - _userPubKeyX: string; - _userPubKeyY: string; - _voiceCreditBalance: number; - _timestamp: number; - }; - }; - - actions.push({ - type: "SignUp", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - stateIndex: Number(event.args._stateIndex), - pubKey: new PubKey([ - BigInt(event.args._userPubKeyX), - BigInt(event.args._userPubKeyY), - ]), - voiceCreditBalance: Number(event.args._voiceCreditBalance), - timestamp: Number(event.args._timestamp), - }, - }); - }); - - let index = 0n; - const foundPollIds: number[] = []; - const pollContractAddresses = new Map(); - - deployPollLogs.forEach((log) => { - assert(!!log); - const mutableLogs = { ...log, topics: [...log.topics] }; - const event = maciIface.parseLog(mutableLogs) as unknown as { - args: { - _coordinatorPubKeyX: string; - _coordinatorPubKeyY: string; - _pollId: bigint; - pollAddr: { - poll: string; - messageProcessor: string; - tally: string; - }; - }; - }; - - const pubKey = new PubKey([ - BigInt(event.args._coordinatorPubKeyX), - BigInt(event.args._coordinatorPubKeyY), - ]); - - const p = event.args._pollId; - assert(p === index); - - const pollAddr = event.args.pollAddr.poll; - actions.push({ - type: "DeployPoll", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { pollId: p, pollAddr, pubKey }, - }); - - foundPollIds.push(Number(p)); - pollContractAddresses.set(BigInt(p), pollAddr); - index += 1n; - }); - - // Check whether each pollId exists - assert( - foundPollIds.includes(Number(pollId)), - "Error: the specified pollId does not exist on-chain" - ); - - const pollContractAddress = pollContractAddresses.get(pollId)!; - const pollContract = new BaseContract( - pollContractAddress, - pollContractAbi, - provider - ) as unknown as Poll; - - const coordinatorPubKeyOnChain = await pollContract.coordinatorPubKey(); - assert( - coordinatorPubKeyOnChain[0].toString() === - coordinatorKeypair.pubKey.rawPubKey[0].toString() - ); - assert( - coordinatorPubKeyOnChain[1].toString() === - coordinatorKeypair.pubKey.rawPubKey[1].toString() - ); - - const dd = await pollContract.getDeployTimeAndDuration(); - const deployTime = Number(dd[0]); - const duration = Number(dd[1]); - const onChainMaxValues = await pollContract.maxValues(); - const onChainTreeDepths = await pollContract.treeDepths(); - - const maxValues = { - maxMessages: Number(onChainMaxValues.maxMessages), - maxVoteOptions: Number(onChainMaxValues.maxVoteOptions), - }; - const treeDepths = { - intStateTreeDepth: Number(onChainTreeDepths.intStateTreeDepth), - messageTreeDepth: Number(onChainTreeDepths.messageTreeDepth), - messageTreeSubDepth: Number(onChainTreeDepths.messageTreeSubDepth), - voteOptionTreeDepth: Number(onChainTreeDepths.voteOptionTreeDepth), - }; - const batchSizes = { - tallyBatchSize: - STATE_TREE_ARITY ** Number(onChainTreeDepths.intStateTreeDepth), - messageBatchSize: - STATE_TREE_ARITY ** Number(onChainTreeDepths.messageTreeSubDepth), - }; - - // fetch poll contract logs - let publishMessageLogs: Log[] = []; - let topupLogs: Log[] = []; - let mergeMaciStateAqSubRootsLogs: Log[] = []; - let mergeMaciStateAqLogs: Log[] = []; - let mergeMessageAqSubRootsLogs: Log[] = []; - let mergeMessageAqLogs: Log[] = []; - - for (let i = fromBlock; i <= lastBlock; i += blocksPerRequest + 1) { - const toBlock = - i + blocksPerRequest >= lastBlock ? lastBlock : i + blocksPerRequest; - - const [ - tmpPublishMessageLogs, - tmpTopupLogs, - tmpMergeMaciStateAqSubRootsLogs, - tmpMergeMaciStateAqLogs, - tmpMergeMessageAqSubRootsLogs, - tmpMergeMessageAqLogs, - // eslint-disable-next-line no-await-in-loop - ] = await Promise.all([ - pollContract.queryFilter( - pollContract.filters.PublishMessage(), - i, - toBlock - ), - pollContract.queryFilter(pollContract.filters.TopupMessage(), i, toBlock), - pollContract.queryFilter( - pollContract.filters.MergeMaciStateAqSubRoots(), - i, - toBlock - ), - pollContract.queryFilter( - pollContract.filters.MergeMaciStateAq(), - i, - toBlock - ), - pollContract.queryFilter( - pollContract.filters.MergeMessageAqSubRoots(), - i, - toBlock - ), - pollContract.queryFilter( - pollContract.filters.MergeMessageAq(), - i, - toBlock - ), - ]); - - publishMessageLogs = publishMessageLogs.concat( - tmpPublishMessageLogs as any - ); - topupLogs = topupLogs.concat(tmpTopupLogs as any); - mergeMaciStateAqSubRootsLogs = mergeMaciStateAqSubRootsLogs.concat( - tmpMergeMaciStateAqSubRootsLogs as any - ); - mergeMaciStateAqLogs = mergeMaciStateAqLogs.concat( - tmpMergeMaciStateAqLogs as any - ); - mergeMessageAqSubRootsLogs = mergeMessageAqSubRootsLogs.concat( - tmpMergeMessageAqSubRootsLogs as any - ); - mergeMessageAqLogs = mergeMessageAqLogs.concat( - tmpMergeMessageAqLogs as any - ); - - if (sleepAmount) { - // eslint-disable-next-line no-await-in-loop - await sleep(sleepAmount); - } - } - - publishMessageLogs.forEach((log) => { - assert(!!log); - const mutableLogs = { ...log, topics: [...log.topics] }; - const event = pollIface.parseLog(mutableLogs) as unknown as { - args: { _message: [string, string[]]; _encPubKey: string[] }; - }; - - const message = new Message( - BigInt(event.args._message[0]), - - event.args._message[1].map((x) => BigInt(x)) as [ - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint - ] - ); - - const encPubKey = new PubKey( - event.args._encPubKey.map((x) => BigInt(x.toString())) as [bigint, bigint] - ); - - actions.push({ - type: "PublishMessage", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - message, - encPubKey, - }, - }); - }); - - topupLogs.forEach((log) => { - assert(!!log); - const mutableLog = { ...log, topics: [...log.topics] }; - const event = pollIface.parseLog(mutableLog) as unknown as { - args: { _message: [string, string[]] }; - }; - const message = new Message( - BigInt(event.args._message[0]), - event.args._message[1].map((x) => BigInt(x)) as [ - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint, - bigint - ] - ); - - actions.push({ - type: "TopupMessage", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - message, - }, - }); - }); - - mergeMessageAqSubRootsLogs.forEach((log) => { - assert(!!log); - const mutableLogs = { ...log, topics: [...log.topics] }; - const event = pollIface.parseLog(mutableLogs) as unknown as { - args: { _numSrQueueOps: string }; - }; - - const numSrQueueOps = Number(event.args._numSrQueueOps); - actions.push({ - type: "MergeMessageAqSubRoots", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { - numSrQueueOps, - }, - }); - }); - - mergeMessageAqLogs.forEach((log) => { - assert(!!log); - const mutableLogs = { ...log, topics: [...log.topics] }; - const event = pollIface.parseLog(mutableLogs); - - const messageRoot = BigInt( - (event?.args as unknown as { _messageRoot: string })._messageRoot - ); - actions.push({ - type: "MergeMessageAq", - blockNumber: log.blockNumber, - transactionIndex: log.transactionIndex, - data: { messageRoot }, - }); - }); - - // Sort actions - actions = sortActions(actions); - - // Reconstruct MaciState in order - actions.forEach((action) => { - switch (true) { - case action.type === "SignUp": { - const { pubKey, voiceCreditBalance, timestamp } = action.data; - - maciState.signUp( - pubKey!, - BigInt(voiceCreditBalance!), - BigInt(timestamp!) - ); - break; - } - - case action.type === "DeployPoll" && - action.data.pollId?.toString() === pollId.toString(): { - maciState.deployPoll( - BigInt(deployTime + duration), - maxValues, - treeDepths, - batchSizes.messageBatchSize, - coordinatorKeypair - ); - break; - } - - case action.type === "DeployPoll" && - action.data.pollId?.toString() !== pollId.toString(): { - maciState.deployNullPoll(); - break; - } - - case action.type === "PublishMessage": { - const { encPubKey, message } = action.data; - maciState.polls.get(pollId)?.publishMessage(message!, encPubKey!); - break; - } - - case action.type === "TopupMessage": { - const { message } = action.data; - maciState.polls.get(pollId)?.topupMessage(message!); - break; - } - - // ensure that the message root is correct (i.e. all messages have been published offchain) - case action.type === "MergeMessageAq": { - assert( - maciState.polls.get(pollId)?.messageTree.root.toString() === - action.data.messageRoot?.toString() - ); - break; - } - - default: - break; - } - }); - - // Set numSignUps - const numSignUpsAndMessages = await pollContract.numSignUpsAndMessages(); - - const poll = maciState.polls.get(pollId); - - // ensure all messages were recorded - assert(Number(numSignUpsAndMessages[1]) === poll?.messages.length); - // set the number of signups - poll.updatePoll(numSignUpsAndMessages[0]); - - console.log(poll.stateTree?.root); - console.log(await pollContract.mergedStateRoot()); - - // we need to ensure that the stateRoot is correct - assert( - poll.stateTree?.root.toString() === - (await pollContract.mergedStateRoot()).toString() - ); - - maciState.polls.set(pollId, poll); - - return maciState; -}; diff --git a/packages/prover/src/deployedContracts.ts b/packages/prover/src/deployedContracts.ts deleted file mode 100644 index 9bbfb73..0000000 --- a/packages/prover/src/deployedContracts.ts +++ /dev/null @@ -1,3646 +0,0 @@ -const deployedContracts = { - 31337: { - ConstantInitialVoiceCreditProxy: { - address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", - abi: [ - { - inputs: [ - { - internalType: "uint256", - name: "_balance", - type: "uint256", - }, - ], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - { - internalType: "bytes", - name: "", - type: "bytes", - }, - ], - name: "getVoiceCredits", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - ], - inheritedFunctions: { - getVoiceCredits: - "contracts/maci-contracts/initialVoiceCreditProxy/InitialVoiceCreditProxy.sol", - }, - deploymentBlockNumber: 1, - }, - FreeForAllGatekeeper: { - address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", - abi: [ - { - inputs: [], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [ - { - internalType: "address", - name: "_address", - type: "address", - }, - { - internalType: "bytes", - name: "_data", - type: "bytes", - }, - ], - name: "register", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_maci", - type: "address", - }, - ], - name: "setMaciInstance", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: {}, - deploymentBlockNumber: 3, - }, - MACI: { - address: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e", - abi: [ - { - inputs: [ - { - internalType: "contract IPollFactory", - name: "_pollFactory", - type: "address", - }, - { - internalType: "contract IMessageProcessorFactory", - name: "_messageProcessorFactory", - type: "address", - }, - { - internalType: "contract ITallyFactory", - name: "_tallyFactory", - type: "address", - }, - { - internalType: "contract SignUpGatekeeper", - name: "_signUpGatekeeper", - type: "address", - }, - { - internalType: "contract InitialVoiceCreditProxy", - name: "_initialVoiceCreditProxy", - type: "address", - }, - { - internalType: "contract TopupCredit", - name: "_topupCredit", - type: "address", - }, - { - internalType: "uint8", - name: "_stateTreeDepth", - type: "uint8", - }, - ], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [ - { - internalType: "address", - name: "_caller", - type: "address", - }, - ], - name: "CallerMustBePoll", - type: "error", - }, - { - inputs: [], - name: "InvalidMessage", - type: "error", - }, - { - inputs: [], - name: "MaciPubKeyLargerThanSnarkFieldSize", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "pollAddr", - type: "address", - }, - ], - name: "PollAddressDoesNotExist", - type: "error", - }, - { - inputs: [ - { - internalType: "uint256", - name: "pollId", - type: "uint256", - }, - ], - name: "PollDoesNotExist", - type: "error", - }, - { - inputs: [], - name: "PoseidonHashLibrariesNotLinked", - type: "error", - }, - { - inputs: [ - { - internalType: "uint256", - name: "pollId", - type: "uint256", - }, - ], - name: "PreviousPollNotCompleted", - type: "error", - }, - { - inputs: [], - name: "PubKeyAlreadyRegistered", - type: "error", - }, - { - inputs: [], - name: "SignupTemporaryBlocked", - type: "error", - }, - { - inputs: [], - name: "TooManySignups", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "_coordinatorPubKeyX", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "_coordinatorPubKeyY", - type: "uint256", - }, - { - components: [ - { - internalType: "address", - name: "poll", - type: "address", - }, - { - internalType: "address", - name: "messageProcessor", - type: "address", - }, - { - internalType: "address", - name: "tally", - type: "address", - }, - ], - indexed: false, - internalType: "struct MACI.PollContracts", - name: "pollAddr", - type: "tuple", - }, - ], - name: "DeployPoll", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "_stateIndex", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "_userPubKeyX", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "_userPubKeyY", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "_voiceCreditBalance", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "_timestamp", - type: "uint256", - }, - ], - name: "SignUp", - type: "event", - }, - { - inputs: [], - name: "MESSAGE_DATA_LENGTH", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_duration", - type: "uint256", - }, - { - components: [ - { - internalType: "uint8", - name: "intStateTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeSubDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "voteOptionTreeDepth", - type: "uint8", - }, - ], - internalType: "struct Params.TreeDepths", - name: "_treeDepths", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_coordinatorPubKey", - type: "tuple", - }, - { - internalType: "address", - name: "_verifier", - type: "address", - }, - { - internalType: "address", - name: "_vkRegistry", - type: "address", - }, - { - internalType: "bool", - name: "_isQv", - type: "bool", - }, - ], - name: "deployPoll", - outputs: [ - { - components: [ - { - internalType: "address", - name: "poll", - type: "address", - }, - { - internalType: "address", - name: "messageProcessor", - type: "address", - }, - { - internalType: "address", - name: "tally", - type: "address", - }, - ], - internalType: "struct MACI.PollContracts", - name: "pollAddr", - type: "tuple", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - ], - name: "getPoll", - outputs: [ - { - internalType: "address", - name: "poll", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_poll", - type: "address", - }, - ], - name: "getPollId", - outputs: [ - { - internalType: "uint256", - name: "pollId", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getStateAqRoot", - outputs: [ - { - internalType: "uint256", - name: "root", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[2]", - name: "array", - type: "uint256[2]", - }, - ], - name: "hash2", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[3]", - name: "array", - type: "uint256[3]", - }, - ], - name: "hash3", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[4]", - name: "array", - type: "uint256[4]", - }, - ], - name: "hash4", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[5]", - name: "array", - type: "uint256[5]", - }, - ], - name: "hash5", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "left", - type: "uint256", - }, - { - internalType: "uint256", - name: "right", - type: "uint256", - }, - ], - name: "hashLeftRight", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - internalType: "struct DomainObjs.Message", - name: "_message", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_encPubKey", - type: "tuple", - }, - ], - name: "hashMessageAndEncPubKey", - outputs: [ - { - internalType: "uint256", - name: "msgHash", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "pubKey", - type: "tuple", - }, - { - internalType: "uint256", - name: "voiceCreditBalance", - type: "uint256", - }, - { - internalType: "uint256", - name: "timestamp", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.StateLeaf", - name: "_stateLeaf", - type: "tuple", - }, - ], - name: "hashStateLeaf", - outputs: [ - { - internalType: "uint256", - name: "ciphertext", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [], - name: "initialVoiceCreditProxy", - outputs: [ - { - internalType: "contract InitialVoiceCreditProxy", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - name: "isPublicKeyRegistered", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "manager", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - ], - name: "mergeStateAq", - outputs: [ - { - internalType: "uint256", - name: "root", - type: "uint256", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_numSrQueueOps", - type: "uint256", - }, - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - ], - name: "mergeStateAqSubRoots", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "messageProcessorFactory", - outputs: [ - { - internalType: "contract IMessageProcessorFactory", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "nextPollId", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "numSignUps", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[2]", - name: "dataToPad", - type: "uint256[2]", - }, - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - ], - name: "padAndHashMessage", - outputs: [ - { - components: [ - { - internalType: "uint256", - name: "msgType", - type: "uint256", - }, - { - internalType: "uint256[10]", - name: "data", - type: "uint256[10]", - }, - ], - internalType: "struct DomainObjs.Message", - name: "message", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "padKey", - type: "tuple", - }, - { - internalType: "uint256", - name: "msgHash", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [], - name: "pollFactory", - outputs: [ - { - internalType: "contract IPollFactory", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - name: "pollIds", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - name: "polls", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[]", - name: "array", - type: "uint256[]", - }, - ], - name: "sha256Hash", - outputs: [ - { - internalType: "uint256", - name: "result", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_pubKey", - type: "tuple", - }, - { - internalType: "bytes", - name: "_signUpGatekeeperData", - type: "bytes", - }, - { - internalType: "bytes", - name: "_initialVoiceCreditProxyData", - type: "bytes", - }, - ], - name: "signUp", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "signUpGatekeeper", - outputs: [ - { - internalType: "contract SignUpGatekeeper", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "stateAq", - outputs: [ - { - internalType: "contract AccQueue", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "stateTreeDepth", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "subtreesMerged", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "tallyFactory", - outputs: [ - { - internalType: "contract ITallyFactory", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "topupCredit", - outputs: [ - { - internalType: "contract TopupCredit", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_manager", - type: "address", - }, - ], - name: "updateManager", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - getStateAqRoot: "contracts/maci-contracts/interfaces/IMACI.sol", - mergeStateAq: "contracts/maci-contracts/interfaces/IMACI.sol", - mergeStateAqSubRoots: "contracts/maci-contracts/interfaces/IMACI.sol", - numSignUps: "contracts/maci-contracts/interfaces/IMACI.sol", - stateAq: "contracts/maci-contracts/interfaces/IMACI.sol", - stateTreeDepth: "contracts/maci-contracts/interfaces/IMACI.sol", - MESSAGE_DATA_LENGTH: "contracts/maci-contracts/utilities/Utilities.sol", - hash2: "contracts/maci-contracts/utilities/Utilities.sol", - hash3: "contracts/maci-contracts/utilities/Utilities.sol", - hash4: "contracts/maci-contracts/utilities/Utilities.sol", - hash5: "contracts/maci-contracts/utilities/Utilities.sol", - hashLeftRight: "contracts/maci-contracts/utilities/Utilities.sol", - hashMessageAndEncPubKey: - "contracts/maci-contracts/utilities/Utilities.sol", - hashStateLeaf: "contracts/maci-contracts/utilities/Utilities.sol", - padAndHashMessage: "contracts/maci-contracts/utilities/Utilities.sol", - sha256Hash: "contracts/maci-contracts/utilities/Utilities.sol", - owner: "@openzeppelin/contracts/access/Ownable.sol", - renounceOwnership: "@openzeppelin/contracts/access/Ownable.sol", - transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", - }, - deploymentBlockNumber: 23, - }, - MessageProcessorFactory: { - address: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318", - abi: [ - { - inputs: [], - name: "MESSAGE_DATA_LENGTH", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_verifier", - type: "address", - }, - { - internalType: "address", - name: "_vkRegistry", - type: "address", - }, - { - internalType: "address", - name: "_poll", - type: "address", - }, - { - internalType: "address", - name: "_owner", - type: "address", - }, - { - internalType: "bool", - name: "_isQv", - type: "bool", - }, - ], - name: "deploy", - outputs: [ - { - internalType: "address", - name: "messageProcessorAddr", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - MESSAGE_DATA_LENGTH: - "contracts/maci-contracts/utilities/DomainObjs.sol", - }, - deploymentBlockNumber: 19, - }, - PollFactory: { - address: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6", - abi: [ - { - inputs: [], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [], - name: "InvalidMaxValues", - type: "error", - }, - { - inputs: [], - name: "MESSAGE_DATA_LENGTH", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_duration", - type: "uint256", - }, - { - components: [ - { - internalType: "uint256", - name: "maxMessages", - type: "uint256", - }, - { - internalType: "uint256", - name: "maxVoteOptions", - type: "uint256", - }, - ], - internalType: "struct Params.MaxValues", - name: "_maxValues", - type: "tuple", - }, - { - components: [ - { - internalType: "uint8", - name: "intStateTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeSubDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "voteOptionTreeDepth", - type: "uint8", - }, - ], - internalType: "struct Params.TreeDepths", - name: "_treeDepths", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_coordinatorPubKey", - type: "tuple", - }, - { - internalType: "address", - name: "_maci", - type: "address", - }, - { - internalType: "contract TopupCredit", - name: "_topupCredit", - type: "address", - }, - { - internalType: "address", - name: "_pollOwner", - type: "address", - }, - ], - name: "deploy", - outputs: [ - { - internalType: "address", - name: "pollAddr", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - MESSAGE_DATA_LENGTH: - "contracts/maci-contracts/utilities/DomainObjs.sol", - deploy: "contracts/maci-contracts/interfaces/IPollFactory.sol", - }, - deploymentBlockNumber: 17, - }, - PollManager: { - address: "0x0B306BF915C4d645ff596e518fAf3F9669b97016", - abi: [ - { - inputs: [ - { - internalType: "contract MACI", - name: "_maci", - type: "address", - }, - { - internalType: "bool", - name: "_isQv", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "constructor", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "uint256", - name: "pollId", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "maciPollId", - type: "uint256", - }, - { - indexed: true, - internalType: "address", - name: "creator", - type: "address", - }, - { - components: [ - { - internalType: "address", - name: "poll", - type: "address", - }, - { - internalType: "address", - name: "messageProcessor", - type: "address", - }, - { - internalType: "address", - name: "tally", - type: "address", - }, - ], - indexed: false, - internalType: "struct MACI.PollContracts", - name: "pollContracts", - type: "tuple", - }, - { - indexed: false, - internalType: "string", - name: "name", - type: "string", - }, - { - indexed: false, - internalType: "string[]", - name: "options", - type: "string[]", - }, - { - indexed: false, - internalType: "string", - name: "ipfsHash", - type: "string", - }, - { - indexed: false, - internalType: "uint256", - name: "startTime", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "endTime", - type: "uint256", - }, - ], - name: "PollCreated", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "uint256", - name: "pollId", - type: "uint256", - }, - { - indexed: true, - internalType: "uint256", - name: "maciPollId", - type: "uint256", - }, - { - indexed: false, - internalType: "string", - name: "tallyJsonCID", - type: "string", - }, - ], - name: "PollTallyCIDUpdated", - type: "event", - }, - { - inputs: [], - name: "MESSAGE_DATA_LENGTH", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "coordinatorPubKey", - outputs: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "string", - name: "_name", - type: "string", - }, - { - internalType: "string[]", - name: "_options", - type: "string[]", - }, - { - internalType: "string", - name: "_ipfsHash", - type: "string", - }, - { - internalType: "uint256", - name: "_duration", - type: "uint256", - }, - ], - name: "createPoll", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - ], - name: "fetchPoll", - outputs: [ - { - components: [ - { - internalType: "uint256", - name: "id", - type: "uint256", - }, - { - internalType: "uint256", - name: "maciPollId", - type: "uint256", - }, - { - internalType: "string", - name: "name", - type: "string", - }, - { - internalType: "bytes", - name: "encodedOptions", - type: "bytes", - }, - { - internalType: "string", - name: "ipfsHash", - type: "string", - }, - { - components: [ - { - internalType: "address", - name: "poll", - type: "address", - }, - { - internalType: "address", - name: "messageProcessor", - type: "address", - }, - { - internalType: "address", - name: "tally", - type: "address", - }, - ], - internalType: "struct MACI.PollContracts", - name: "pollContracts", - type: "tuple", - }, - { - internalType: "uint256", - name: "startTime", - type: "uint256", - }, - { - internalType: "uint256", - name: "endTime", - type: "uint256", - }, - { - internalType: "uint256", - name: "numOfOptions", - type: "uint256", - }, - { - internalType: "string[]", - name: "options", - type: "string[]", - }, - { - internalType: "string", - name: "tallyJsonCID", - type: "string", - }, - ], - internalType: "struct PollManager.PollData", - name: "poll_", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_page", - type: "uint256", - }, - { - internalType: "uint256", - name: "_perPage", - type: "uint256", - }, - { - internalType: "bool", - name: "_ascending", - type: "bool", - }, - ], - name: "fetchPolls", - outputs: [ - { - components: [ - { - internalType: "uint256", - name: "id", - type: "uint256", - }, - { - internalType: "uint256", - name: "maciPollId", - type: "uint256", - }, - { - internalType: "string", - name: "name", - type: "string", - }, - { - internalType: "bytes", - name: "encodedOptions", - type: "bytes", - }, - { - internalType: "string", - name: "ipfsHash", - type: "string", - }, - { - components: [ - { - internalType: "address", - name: "poll", - type: "address", - }, - { - internalType: "address", - name: "messageProcessor", - type: "address", - }, - { - internalType: "address", - name: "tally", - type: "address", - }, - ], - internalType: "struct MACI.PollContracts", - name: "pollContracts", - type: "tuple", - }, - { - internalType: "uint256", - name: "startTime", - type: "uint256", - }, - { - internalType: "uint256", - name: "endTime", - type: "uint256", - }, - { - internalType: "uint256", - name: "numOfOptions", - type: "uint256", - }, - { - internalType: "string[]", - name: "options", - type: "string[]", - }, - { - internalType: "string", - name: "tallyJsonCID", - type: "string", - }, - ], - internalType: "struct PollManager.PollData[]", - name: "polls_", - type: "tuple[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "isQv", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "maci", - outputs: [ - { - internalType: "contract MACI", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - name: "pollIdByAddress", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "uint8", - name: "intStateTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeSubDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "voteOptionTreeDepth", - type: "uint8", - }, - ], - internalType: "struct Params.TreeDepths", - name: "_treeDepths", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct DomainObjs.PubKey", - name: "_coordinatorPubKey", - type: "tuple", - }, - { - internalType: "address", - name: "_verifier", - type: "address", - }, - { - internalType: "address", - name: "_vkRegistry", - type: "address", - }, - { - internalType: "bool", - name: "_useSubsidy", - type: "bool", - }, - ], - name: "setConfig", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "totalPolls", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "treeDepths", - outputs: [ - { - internalType: "uint8", - name: "intStateTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeSubDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "messageTreeDepth", - type: "uint8", - }, - { - internalType: "uint8", - name: "voteOptionTreeDepth", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_pollId", - type: "uint256", - }, - { - internalType: "string", - name: "_tallyJsonCID", - type: "string", - }, - ], - name: "updatePollTallyCID", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "useSubsidy", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "verifier", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "vkRegistry", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - ], - inheritedFunctions: { - MESSAGE_DATA_LENGTH: - "contracts/maci-contracts/utilities/DomainObjs.sol", - }, - deploymentBlockNumber: 29, - }, - PoseidonT3: { - address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", - abi: [ - { - inputs: [ - { - internalType: "uint256[2]", - name: "input", - type: "uint256[2]", - }, - ], - name: "poseidon", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - ], - inheritedFunctions: {}, - deploymentBlockNumber: 9, - }, - PoseidonT4: { - address: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", - abi: [ - { - inputs: [ - { - internalType: "uint256[3]", - name: "input", - type: "uint256[3]", - }, - ], - name: "poseidon", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - ], - inheritedFunctions: {}, - deploymentBlockNumber: 11, - }, - PoseidonT5: { - address: "0x0165878A594ca255338adfa4d48449f69242Eb8F", - abi: [ - { - inputs: [ - { - internalType: "uint256[4]", - name: "input", - type: "uint256[4]", - }, - ], - name: "poseidon", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - ], - inheritedFunctions: {}, - deploymentBlockNumber: 13, - }, - PoseidonT6: { - address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", - abi: [ - { - inputs: [ - { - internalType: "uint256[5]", - name: "input", - type: "uint256[5]", - }, - ], - name: "poseidon", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - ], - inheritedFunctions: {}, - deploymentBlockNumber: 15, - }, - TallyFactory: { - address: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788", - abi: [ - { - inputs: [ - { - internalType: "address", - name: "_verifier", - type: "address", - }, - { - internalType: "address", - name: "_vkRegistry", - type: "address", - }, - { - internalType: "address", - name: "_poll", - type: "address", - }, - { - internalType: "address", - name: "_messageProcessor", - type: "address", - }, - { - internalType: "address", - name: "_owner", - type: "address", - }, - { - internalType: "bool", - name: "_isQv", - type: "bool", - }, - ], - name: "deploy", - outputs: [ - { - internalType: "address", - name: "tallyAddr", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - deploy: "contracts/maci-contracts/interfaces/ITallyFactory.sol", - }, - deploymentBlockNumber: 21, - }, - TopupCredit: { - address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", - abi: [ - { - inputs: [], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [], - name: "ExceedLimit", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "owner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "spender", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "Approval", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "from", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "to", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "value", - type: "uint256", - }, - ], - name: "Transfer", - type: "event", - }, - { - inputs: [], - name: "DECIMALS", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "MAXIMUM_AIRDROP_AMOUNT", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "airdrop", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "account", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "airdropTo", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "owner", - type: "address", - }, - { - internalType: "address", - name: "spender", - type: "address", - }, - ], - name: "allowance", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "spender", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "approve", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "account", - type: "address", - }, - ], - name: "balanceOf", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "decimals", - outputs: [ - { - internalType: "uint8", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "spender", - type: "address", - }, - { - internalType: "uint256", - name: "subtractedValue", - type: "uint256", - }, - ], - name: "decreaseAllowance", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "spender", - type: "address", - }, - { - internalType: "uint256", - name: "addedValue", - type: "uint256", - }, - ], - name: "increaseAllowance", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "name", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "symbol", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "totalSupply", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "to", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "transfer", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "from", - type: "address", - }, - { - internalType: "address", - name: "to", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "transferFrom", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - allowance: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - approve: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - balanceOf: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - decimals: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - decreaseAllowance: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - increaseAllowance: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - name: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - symbol: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - totalSupply: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - transfer: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - transferFrom: "@openzeppelin/contracts/token/ERC20/ERC20.sol", - owner: "@openzeppelin/contracts/access/Ownable.sol", - renounceOwnership: "@openzeppelin/contracts/access/Ownable.sol", - transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", - }, - deploymentBlockNumber: 7, - }, - Verifier: { - address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", - abi: [ - { - inputs: [], - name: "InvalidInputVal", - type: "error", - }, - { - inputs: [], - name: "InvalidProofQ", - type: "error", - }, - { - inputs: [], - name: "PairingAddFailed", - type: "error", - }, - { - inputs: [], - name: "PairingMulFailed", - type: "error", - }, - { - inputs: [], - name: "PairingOpcodeFailed", - type: "error", - }, - { - inputs: [], - name: "PRIME_Q", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256[8]", - name: "_proof", - type: "uint256[8]", - }, - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "vk", - type: "tuple", - }, - { - internalType: "uint256", - name: "input", - type: "uint256", - }, - ], - name: "verify", - outputs: [ - { - internalType: "bool", - name: "isValid", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - ], - inheritedFunctions: { - verify: "contracts/maci-contracts/interfaces/IVerifier.sol", - }, - deploymentBlockNumber: 5, - }, - VkRegistry: { - address: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82", - abi: [ - { - inputs: [], - stateMutability: "payable", - type: "constructor", - }, - { - inputs: [], - name: "ProcessVkAlreadySet", - type: "error", - }, - { - inputs: [], - name: "ProcessVkNotSet", - type: "error", - }, - { - inputs: [], - name: "SubsidyVkNotSet", - type: "error", - }, - { - inputs: [], - name: "TallyVkAlreadySet", - type: "error", - }, - { - inputs: [], - name: "TallyVkNotSet", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, - { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "OwnershipTransferred", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "_sig", - type: "uint256", - }, - { - indexed: false, - internalType: "enum IVkRegistry.Mode", - name: "mode", - type: "uint8", - }, - ], - name: "ProcessVkSet", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "_sig", - type: "uint256", - }, - { - indexed: false, - internalType: "enum IVkRegistry.Mode", - name: "mode", - type: "uint8", - }, - ], - name: "TallyVkSet", - type: "event", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageBatchSize", - type: "uint256", - }, - ], - name: "genProcessVkSig", - outputs: [ - { - internalType: "uint256", - name: "sig", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_intStateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - ], - name: "genTallyVkSig", - outputs: [ - { - internalType: "uint256", - name: "sig", - type: "uint256", - }, - ], - stateMutability: "pure", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageBatchSize", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "getProcessVk", - outputs: [ - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "vk", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_sig", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "getProcessVkBySig", - outputs: [ - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "vk", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_intStateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "getTallyVk", - outputs: [ - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "vk", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_sig", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "getTallyVkBySig", - outputs: [ - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "vk", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageBatchSize", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "hasProcessVk", - outputs: [ - { - internalType: "bool", - name: "isSet", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_intStateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "hasTallyVk", - outputs: [ - { - internalType: "bool", - name: "isSet", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_sig", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "isProcessVkSet", - outputs: [ - { - internalType: "bool", - name: "isSet", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_sig", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - ], - name: "isTallyVkSet", - outputs: [ - { - internalType: "bool", - name: "isSet", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "owner", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_stateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_intStateTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_voteOptionTreeDepth", - type: "uint256", - }, - { - internalType: "uint256", - name: "_messageBatchSize", - type: "uint256", - }, - { - internalType: "enum IVkRegistry.Mode", - name: "_mode", - type: "uint8", - }, - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "_processVk", - type: "tuple", - }, - { - components: [ - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point", - name: "alpha1", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "beta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "gamma2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256[2]", - name: "x", - type: "uint256[2]", - }, - { - internalType: "uint256[2]", - name: "y", - type: "uint256[2]", - }, - ], - internalType: "struct Pairing.G2Point", - name: "delta2", - type: "tuple", - }, - { - components: [ - { - internalType: "uint256", - name: "x", - type: "uint256", - }, - { - internalType: "uint256", - name: "y", - type: "uint256", - }, - ], - internalType: "struct Pairing.G1Point[]", - name: "ic", - type: "tuple[]", - }, - ], - internalType: "struct SnarkCommon.VerifyingKey", - name: "_tallyVk", - type: "tuple", - }, - ], - name: "setVerifyingKeys", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "newOwner", - type: "address", - }, - ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - ], - inheritedFunctions: { - owner: "@openzeppelin/contracts/access/Ownable.sol", - renounceOwnership: "@openzeppelin/contracts/access/Ownable.sol", - transferOwnership: "@openzeppelin/contracts/access/Ownable.sol", - getProcessVk: "contracts/maci-contracts/interfaces/IVkRegistry.sol", - getTallyVk: "contracts/maci-contracts/interfaces/IVkRegistry.sol", - }, - deploymentBlockNumber: 26, - }, - }, -}; - -export default deployedContracts; diff --git a/packages/prover/src/index.ts b/packages/prover/src/index.ts deleted file mode 100644 index 6dffe9a..0000000 --- a/packages/prover/src/index.ts +++ /dev/null @@ -1,368 +0,0 @@ -import express from "express"; -import { - PORT, - blocksPerBatch, - configure, - coordinatorKeypair, - deploymentBlockNumber, - maciContract, - maciContractDetails, - pollManagerContract, - processVk, - processWasmPath, - processZkeyPath, - provider, - tallyVk, - tallyWasmPath, - tallyZkeyPath, - useQuadraticVoting, -} from "./config"; -import cors from "cors"; -import { getAccQueueContract, getPollContract } from "./utils"; -import { CircuitInputs, MaciState } from "@se-2/hardhat/maci-ts/core"; -import fs from "fs"; -import { groth16 } from "snarkjs"; -// import { Proof } from "@se-2/hardhat/maci-ts/domainobjs"; -import { - genTreeCommitment, - hash3, - hashLeftRight, -} from "@se-2/hardhat/maci-ts/crypto"; -import { BigNumberish } from "@se-2/hardhat/maci-ts/domainobjs/types"; -import { verifyProof } from "@se-2/hardhat/maci-ts/circuits"; -import { genMaciStateFromContract } from "./contract"; - -const app = express(); - -app.use(express.json()); -app.use(cors()); - -export const asHex = (val: BigNumberish): string => - `0x${BigInt(val).toString(16)}`; - -export const genProof = async ({ inputs, zkeyPath, wasmPath }: any) => { - // if we want to use a wasm witness we use snarkjs - if (!wasmPath) { - throw new Error("wasmPath must be specified"); - } - - if (!fs.existsSync(wasmPath)) { - throw new Error(`wasmPath ${wasmPath} does not exist`); - } - - const { proof, publicSignals } = await groth16.fullProve( - inputs, - wasmPath, - zkeyPath - ); - return { proof, publicSignals }; -}; - -app.post("/generate-proof", async (req, res) => { - const { pollContractAddress } = req.body; - const pollContract = getPollContract(pollContractAddress); - - const pollId = await maciContract.getPollId(pollContractAddress); - - const extContracts = await pollContract.extContracts(); - const messageAqContractAddr = extContracts.messageAq; - const messageAqContract = getAccQueueContract(messageAqContractAddr); - - // Check that the state and message trees have been merged for at least the first poll - if (!(await pollContract.stateAqMerged()) && pollId.toString() === "0") { - res.status(400).json({ - error: - "The state tree has not been merged yet. Please use the mergeSignups subcommmand to do so.", - }); - return; - } - - const messageTreeDepth = Number( - (await pollContract.treeDepths()).messageTreeDepth - ); - - // check that the main root is set - const mainRoot = ( - await messageAqContract.getMainRoot(messageTreeDepth.toString()) - ).toString(); - if (mainRoot === "0") { - res.status(400).json({ - error: - "The message tree has not been merged yet. Please use the mergeMessages subcommmand to do so.", - }); - return; - } - - let maciState: MaciState | undefined; - - // build an off-chain representation of the MACI contract using data in the contract storage - const [stateRoot, numSignups, messageRoot] = await Promise.all([ - maciContract.getStateAqRoot(), - maciContract.numSignUps(), - messageAqContract.getMainRoot(messageTreeDepth), - ]); - let fromBlock = deploymentBlockNumber; - console.log("Here"); - - const defaultEndBlock = await Promise.all([ - pollContract - .queryFilter(pollContract.filters.MergeMessageAq(messageRoot), fromBlock) - .then((events) => events[events.length - 1]?.blockNumber), - pollContract - .queryFilter( - pollContract.filters.MergeMaciStateAq(stateRoot, numSignups), - fromBlock - ) - .then((events) => events[events.length - 1]?.blockNumber), - ]).then((blocks) => Math.max(...blocks)); - - console.log(`starting to fetch logs from block ${fromBlock}`); - maciState = await genMaciStateFromContract( - provider as any, - coordinatorKeypair, - pollId, - fromBlock, - blocksPerBatch, - defaultEndBlock - ); - - const poll = maciState!.polls.get(pollId)!; - - const processProofs: any[] = []; - const tallyProofs: any[] = []; - - // time how long it takes - const startTime = Date.now(); - - console.log(`Generating proofs of message processing...`); - const { messageBatchSize } = poll.batchSizes; - const numMessages = poll.messages.length; - let totalMessageBatches = - numMessages <= messageBatchSize - ? 1 - : Math.floor(numMessages / messageBatchSize); - if (numMessages > messageBatchSize && numMessages % messageBatchSize > 0) { - totalMessageBatches += 1; - } - - // while we have unprocessed messages, process them - while (poll.hasUnprocessedMessages()) { - // process messages in batches - const circuitInputs = poll.processMessages( - pollId, - useQuadraticVoting, - true - ) as unknown as CircuitInputs; - - try { - // generate the proof for this batch - // eslint-disable-next-line no-await-in-loop - const r = await genProof({ - inputs: circuitInputs, - zkeyPath: processZkeyPath, - wasmPath: processWasmPath, - }); - - // verify it - // eslint-disable-next-line no-await-in-loop - const isValid = await verifyProof(r.publicSignals, r.proof, processVk); - if (!isValid) { - throw new Error("Generated an invalid proof"); - } - - const thisProof = { - circuitInputs, - proof: r.proof, - publicInputs: r.publicSignals, - }; - // save the proof - processProofs.push(thisProof); - - console.log( - `Progress: ${poll.numBatchesProcessed} / ${totalMessageBatches}` - ); - } catch (error) { - res.status(400).json({ error: (error as Error).message }); - return; - } - } - - const endTime = Date.now(); - - console.log( - `gen processMessage proof took ${(endTime - startTime) / 1000} seconds\n` - ); - - // tallying proofs - console.log(`Generating proofs of vote tallying...`); - const tallyStartTime = Date.now(); - - const { tallyBatchSize } = poll.batchSizes; - const numStateLeaves = poll.stateLeaves.length; - let totalTallyBatches = - numStateLeaves <= tallyBatchSize - ? 1 - : Math.floor(numStateLeaves / tallyBatchSize); - if (numStateLeaves > tallyBatchSize && numStateLeaves % tallyBatchSize > 0) { - totalTallyBatches += 1; - } - - let tallyCircuitInputs: CircuitInputs; - // tally all ballots for this poll - while (poll.hasUntalliedBallots()) { - // tally votes in batches - tallyCircuitInputs = useQuadraticVoting - ? (poll.tallyVotes() as unknown as CircuitInputs) - : (poll.tallyVotesNonQv() as unknown as CircuitInputs); - - try { - // generate the proof - // eslint-disable-next-line no-await-in-loop - const r = await genProof({ - inputs: tallyCircuitInputs, - zkeyPath: tallyZkeyPath, - wasmPath: tallyWasmPath, - }); - - // verify it - // eslint-disable-next-line no-await-in-loop - const isValid = await verifyProof(r.publicSignals, r.proof, tallyVk); - - if (!isValid) { - res.status(400).json({ error: "Generated an invalid tally proof" }); - return; - } - - const thisProof = { - circuitInputs: tallyCircuitInputs, - proof: r.proof, - publicInputs: r.publicSignals, - }; - - // save it - tallyProofs.push(thisProof); - - console.log(`Progress: ${poll.numBatchesTallied} / ${totalTallyBatches}`); - } catch (error) { - res.status(400).json({ error: (error as Error).message }); - return; - } - } - - // verify the results - // Compute newResultsCommitment - const newResultsCommitment = genTreeCommitment( - poll.tallyResult, - BigInt(asHex(tallyCircuitInputs!.newResultsRootSalt as BigNumberish)), - poll.treeDepths.voteOptionTreeDepth - ); - - // compute newSpentVoiceCreditsCommitment - const newSpentVoiceCreditsCommitment = hashLeftRight( - poll.totalSpentVoiceCredits, - BigInt( - asHex(tallyCircuitInputs!.newSpentVoiceCreditSubtotalSalt as BigNumberish) - ) - ); - - const pollIdInManager = await pollManagerContract.pollIdByAddress( - pollContractAddress - ); - // get the tally contract address - const { - pollContracts: { - tally: tallyContractAddress, - messageProcessor: messageProcessorAddress, - }, - } = await pollManagerContract.fetchPoll(pollIdInManager); - - let newPerVOSpentVoiceCreditsCommitment: bigint | undefined; - let newTallyCommitment: bigint; - - const network = await provider.getNetwork(); - - // create the tally file data to store for verification later - const tallyFileData: any = { - maci: maciContractDetails.address, - pollId: pollId.toString(), - network: network?.name, - chainId: network?.chainId.toString(), - isQuadratic: useQuadraticVoting, - tallyAddress: tallyContractAddress, - newTallyCommitment: asHex( - tallyCircuitInputs!.newTallyCommitment as BigNumberish - ), - results: { - tally: poll.tallyResult.map((x) => x.toString()), - salt: asHex(tallyCircuitInputs!.newResultsRootSalt as BigNumberish), - commitment: asHex(newResultsCommitment), - }, - totalSpentVoiceCredits: { - spent: poll.totalSpentVoiceCredits.toString(), - salt: asHex( - tallyCircuitInputs!.newSpentVoiceCreditSubtotalSalt as BigNumberish - ), - commitment: asHex(newSpentVoiceCreditsCommitment), - }, - }; - - if (useQuadraticVoting) { - // Compute newPerVOSpentVoiceCreditsCommitment - newPerVOSpentVoiceCreditsCommitment = genTreeCommitment( - poll.perVOSpentVoiceCredits, - BigInt( - asHex( - tallyCircuitInputs!.newPerVOSpentVoiceCreditsRootSalt as BigNumberish - ) - ), - poll.treeDepths.voteOptionTreeDepth - ); - - // Compute newTallyCommitment - newTallyCommitment = hash3([ - newResultsCommitment, - newSpentVoiceCreditsCommitment, - newPerVOSpentVoiceCreditsCommitment, - ]); - - // update perVOSpentVoiceCredits in the tally file data - tallyFileData.perVOSpentVoiceCredits = { - tally: poll.perVOSpentVoiceCredits.map((x) => x.toString()), - salt: asHex( - tallyCircuitInputs!.newPerVOSpentVoiceCreditsRootSalt as BigNumberish - ), - commitment: asHex(newPerVOSpentVoiceCreditsCommitment), - }; - } else { - newTallyCommitment = hashLeftRight( - newResultsCommitment, - newSpentVoiceCreditsCommitment - ); - } - - // compare the commitments - if (asHex(newTallyCommitment) === tallyFileData.newTallyCommitment) { - console.log("The tally commitment is correct"); - } else { - res - .status(400) - .json({ error: "Error: the newTallyCommitment is invalid." }); - return; - } - - const tallyEndTime = Date.now(); - - console.log( - `gen tally proof took ${(tallyEndTime - tallyStartTime) / 1000} seconds\n` - ); - - console.log(tallyFileData); - - res.json(tallyFileData); -}); - -configure().then(() => { - app.listen(PORT, () => - console.log(`The server is listening on port ${PORT}`) - ); -}); diff --git a/packages/prover/src/types/hardhat.d.ts b/packages/prover/src/types/hardhat.d.ts deleted file mode 100644 index fea72c2..0000000 --- a/packages/prover/src/types/hardhat.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module "hardhat" { - export const ethers; -} diff --git a/packages/prover/src/types/snarkjs.d.ts b/packages/prover/src/types/snarkjs.d.ts deleted file mode 100644 index 19cb66a..0000000 --- a/packages/prover/src/types/snarkjs.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -declare module "snarkjs" { - export type NumericString = string; - export type PublicSignals = Record; - export type BigNumberish = number | string | bigint; - - export interface ISnarkJSVerificationKey { - protocol: BigNumberish; - curve: BigNumberish; - nPublic: BigNumberish; - vk_alpha_1: BigNumberish[]; - vk_beta_2: BigNumberish[][]; - vk_gamma_2: BigNumberish[][]; - vk_delta_2: BigNumberish[][]; - vk_alphabeta_12: BigNumberish[][][]; - IC: BigNumberish[][]; - } - - export interface FullProveResult { - proof: Groth16Proof; - publicSignals: PublicSignals; - } - - export interface Groth16Proof { - pi_a: NumericString[]; - pi_b: NumericString[][]; - pi_c: NumericString[]; - protocol: string; - curve: string; - } - - export namespace zKey { - function exportVerificationKey(zkeyName: string, logger?: unknown): Promise; - } - - export namespace groth16 { - function verify( - vk_verifier: ISnarkJSVerificationKey, - publicSignals: PublicSignals, - proof: Groth16Proof, - logger?: unknown, - ): Promise; - - function fullProve( - input: PublicSignals, - wasmFile: string, - zkeyFileName: string, - logger?: unknown, - ): Promise; - } -} diff --git a/packages/prover/src/utils.ts b/packages/prover/src/utils.ts deleted file mode 100644 index 0b3fe10..0000000 --- a/packages/prover/src/utils.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { zKey } from "snarkjs"; -import PollAbi from "./abi/Poll"; -import AccQueueAbi from "./abi/AccQueue"; -import { ethers } from "ethers"; -import { signer } from "./config"; - -export const cleanThreads = async (): Promise => { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (!globalThis) { - return; - } - - const curves = ["curve_bn128", "curve_bls12381"]; - await Promise.all( - curves - .map((curve) => - globalThis[curve as "curve_bn128" | "curve_bls12381"]?.terminate() - ) - .filter(Boolean) - ); -}; - -export const extractVk = async (zkeyPath: string): Promise => { - const vk = await zKey.exportVerificationKey(zkeyPath); - await cleanThreads(); - return vk; -}; - -export function getPollContract(pollContractAddress: string) { - const pollContract = new ethers.Contract( - pollContractAddress, - PollAbi, - signer - ); - return pollContract; -} - -export function getAccQueueContract(accQueueContractAddress: string) { - const accQueueContract = new ethers.Contract( - accQueueContractAddress, - AccQueueAbi, - signer - ); - return accQueueContract; -} diff --git a/packages/prover/tsconfig.json b/packages/prover/tsconfig.json deleted file mode 100644 index 0519213..0000000 --- a/packages/prover/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "ts-node": { - "files": true - }, - "files": ["src/index.ts", "src/types/hardhat.d.ts", "src/types/snarkjs.d.ts"], - "compilerOptions": { - "target": "esnext", - "module": "commonjs", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "outDir": "./dist" - } -}