Skip to content

Commit

Permalink
feat: add extractVkToFile function to cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest authored and 0xmad committed May 16, 2024
1 parent 8fa452b commit 346ebee
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cli/ts/commands/extractVkToFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { extractVk } from "maci-circuits";

import fs from "fs";

import { ExtractVkToFileArgs } from "../utils";

/**
* Command to confirm that the verifying keys in the contract match the
* local ones
* @note see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing
* @param CheckVerifyingKeysArgs - The arguments for the checkVerifyingKeys command
* @returns Whether the verifying keys match or not
*/
export const extractVkToFile = async ({
processMessagesZkeyPathQv,
tallyVotesZkeyPathQv,
processMessagesZkeyPathNonQv,
tallyVotesZkeyPathNonQv,
outputFilePath,
}: ExtractVkToFileArgs): Promise<void> => {
const [processVkQv, tallyVkQv, processVkNonQv, tallyVkNonQv] = await Promise.all([
extractVk(processMessagesZkeyPathQv),
extractVk(tallyVotesZkeyPathQv),
extractVk(processMessagesZkeyPathNonQv),
extractVk(tallyVotesZkeyPathNonQv),
]);

await fs.promises.writeFile(outputFilePath, JSON.stringify({ processVkQv, tallyVkQv, processVkNonQv, tallyVkNonQv }));
};
1 change: 1 addition & 0 deletions cli/ts/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { fundWallet } from "./fundWallet";
export { proveOnChain } from "./proveOnChain";
export { checkVerifyingKeys } from "./checkVerifyingKeys";
export { genLocalState } from "./genLocalState";
export { extractVkToFile } from "./extractVkToFile";
34 changes: 34 additions & 0 deletions cli/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
proveOnChain,
checkVerifyingKeys,
genLocalState,
extractVkToFile,
} from "./commands";
import { TallyData, logError, promptSensitiveValue, readContractAddress } from "./utils";

Expand Down Expand Up @@ -357,6 +358,39 @@ program
program.error((error as Error).message, { exitCode: 1 });
}
});
program
.command("extractVkToFile")
.description("extract vkey to json file")
.requiredOption(
"-pqv, --process-messages-zkey-qv <processMessagesZkeyPathQv>",
"the process messages qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)",
)
.requiredOption(
"-tqv, --tally-votes-zkey-qv <tallyVotesZkeyPathQv>",
"the tally votes qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)",
)
.requiredOption(
"-pnqv, --process-messages-zkey-non-qv <processMessagesZkeyPathNonQv>",
"the process messages non-qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)",
)
.requiredOption(
"-tnqv, --tally-votes-zkey-non-qv <tallyVotesZkeyPathNonQv>",
"the tally votes non-qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)",
)
.requiredOption("-o, --output-file <outputFile>", "the output file path of extracted vkeys")
.action(async (cmdObj) => {
try {
await extractVkToFile({
processMessagesZkeyPathQv: cmdObj.processMessagesZkeyQv,
tallyVotesZkeyPathQv: cmdObj.tallyVotesZkeyQv,
processMessagesZkeyPathNonQv: cmdObj.processMessagesZkeyNonQv,
tallyVotesZkeyPathNonQv: cmdObj.tallyVotesZkeyNonQv,
outputFilePath: cmdObj.outputFile,
});
} catch (error) {
program.error((error as Error).message, { exitCode: 1 });
}
});
program
.command("signup")
.description("Sign up to a MACI contract")
Expand Down
1 change: 1 addition & 0 deletions cli/ts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type {
PollContracts,
TallyData,
VerifyArgs,
ExtractVkToFileArgs,
IRegisteredUserArgs,
IGenKeypairArgs,
IGetPollArgs,
Expand Down
27 changes: 27 additions & 0 deletions cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,3 +1062,30 @@ export interface DeployVkRegistryArgs {
*/
quiet?: boolean;
}

export interface ExtractVkToFileArgs {
/**
* File path for processMessagesQv zkey
*/
processMessagesZkeyPathQv: string;

/**
* File path for tallyVotesQv zkey
*/
tallyVotesZkeyPathQv: string;

/**
* File path for processMessagesNonQv zkey
*/
processMessagesZkeyPathNonQv: string;

/**
* File path for tallyVotes zkey
*/
tallyVotesZkeyPathNonQv: string;

/**
* Output file path of extracted vkeys
*/
outputFilePath: string;
}
1 change: 1 addition & 0 deletions website/versioned_docs/version-v1.3_alpha/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pnpm run hardhat
| `mergeMessages` | Merge the message accumulator queue | `-q, --quiet`: Whether to print values to the console <br/> `-r, --rpc-provider <provider>`: The rpc provider URL <br/> `-x, --maci-address <maciAddress>`: The MACI contract address <br/> `-o, --poll-id <pollId>`: The poll id <br/> `-n, --num-queue-ops <numQueueOps>`: The number of queue operations |
| `mergeSignups` | Merge the signups accumulator queue | `-q, --quiet`: Whether to print values to the console <br/> `-r, --rpc-provider <provider>`: The rpc provider URL <br/> `-x, --maci-address <maciAddress>`: The MACI contract address <br/> `-o, --poll-id <pollId>`: The poll id <br/> `-n, --num-queue-ops <numQueueOps>`: The number of queue operations |
| `timeTravel` | Fast-forward the time (only works for local hardhat testing) | `-s, --seconds <seconds>`: The number of seconds to fast-forward <br/> `-q, --quiet`: Whether to print values to the console <br/> `-r, --rpc-provider <provider>`: The rpc provider URL |
| `extractVkToFile` | Extract verification keys (vKey) from zKey files | `-pqv, --process-messages-zkey-qv <processMessagesZkeyPathQv>`: The path of processMessagesQv zkey files <br/> `-tqv, --tally-votes-zkey-qv <tallyVotesZkeyPathQv>`: The path of tallyVotesQv zkey files <br/> `-pnqv, --process-messages-zkey-non-qv <processMessagesZkeyPathNonQv>`: The path of processMessagesNonQv zkey files <br/> `-tnqv, --tally-votes-zkey-non-qv <tallyVotesZkeyPathNonQv>`: The path of tallyVotesNonQv zkey files <br/> |
| `signup` | Sign up to a MACI contract | `-p, --pubkey <maciPubKey>`: The MACI public key <br/> `-x, --maci-address <maciAddress>`: The MACI contract address <br/> `-s, --sg-data <sgData>`: The signup gateway data <br/> `-i, --ivcp-data <ivcpData>`: The initial voice credit proxy data <br/> `-q, --quiet`: Whether to print values to the console <br/> `-r, --rpc-provider <provider>`: The rpc provider URL |
| `isRegisteredUser` | Checks if user is registered with public key | `-p, --pubkey <maciPubKey>`: The MACI public key <br/> `-x, --maci-address <maciAddress>`: The MACI contract address <br/> `-q, --quiet`: Whether to print values to the console |
| `topup` | Top up an account with voice credits | `-a, --amount <amount>`: The amount of topup <br/> `-x, --maci-address <maciAddress>`: The MACI contract address <br/> `-i, --state-index <stateIndex>`: State leaf index <br/> `-o, --poll-id <pollId>`: Poll id <br/> `-q, --quiet`: Whether to print values to the console <br/> `-r, --rpc-provider <provider>`: The rpc provider URL |
Expand Down

0 comments on commit 346ebee

Please sign in to comment.