Skip to content

Commit

Permalink
refactor(cli): move proof generation and poll deploy to sdk
Browse files Browse the repository at this point in the history
- [x] Update params for proof generation
- [x] Move param validation to sdk for proof generation executables
- [x] Move param validation to sdk for poll deployment
- [x] Update params for poll deployment
  • Loading branch information
0xmad committed Feb 28, 2025
1 parent dfbc410 commit 31922b2
Show file tree
Hide file tree
Showing 29 changed files with 469 additions and 648 deletions.
4 changes: 3 additions & 1 deletion apps/relayer/tests/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
pollWitgen,
rapidsnark,
DEFAULT_VOTE_OPTIONS,
DEFAULT_INITIAL_VOICE_CREDITS,
} from "./constants.js";

interface IContractsData {
Expand Down Expand Up @@ -107,11 +108,12 @@ export class TestDeploy {
relayers: [await signer.getAddress()],
signer,
verifierContractAddress: maciAddresses.verifierAddress,
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
initialVoiceCreditProxyContractAddress: maciAddresses.initialVoiceCreditProxyAddress,
voteOptions: DEFAULT_VOTE_OPTIONS,
vkRegistryContractAddress: vkRegistry,
initialVoiceCredits: DEFAULT_INITIAL_VOICE_CREDITS,
});

await signup({
Expand Down
46 changes: 30 additions & 16 deletions packages/cli/tests/ceremony-params/ceremonyParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import {
proveOnChain,
publish,
deployPoll,
generateProofs,
type IGenerateProofsArgs,
} from "maci-sdk";

import type { Signer } from "ethers";

import { deploy, deployVkRegistryContract, genProofsCommand, timeTravel } from "../../ts/commands";
import { DEFAULT_SG_DATA, DeployArgs, DeployedContracts, GenProofsArgs } from "../../ts/utils";
import { deploy, deployVkRegistryContract, timeTravel } from "../../ts/commands";
import { DEFAULT_SG_DATA, DeployArgs, DeployedContracts } from "../../ts/utils";
import {
coordinatorPrivKey,
ceremonyProcessMessagesZkeyPath,
Expand Down Expand Up @@ -70,14 +72,14 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
stateTreeDepth,
};

const genProofsCommandCeremonyArgs: Omit<GenProofsArgs, "signer"> = {
const generateProofsCeremonyArgs: Omit<IGenerateProofsArgs, "maciAddress" | "signer"> = {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: ceremonyTallyVotesZkeyPath,
processZkey: ceremonyProcessMessagesZkeyPath,
pollId: 0n,
useWasm,
coordinatorPrivKey,
coordinatorPrivateKey: coordinatorPrivKey,
rapidsnark: testRapidsnarkPath,
processWitgen: ceremonyProcessMessagesWitnessPath,
tallyWitgen: ceremonyTallyVotesWitnessPath,
Expand Down Expand Up @@ -122,7 +124,7 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
intStateTreeDepth,
messageBatchSize,
voteOptionTreeDepth,
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
verifierContractAddress: maciAddresses.verifierAddress,
vkRegistryContractAddress: vkRegistryAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
Expand Down Expand Up @@ -205,7 +207,12 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
const ipfsMessageBackupFiles = await getBackupFilenames();
await timeTravel({ seconds: pollDuration, signer });
await mergeSignups({ ...mergeSignupsArgs, maciAddress: maciAddresses.maciAddress, signer });
await genProofsCommand({ ...genProofsCommandCeremonyArgs, signer, ipfsMessageBackupFiles });
await generateProofs({
...generateProofsCeremonyArgs,
maciAddress: maciAddresses.maciAddress,
signer,
ipfsMessageBackupFiles,
});
await proveOnChain({ ...proveOnChainArgs, maciAddress: maciAddresses.maciAddress, signer });
await verify({ ...(await verifyArgs(signer)) });
});
Expand All @@ -232,7 +239,7 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
intStateTreeDepth,
messageBatchSize,
voteOptionTreeDepth,
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
verifierContractAddress: maciAddresses.verifierAddress,
vkRegistryContractAddress: vkRegistryAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
Expand Down Expand Up @@ -306,15 +313,20 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
const ipfsMessageBackupFiles = await getBackupFilenames();
await timeTravel({ seconds: pollDuration, signer });
await mergeSignups({ ...mergeSignupsArgs, maciAddress: maciAddresses.maciAddress, signer });
await genProofsCommand({ ...genProofsCommandCeremonyArgs, signer, ipfsMessageBackupFiles });
await generateProofs({
...generateProofsCeremonyArgs,
maciAddress: maciAddresses.maciAddress,
signer,
ipfsMessageBackupFiles,
});
await proveOnChain({ ...proveOnChainArgs, maciAddress: maciAddresses.maciAddress, signer });
await verify({ ...(await verifyArgs(signer)) });
});
});
});

