Skip to content

Commit

Permalink
docs(cli): clarify cli commands
Browse files Browse the repository at this point in the history
- [x] Circuit files clarification
- [x] Tally file and verify command clarification
  • Loading branch information
0xmad committed Jan 16, 2024
1 parent 760fff9 commit 3aa4f33
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
1 change: 1 addition & 0 deletions cli/ts/commands/checkVerifyingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
/**
* 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 stateTreeDepth the depth of the state tree
* @param intStateTreeDepth the depth of the state subtree
* @param messageTreeDepth the depth of the message tree
Expand Down
1 change: 1 addition & 0 deletions cli/ts/commands/genProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { Proof, TallyData } from "../utils/interfaces";

/**
* Generate proofs for the message processing, tally and subsidy calculations
* @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 outputDir - the directory to store the proofs
* @param tallyFile - the file to store the tally proof
* @param tallyZkey - the path to the tally zkey file
Expand Down
1 change: 1 addition & 0 deletions cli/ts/commands/setVerifyingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { info, logError, logGreen, logYellow, success } from "../utils/theme";

/**
* Function that sets the verifying keys in the VkRegistry contract
* @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 stateTreeDepth - the depth of the state tree
* @param intStateTreeDepth - the depth of the state subtree
* @param messageTreeDepth - the depth of the message tree
Expand Down
14 changes: 9 additions & 5 deletions cli/ts/commands/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { banner, contractExists, info, logError, logGreen, logYellow, readContra
import { verifyPerVOSpentVoiceCredits, verifyTallyResults } from "../utils/verifiers";

/**
* Verify the results of a poll and optionally the subsidy results
* Verify the results of a poll and optionally the subsidy results on-chain
* @param pollId - the id of the poll
* @param subsidyEnabled - whether to deploy subsidy contract
* @param tallyFile - the path to the tally file
* @param tallyFile - the path to the tally file with results, per vote option spent credits, spent voice credits total
* @param maciAddress - the address of the MACI contract
* @param tallyAddress - the address of the Tally contract
* @param subsidyAddress - the address of the Subsidy contract
Expand Down Expand Up @@ -51,6 +51,7 @@ export const verify = async (
const tallyContractAddress = tallyAddress || readContractAddress(`Tally-${pollId}`);

let subsidyContractAddress = "";

if (subsidyEnabled) {
subsidyContractAddress = subsidyAddress || readContractAddress(`Subsidy-${pollId}`);
}
Expand Down Expand Up @@ -79,16 +80,17 @@ export const verify = async (
: undefined;

// verification
const onChainTallycomment = BigInt(await tallyContract.tallyCommitment());
const onChainTallyCommitment = BigInt(await tallyContract.tallyCommitment());

logYellow(quiet, info(`on-chain tally commitment: ${onChainTallycomment.toString(16)}`));
logYellow(quiet, info(`on-chain tally commitment: ${onChainTallyCommitment.toString(16)}`));

// ensure we have either tally data or tally file
if (!(tallyData || tallyFile)) {
logError("No tally data or tally file provided.");
}
// if we have the data as param, then use that
let tallyResults: TallyData;

if (tallyData) {
tallyResults = tallyData;
} else {
Expand Down Expand Up @@ -149,7 +151,7 @@ export const verify = async (
newPerVOSpentVoiceCreditsCommitment,
]);

if (onChainTallycomment !== newTallyCommitment) {
if (onChainTallyCommitment !== newTallyCommitment) {
logError("The on-chain tally commitment does not match.");
}
logGreen(quiet, success("The on-chain tally commitment matches."));
Expand All @@ -161,6 +163,7 @@ export const verify = async (
newResultsCommitment,
newPerVOSpentVoiceCreditsCommitment,
);

if (isValid) {
logGreen(quiet, success("The on-chain verification of total spent voice credits passed."));
} else {
Expand All @@ -175,6 +178,7 @@ export const verify = async (
newSpentVoiceCreditsCommitment,
newResultsCommitment,
);

if (failedSpentCredits.length === 0) {
logGreen(quiet, success("The on-chain verification of per vote option spent voice credits passed"));
} else {
Expand Down
40 changes: 32 additions & 8 deletions cli/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,18 @@ program
.requiredOption("-m, --msg-tree-depth <messageTreeDepth>", "the message tree depth", parseInt)
.requiredOption("-v, --vote-option-tree-depth <voteOptionTreeDepth>", "the vote option tree depth", parseInt)
.requiredOption("-b, --msg-batch-depth <messageBatchDepth>", "the message batch depth", parseInt)
.requiredOption("-p, --process-messages-zkey <processMessagesZkeyPath>", "the process messages zkey path")
.requiredOption("-t, --tally-votes-zkey <tallyVotesZkeyPath>", "the tally votes zkey path")
.option("-ss, --subsidy-zkey <subsidyZkeyPath>", "the subsidy zkey path")
.requiredOption(
"-p, --process-messages-zkey <processMessagesZkeyPath>",
"the process messages 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(
"-t, --tally-votes-zkey <tallyVotesZkeyPath>",
"the tally votes 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)",
)
.option(
"-ss, --subsidy-zkey <subsidyZkeyPath>",
"the subsidy 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)",
)
.action(async (cmdOptions) => {
try {
await checkVerifyingKeys(
Expand Down Expand Up @@ -199,12 +208,21 @@ program
.requiredOption("-m, --msg-tree-depth <messageTreeDepth>", "the message tree depth", parseInt)
.requiredOption("-v, --vote-option-tree-depth <voteOptionTreeDepth>", "the vote option tree depth", parseInt)
.requiredOption("-b, --msg-batch-depth <messageBatchDepth>", "the message batch depth", parseInt)
.requiredOption("-p, --process-messages-zkey <processMessagesZkeyPath>", "the process messages zkey path")
.requiredOption("-t, --tally-votes-zkey <tallyVotesZkeyPath>", "the tally votes zkey path")
.requiredOption(
"-p, --process-messages-zkey <processMessagesZkeyPath>",
"the process messages 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(
"-t, --tally-votes-zkey <tallyVotesZkeyPath>",
"the tally votes 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)",
)
.option("-k, --vk-registry <vkRegistry>", "the vk registry contract address")
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
.option("-ss, --subsidy-zkey <subsidyZkeyPath>", "the subsidy zkey path")
.option(
"-ss, --subsidy-zkey <subsidyZkeyPath>",
"the subsidy 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)",
)
.action(async (cmdObj) => {
try {
await setVerifyingKeys(
Expand Down Expand Up @@ -351,7 +369,10 @@ program
.command("verify")
.description("verify the results of a poll and optionally the subsidy results")
.requiredOption("-o, --poll-id <pollId>", "the poll id", parseInt)
.requiredOption("-t, --tally-file <tallyFile>", "the tally file")
.requiredOption(
"-t, --tally-file <tallyFile>",
"the tally file with results, per vote option spent credits, spent voice credits total",
)
.requiredOption(
"-se, --subsidy-enabled <subsidyEnabled>",
"whether to deploy subsidy contract",
Expand Down Expand Up @@ -387,7 +408,10 @@ program
.option("-sk, --privkey <privkey>", "your serialized MACI private key")
.option("-x, --contract <contract>", "the MACI contract address")
.requiredOption("-o, --poll-id <pollId>", "the poll id", parseInt)
.requiredOption("-t, --tally-file <tallyFile>", "the tally file")
.requiredOption(
"-t, --tally-file <tallyFile>",
"the tally file with results, per vote option spent credits, spent voice credits total",
)
.option("-s, --subsidy-file <subsidyFile>", "the subsidy file")
.option("-r, --rapidsnark <rapidsnark>", "the path to the rapidsnark binary")
.option("-wp, --process-witnessgen <processWitnessgen>", "the path to the process witness generation binary")
Expand Down
Loading

0 comments on commit 3aa4f33

Please sign in to comment.