Skip to content

Commit

Permalink
test(ceremony): update ceremony params tests
Browse files Browse the repository at this point in the history
update ceremony params tests to use new artifacts, as well as adding non qv tests

#1272
  • Loading branch information
ctrlc03 committed Mar 6, 2024
1 parent 3001fe0 commit 6eda67f
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/download-ceremony-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd "$(dirname "$0")"
cd ..
mkdir -p ../cli/zkeys

URL=https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v1.2.0/maci-ceremony-artifacts-v1.2.0.tar.gz
URL=https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v1.2.0/maci_artifacts_6-9-2-3_prod.tar.gz
DIR_NAME="maci_keys.tar.gz"
OUT_DIR=../cli/

Expand Down
4 changes: 2 additions & 2 deletions circuits/ts/__tests__/CeremonyParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("Ceremony param tests", () => {
// processMessages and Tally
stateTreeDepth: 6,
// processMessages
messageTreeDepth: 8,
messageTreeDepth: 9,
// processMessages
messageBatchTreeDepth: 2,
// processMessages and Tally
Expand Down Expand Up @@ -80,7 +80,7 @@ describe("Ceremony param tests", () => {
circuit = await circomkitInstance.WitnessTester("processMessages", {
file: "processMessages",
template: "ProcessMessages",
params: [6, 8, 2, 3],
params: [6, 9, 2, 3],
});

hasherCircuit = await circomkitInstance.WitnessTester("processMessageInputHasher", {
Expand Down
300 changes: 254 additions & 46 deletions cli/tests/ceremony-params/ceremonyParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { DeployArgs, DeployPollArgs, DeployedContracts, GenProofsArgs, SetVerify
import {
coordinatorPrivKey,
coordinatorPubKey,
ceremonyProcessMessageZkeyPath,
ceremonyProcessMessagesZkeyPath,
ceremonyTallyVotesZkeyPath,
ceremonyProcessMessagesWasmPath,
cermeonyProcessMessagesWitnessPath,
ceremonyProcessMessagesWitnessPath,
testProofsDirPath,
testRapidsnarkPath,
testTallyFilePath,
Expand All @@ -37,11 +37,19 @@ import {
verifyArgs,
ceremonyProcessMessagesDatPath,
ceremonyTallyVotesDatPath,
ceremonyProcessMessagesNonQvWitnessPath,
ceremonyProcessMessagesNonQvDatPath,
ceremonyTallyVotesNonQvWitnessPath,
ceremonyTallyVotesNonQvDatPath,
ceremonyProcessMessagesNonQvZkeyPath,
ceremonyTallyVotesNonQvZkeyPath,
ceremonyProcessMessagesNonQvWasmPath,
ceremonyTallyVotesNonQvWasmPath,
} from "../constants";
import { cleanVanilla, isArm } from "../utils";

describe("stress tests", function test() {
const messageTreeDepth = 8;
describe("Stress tests with ceremony params (6,9,2,3)", function test() {
const messageTreeDepth = 9;
const stateTreeDepth = 6;
const voteOptionTreeDepth = 3;
const messageBatchDepth = 2;
Expand All @@ -64,10 +72,21 @@ describe("stress tests", function test() {
messageTreeDepth,
voteOptionTreeDepth,
messageBatchDepth,
processMessagesZkeyPath: ceremonyProcessMessageZkeyPath,
processMessagesZkeyPath: ceremonyProcessMessagesZkeyPath,
tallyVotesZkeyPath: ceremonyTallyVotesZkeyPath,
};

const verifyingKeysNonQvArgs: Omit<SetVerifyingKeysArgs, "signer"> = {
quiet: true,
stateTreeDepth,
intStateTreeDepth,
messageTreeDepth,
voteOptionTreeDepth,
messageBatchDepth,
processMessagesZkeyPath: ceremonyProcessMessagesNonQvZkeyPath,
tallyVotesZkeyPath: ceremonyTallyVotesNonQvZkeyPath,
};

const ceremonyDeployArgs: Omit<DeployArgs, "signer"> = {
stateTreeDepth,
};
Expand All @@ -86,75 +105,264 @@ describe("stress tests", function test() {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: ceremonyTallyVotesZkeyPath,
processZkey: ceremonyProcessMessageZkeyPath,
processZkey: ceremonyProcessMessagesZkeyPath,
pollId: 0n,
useWasm,
coordinatorPrivKey,
rapidsnark: testRapidsnarkPath,
processWitgen: cermeonyProcessMessagesWitnessPath,
processWitgen: ceremonyProcessMessagesWitnessPath,
tallyWitgen: ceremonyTallyVotesWitnessPath,
processWasm: ceremonyProcessMessagesWasmPath,
tallyWasm: ceremonyTallyVotesWasmPath,
processDatFile: ceremonyProcessMessagesDatPath,
tallyDatFile: ceremonyTallyVotesDatPath,
};

// before all tests we deploy the vk registry contract and set the verifying keys
before(async () => {
signer = await getDefaultSigner();
const users = Array<Keypair>(100).fill(new Keypair());

// we deploy the vk registry contract
await deployVkRegistryContract({ signer });
// we set the verifying keys
await setVerifyingKeys({ ...verifyingKeysArgs, signer });
});
describe("quadratic voting", () => {
// before all tests we deploy the vk registry contract and set the verifying keys
before(async () => {
signer = await getDefaultSigner();

const users = Array<Keypair>(2).fill(new Keypair());
// we deploy the vk registry contract
await deployVkRegistryContract({ signer });
// we set the verifying keys
await setVerifyingKeys({ ...verifyingKeysArgs, signer });
});

describe("1 user, 2 messages", () => {
after(() => {
cleanVanilla();
});

before(async () => {
// deploy the smart contracts
maciAddresses = await deploy({ ...ceremonyDeployArgs, signer });
// deploy a poll contract
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup 1 user", async () => {
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: users[0].pubKey.serialize(), signer });
});

it("should publish 2 messages", async () => {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < 2; i += 1) {
const randomVoteOption = BigInt(Math.floor(Math.random() * 126));
const randomVoteWeight = BigInt(Math.floor(Math.random() * 10));
// eslint-disable-next-line no-await-in-loop
await publish({
pubkey: users[0].pubKey.serialize(),
stateIndex: BigInt(i) + 1n,
voteOptionIndex: randomVoteOption,
nonce: 1n,
newVoteWeight: randomVoteWeight,
maciContractAddress: maciAddresses.maciAddress,
salt: genRandomSalt(),
privateKey: users[0].privKey.serialize(),
pollId: 0n,
signer,
});
}
});

describe("1 user, 2 messages", () => {
after(() => {
cleanVanilla();
it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration, signer });
await mergeMessages({ ...mergeMessagesArgs, signer });
await mergeSignups({ ...mergeSignupsArgs, signer });
await genProofs({ ...genProofsCeremonyArgs, signer });
await proveOnChain({ ...proveOnChainArgs, signer });
await verify({ ...verifyArgs(), signer });
});
});

before(async () => {
// deploy the smart contracts
maciAddresses = await deploy({ ...ceremonyDeployArgs, signer });
// deploy a poll contract
await deployPoll({ ...deployPollArgs, signer });
describe("25 signups, 100 messages", () => {
after(() => {
cleanVanilla();
});

before(async () => {
// deploy the smart contracts
maciAddresses = await deploy({ ...ceremonyDeployArgs, signer });
// deploy a poll contract
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup 25 users", async () => {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < 25; i += 1) {
// eslint-disable-next-line no-await-in-loop
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: users[i].pubKey.serialize(), signer });
}
});

it("should publish 100 messages", async () => {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < users.length; i += 1) {
const randomVoteOption = BigInt(Math.floor(Math.random() * 126));
const randomVoteWeight = BigInt(Math.floor(Math.random() * 10));
// eslint-disable-next-line no-await-in-loop
await publish({
pubkey: users[i].pubKey.serialize(),
stateIndex: 1n,
voteOptionIndex: randomVoteOption,
nonce: 1n,
pollId: 0n,
newVoteWeight: randomVoteWeight,
maciContractAddress: maciAddresses.maciAddress,
salt: genRandomSalt(),
privateKey: users[i].privKey.serialize(),
signer,
});
}
});

it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration, signer });
await mergeMessages({ ...mergeMessagesArgs, signer });
await mergeSignups({ ...mergeSignupsArgs, signer });
await genProofs({ ...genProofsCeremonyArgs, signer });
await proveOnChain({ ...proveOnChainArgs, signer });
await verify({ ...verifyArgs(), signer });
});
});
});

describe("non quadratic voting", () => {
const genProofsArgs: Omit<GenProofsArgs, "signer"> = {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: ceremonyTallyVotesNonQvZkeyPath,
processZkey: ceremonyProcessMessagesNonQvZkeyPath,
pollId: 0n,
rapidsnark: testRapidsnarkPath,
processWitgen: ceremonyProcessMessagesNonQvWitnessPath,
processDatFile: ceremonyProcessMessagesNonQvDatPath,
tallyWitgen: ceremonyTallyVotesNonQvWitnessPath,
tallyDatFile: ceremonyTallyVotesNonQvDatPath,
coordinatorPrivKey,
processWasm: ceremonyProcessMessagesNonQvWasmPath,
tallyWasm: ceremonyTallyVotesNonQvWasmPath,
useWasm,
useQuadraticVoting: false,
};

it("should signup 1 user", async () => {
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: users[0].pubKey.serialize(), signer });
// before all tests we deploy the vk registry contract and set the verifying keys
before(async () => {
signer = await getDefaultSigner();

// we deploy the vk registry contract
await deployVkRegistryContract({ signer });
// we set the verifying keys
await setVerifyingKeys({ ...verifyingKeysNonQvArgs, signer });
});

it("should publish 2 messages", async () => {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < 2; i += 1) {
const randomVoteOption = BigInt(Math.floor(Math.random() * 126));
const randomVoteWeight = BigInt(Math.floor(Math.random() * 10));
// eslint-disable-next-line no-await-in-loop
describe("1 signup, 1 message", () => {
after(() => {
cleanVanilla();
});

const user = new Keypair();

before(async () => {
// deploy the smart contracts
maciAddresses = await deploy({ ...ceremonyDeployArgs, signer, useQv: false });
// deploy a poll contract
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup one user", async () => {
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: user.pubKey.serialize(), signer });
});

it("should publish one message", async () => {
await publish({
pubkey: users[0].pubKey.serialize(),
stateIndex: BigInt(i) + 1n,
voteOptionIndex: randomVoteOption,
pubkey: user.pubKey.serialize(),
stateIndex: 1n,
voteOptionIndex: 0n,
nonce: 1n,
newVoteWeight: randomVoteWeight,
pollId: 0n,
newVoteWeight: 9n,
maciContractAddress: maciAddresses.maciAddress,
salt: genRandomSalt(),
privateKey: users[0].privKey.serialize(),
pollId: 0n,
privateKey: user.privKey.serialize(),
signer,
});
}
});

it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration, signer });
await mergeMessages({ ...mergeMessagesArgs, signer });
await mergeSignups({ ...mergeSignupsArgs, signer });
const tallyFileData = await genProofs({ ...genProofsArgs, signer, useQuadraticVoting: false });
await proveOnChain({ ...proveOnChainArgs, signer });
await verify({
...verifyArgs(),
tallyData: tallyFileData,
maciAddress: tallyFileData.maci,
tallyAddress: tallyFileData.tallyAddress,
signer,
});
});
});

it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration, signer });
await mergeMessages({ ...mergeMessagesArgs, signer });
await mergeSignups({ ...mergeSignupsArgs, signer });
await genProofs({ ...genProofsCeremonyArgs, signer });
await proveOnChain({ ...proveOnChainArgs, signer });
await verify({ ...verifyArgs(), signer });
describe("25 signups, 100 messages", () => {
after(() => {
cleanVanilla();
});

before(async () => {
// deploy the smart contracts
maciAddresses = await deploy({ ...ceremonyDeployArgs, signer, useQv: false });
// deploy a poll contract
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup 25 users", async () => {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < 25; i += 1) {
// eslint-disable-next-line no-await-in-loop
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: users[i].pubKey.serialize(), signer });
}
});

it("should publish 100 messages", async () => {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < users.length; i += 1) {
const randomVoteOption = BigInt(Math.floor(Math.random() * 126));
const randomVoteWeight = BigInt(Math.floor(Math.random() * 10));
// eslint-disable-next-line no-await-in-loop
await publish({
pubkey: users[i].pubKey.serialize(),
stateIndex: 1n,
voteOptionIndex: randomVoteOption,
nonce: 1n,
pollId: 0n,
newVoteWeight: randomVoteWeight,
maciContractAddress: maciAddresses.maciAddress,
salt: genRandomSalt(),
privateKey: users[i].privKey.serialize(),
signer,
});
}
});

it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration, signer });
await mergeMessages({ ...mergeMessagesArgs, signer });
await mergeSignups({ ...mergeSignupsArgs, signer });
const tallyFileData = await genProofs({ ...genProofsArgs, signer, useQuadraticVoting: false });
await proveOnChain({ ...proveOnChainArgs, signer });
await verify({
...verifyArgs(),
tallyData: tallyFileData,
maciAddress: tallyFileData.maci,
tallyAddress: tallyFileData.tallyAddress,
signer,
});
});
});
});
});
Loading

0 comments on commit 6eda67f

Please sign in to comment.