describe("non quadratic voting", () => {
const genProofsCommandArgs: Omit<GenProofsArgs, "signer"> = {
const generateProofsArgs: Omit<IGenerateProofsArgs, "maciAddress" | "signer"> = {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: ceremonyTallyVotesNonQvZkeyPath,
Expand All @@ -325,7 +337,7 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
processDatFile: ceremonyProcessMessagesNonQvDatPath,
tallyWitgen: ceremonyTallyVotesNonQvWitnessPath,
tallyDatFile: ceremonyTallyVotesNonQvDatPath,
coordinatorPrivKey,
coordinatorPrivateKey: coordinatorPrivKey,
processWasm: ceremonyProcessMessagesNonQvWasmPath,
tallyWasm: ceremonyTallyVotesNonQvWasmPath,
useWasm,
Expand Down Expand Up @@ -382,7 +394,7 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
intStateTreeDepth,
messageBatchSize,
voteOptionTreeDepth,
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
verifierContractAddress: maciAddresses.verifierAddress,
vkRegistryContractAddress: vkRegistryAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
Expand Down Expand Up @@ -448,10 +460,11 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
const ipfsMessageBackupFiles = await getBackupFilenames();
await timeTravel({ seconds: pollDuration, signer });
await mergeSignups({ ...mergeSignupsArgs, maciAddress: maciAddresses.maciAddress, signer });
const tallyFileData = await genProofsCommand({
...genProofsCommandArgs,
const { tallyData: tallyFileData } = await generateProofs({
...generateProofsArgs,
signer,
ipfsMessageBackupFiles,
maciAddress: maciAddresses.maciAddress,
useQuadraticVoting: false,
});
await proveOnChain({ ...proveOnChainArgs, maciAddress: maciAddresses.maciAddress, signer });
Expand Down Expand Up @@ -484,7 +497,7 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
intStateTreeDepth,
messageBatchSize,
voteOptionTreeDepth,
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
verifierContractAddress: maciAddresses.verifierAddress,
vkRegistryContractAddress: vkRegistryAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
Expand Down Expand Up @@ -559,9 +572,10 @@ describe("Stress tests with ceremony params (6,3,2,20)", function test() {
const ipfsMessageBackupFiles = await getBackupFilenames();
await timeTravel({ seconds: pollDuration, signer });
await mergeSignups({ ...mergeSignupsArgs, maciAddress: maciAddresses.maciAddress, signer });
const tallyFileData = await genProofsCommand({
...genProofsCommandArgs,
const { tallyData: tallyFileData } = await generateProofs({
...generateProofsArgs,
signer,
maciAddress: maciAddresses.maciAddress,
ipfsMessageBackupFiles,
useQuadraticVoting: false,
});
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { homedir } from "os";
import type { Signer } from "ethers";

import { DeployArgs, TimeTravelArgs, readJSONFile } from "../ts/utils";
import { DEFAULT_VOTE_OPTIONS } from "../ts/utils/defaults";
import { DEFAULT_INITIAL_VOICE_CREDITS, DEFAULT_VOTE_OPTIONS } from "../ts/utils/defaults";

export const STATE_TREE_DEPTH = 10;
export const INT_STATE_TREE_DEPTH = 1;
Expand Down Expand Up @@ -178,7 +178,7 @@ export const deployPollArgs: Omit<
| "signer"
| "pollStartTimestamp"
| "pollEndTimestamp"
| "maciContractAddress"
| "maciAddress"
| "verifierContractAddress"
| "vkRegistryContractAddress"
| "gatekeeperContractAddress"
Expand All @@ -188,6 +188,7 @@ export const deployPollArgs: Omit<
messageBatchSize: MESSAGE_BATCH_SIZE,
voteOptionTreeDepth: VOTE_OPTION_TREE_DEPTH,
coordinatorPubKey: coordinatorKeypair.pubKey,
initialVoiceCredits: DEFAULT_INITIAL_VOICE_CREDITS,
mode: EMode.QV,
voteOptions: DEFAULT_VOTE_OPTIONS,
};
26 changes: 17 additions & 9 deletions packages/cli/tests/e2e/e2e.nonQv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {
proveOnChain,
publish,
deployPoll,
generateProofs,
type IGenerateProofsArgs,
} from "maci-sdk";

import type { Signer } from "ethers";

import { deploy, deployVkRegistryContract, genProofsCommand, timeTravel } from "../../ts/commands";
import { DEFAULT_SG_DATA, DeployedContracts, GenProofsArgs } from "../../ts/utils";
import { deploy, deployVkRegistryContract, timeTravel } from "../../ts/commands";
import { DEFAULT_SG_DATA, DeployedContracts } from "../../ts/utils";
import {
deployPollArgs,
coordinatorPrivKey,
Expand Down Expand Up @@ -56,7 +58,7 @@ describe("e2e tests with non quadratic voting", function test() {
let signer: Signer;
let vkRegistryAddress: string;

const genProofsCommandArgs: Omit<GenProofsArgs, "signer"> = {
const generateProofsArgs: Omit<IGenerateProofsArgs, "maciAddress" | "signer"> = {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: tallyVotesTestNonQvZkeyPath,
Expand All @@ -67,7 +69,7 @@ describe("e2e tests with non quadratic voting", function test() {
processDatFile: testProcessMessagesNonQvWitnessDatPath,
tallyWitgen: testTallyVotesNonQvWitnessPath,
tallyDatFile: testTallyVotesNonQvWitnessDatPath,
coordinatorPrivKey,
coordinatorPrivateKey: coordinatorPrivKey,
processWasm: testProcessMessagesNonQvWasmPath,
tallyWasm: testTallyVotesNonQvWasmPath,
useWasm,
Expand Down Expand Up @@ -105,7 +107,7 @@ describe("e2e tests with non quadratic voting", function test() {
pollStartTimestamp: startDate,
pollEndTimestamp: startDate + pollDuration,
relayers: [await signer.getAddress()],
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
verifierContractAddress: maciAddresses.verifierAddress,
vkRegistryContractAddress: vkRegistryAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
Expand Down Expand Up @@ -141,7 +143,12 @@ describe("e2e tests with non quadratic voting", function test() {
it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration, signer });
await mergeSignups({ ...mergeSignupsArgs, maciAddress: maciAddresses.maciAddress, signer });
const tallyFileData = await genProofsCommand({ ...genProofsCommandArgs, signer, useQuadraticVoting: false });
const { tallyData: tallyFileData } = await generateProofs({
...generateProofsArgs,
signer,
maciAddress: maciAddresses.maciAddress,
useQuadraticVoting: false,
});
await proveOnChain({ ...proveOnChainArgs, maciAddress: maciAddresses.maciAddress, signer });
await verify({
...(await verifyArgs(signer)),
Expand Down Expand Up @@ -172,7 +179,7 @@ describe("e2e tests with non quadratic voting", function test() {
pollStartTimestamp: startDate,
pollEndTimestamp: startDate + pollDuration,
relayers: [await signer.getAddress()],
maciContractAddress: maciAddresses.maciAddress,
maciAddress: maciAddresses.maciAddress,
verifierContractAddress: maciAddresses.verifierAddress,
vkRegistryContractAddress: vkRegistryAddress,
gatekeeperContractAddress: maciAddresses.signUpGatekeeperAddress,
Expand Down Expand Up @@ -221,9 +228,10 @@ describe("e2e tests with non quadratic voting", function test() {
const ipfsMessageBackupFiles = await getBackupFilenames();
await timeTravel({ seconds: pollDuration, signer });
await mergeSignups({ ...mergeSignupsArgs, maciAddress: maciAddresses.maciAddress, signer });
const tallyFileData = await genProofsCommand({
...genProofsCommandArgs,
const { tallyData: tallyFileData } = await generateProofs({
...generateProofsArgs,
signer,
maciAddress: maciAddresses.maciAddress,
ipfsMessageBackupFiles,
useQuadraticVoting: false,
});
Expand Down
Loading

0 comments on commit 31922b2

Please sign in to comment.