diff --git a/.github/workflows/nightly-ceremony.yml b/.github/workflows/nightly-ceremony.yml index 155edd3de1..a17fcdb208 100644 --- a/.github/workflows/nightly-ceremony.yml +++ b/.github/workflows/nightly-ceremony.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: v1.2.2 + ref: dev - uses: pnpm/action-setup@v4 with: diff --git a/packages/circuits/ts/__tests__/CeremonyParams.test.ts b/packages/circuits/ts/__tests__/CeremonyParams.test.ts index 8d2f21a3a6..a73d8d4bf4 100644 --- a/packages/circuits/ts/__tests__/CeremonyParams.test.ts +++ b/packages/circuits/ts/__tests__/CeremonyParams.test.ts @@ -11,7 +11,7 @@ import { generateRandomIndex, circomkitInstance } from "./utils/utils"; describe("Ceremony param tests", () => { const params = { // processMessages and Tally - stateTreeDepth: 6, + stateTreeDepth: 14, // processMessages messageTreeDepth: 9, // processMessages @@ -19,11 +19,11 @@ describe("Ceremony param tests", () => { // processMessages and Tally voteOptionTreeDepth: 3, // Tally - stateLeafBatchDepth: 2, + stateLeafBatchDepth: 5, }; const treeDepths = { - intStateTreeDepth: params.messageBatchTreeDepth, + intStateTreeDepth: params.stateLeafBatchDepth, messageTreeDepth: params.messageTreeDepth, messageTreeSubDepth: params.messageBatchTreeDepth, voteOptionTreeDepth: params.voteOptionTreeDepth, @@ -71,7 +71,7 @@ describe("Ceremony param tests", () => { circuit = await circomkitInstance.WitnessTester("processMessages", { file: "./core/qv/processMessages", template: "ProcessMessages", - params: [6, 9, 2, 3], + params: [14, 9, 2, 3], }); }); @@ -175,117 +175,117 @@ describe("Ceremony param tests", () => { expect(newBallotRoot?.toString()).not.to.be.eq(currentBallotRoot.toString()); }); }); + }); - describe("TallyVotes circuit", function test() { - this.timeout(900000); - - let testCircuit: WitnessTester< - [ - "stateRoot", - "ballotRoot", - "sbSalt", - "sbCommitment", - "index", - "numSignUps", - "currentTallyCommitment", - "newTallyCommitment", - "ballots", - "ballotPathElements", - "votes", - "currentResults", - "currentResultsRootSalt", - "currentSpentVoiceCreditSubtotal", - "currentSpentVoiceCreditSubtotalSalt", - "currentPerVOSpentVoiceCredits", - "currentPerVOSpentVoiceCreditsRootSalt", - "newResultsRootSalt", - "newPerVOSpentVoiceCreditsRootSalt", - "newSpentVoiceCreditSubtotalSalt", - ] - >; - - before(async () => { - testCircuit = await circomkitInstance.WitnessTester("tallyVotes", { - file: "./core/qv/tallyVotes", - template: "TallyVotes", - params: [6, 2, 3], - }); + describe("TallyVotes circuit", function test() { + this.timeout(900000); + + let testCircuit: WitnessTester< + [ + "stateRoot", + "ballotRoot", + "sbSalt", + "sbCommitment", + "index", + "numSignUps", + "currentTallyCommitment", + "newTallyCommitment", + "ballots", + "ballotPathElements", + "votes", + "currentResults", + "currentResultsRootSalt", + "currentSpentVoiceCreditSubtotal", + "currentSpentVoiceCreditSubtotalSalt", + "currentPerVOSpentVoiceCredits", + "currentPerVOSpentVoiceCreditsRootSalt", + "newResultsRootSalt", + "newPerVOSpentVoiceCreditsRootSalt", + "newSpentVoiceCreditSubtotalSalt", + ] + >; + + before(async () => { + testCircuit = await circomkitInstance.WitnessTester("tallyVotes", { + file: "./core/qv/tallyVotes", + template: "TallyVotes", + params: [14, 5, 3], }); + }); - describe("1 user, 2 messages", () => { - let stateIndex: bigint; - let pollId: bigint; - let poll: Poll; - let maciState: MaciState; - const voteWeight = BigInt(9); - const voteOptionIndex = BigInt(0); - - beforeEach(() => { - maciState = new MaciState(params.stateTreeDepth); - const messages: Message[] = []; - const commands: PCommand[] = []; - // Sign up and publish - const userKeypair = new Keypair(); - stateIndex = BigInt( - maciState.signUp(userKeypair.pubKey, voiceCreditBalance, BigInt(Math.floor(Date.now() / 1000))), - ); - - pollId = maciState.deployPoll( - BigInt(Math.floor(Date.now() / 1000) + duration), - treeDepths, - messageBatchSize, - coordinatorKeypair, - ); - - poll = maciState.polls.get(pollId)!; - - // update the state - poll.updatePoll(BigInt(maciState.stateLeaves.length)); - - // First command (valid) - const command = new PCommand( - stateIndex, - userKeypair.pubKey, - voteOptionIndex, // voteOptionIndex, - voteWeight, // vote weight - BigInt(1), // nonce - BigInt(pollId), - ); - - const signature = command.sign(userKeypair.privKey); - - const ecdhKeypair = new Keypair(); - const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); - const message = command.encrypt(signature, sharedKey); - messages.push(message); - commands.push(command); - - poll.publishMessage(message, ecdhKeypair.pubKey); - - // Process messages - poll.processMessages(pollId); - }); + describe("1 user, 2 messages", () => { + let stateIndex: bigint; + let pollId: bigint; + let poll: Poll; + let maciState: MaciState; + const voteWeight = BigInt(9); + const voteOptionIndex = BigInt(0); - it("should produce the correct result commitments", async () => { - const generatedInputs = poll.tallyVotes() as unknown as ITallyVotesInputs; - const witness = await testCircuit.calculateWitness(generatedInputs); - await testCircuit.expectConstraintPass(witness); - }); + beforeEach(() => { + maciState = new MaciState(params.stateTreeDepth); + const messages: Message[] = []; + const commands: PCommand[] = []; + // Sign up and publish + const userKeypair = new Keypair(); + stateIndex = BigInt( + maciState.signUp(userKeypair.pubKey, voiceCreditBalance, BigInt(Math.floor(Date.now() / 1000))), + ); - it("should produce the correct result if the initial tally is not zero", async () => { - const generatedInputs = poll.tallyVotes() as unknown as ITallyVotesInputs; + pollId = maciState.deployPoll( + BigInt(Math.floor(Date.now() / 1000) + duration), + treeDepths, + messageBatchSize, + coordinatorKeypair, + ); - // Start the tally from non-zero value - let randIdx = generateRandomIndex(Object.keys(generatedInputs).length); - while (randIdx === 0) { - randIdx = generateRandomIndex(Object.keys(generatedInputs).length); - } + poll = maciState.polls.get(pollId)!; - generatedInputs.currentResults[randIdx] = 1n; + // update the state + poll.updatePoll(BigInt(maciState.stateLeaves.length)); - const witness = await testCircuit.calculateWitness(generatedInputs); - await testCircuit.expectConstraintPass(witness); - }); + // First command (valid) + const command = new PCommand( + stateIndex, + userKeypair.pubKey, + voteOptionIndex, // voteOptionIndex, + voteWeight, // vote weight + BigInt(1), // nonce + BigInt(pollId), + ); + + const signature = command.sign(userKeypair.privKey); + + const ecdhKeypair = new Keypair(); + const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); + const message = command.encrypt(signature, sharedKey); + messages.push(message); + commands.push(command); + + poll.publishMessage(message, ecdhKeypair.pubKey); + + // Process messages + poll.processMessages(pollId); + }); + + it("should produce the correct result commitments", async () => { + const generatedInputs = poll.tallyVotes() as unknown as ITallyVotesInputs; + const witness = await testCircuit.calculateWitness(generatedInputs); + await testCircuit.expectConstraintPass(witness); + }); + + it("should produce the correct result if the initial tally is not zero", async () => { + const generatedInputs = poll.tallyVotes() as unknown as ITallyVotesInputs; + + // Start the tally from non-zero value + let randIdx = generateRandomIndex(Object.keys(generatedInputs).length); + while (randIdx === 0) { + randIdx = generateRandomIndex(Object.keys(generatedInputs).length); + } + + generatedInputs.currentResults[randIdx] = 1n; + + const witness = await testCircuit.calculateWitness(generatedInputs); + await testCircuit.expectConstraintPass(witness); }); }); }); diff --git a/packages/cli/tests/ceremony-params/ceremonyParams.test.ts b/packages/cli/tests/ceremony-params/ceremonyParams.test.ts index 354534c772..d1a590ba84 100644 --- a/packages/cli/tests/ceremony-params/ceremonyParams.test.ts +++ b/packages/cli/tests/ceremony-params/ceremonyParams.test.ts @@ -48,12 +48,12 @@ import { } from "../constants"; import { clean, isArm } from "../utils"; -describe("Stress tests with ceremony params (6,9,2,3)", function test() { +describe("Stress tests with ceremony params (14,9,2,3)", function test() { const messageTreeDepth = 9; - const stateTreeDepth = 6; + const stateTreeDepth = 14; const voteOptionTreeDepth = 3; const messageBatchDepth = 2; - const intStateTreeDepth = 2; + const intStateTreeDepth = 5; const pollDuration = 60000; diff --git a/packages/cli/tests/constants.ts b/packages/cli/tests/constants.ts index c51e16fa68..15d7644826 100644 --- a/packages/cli/tests/constants.ts +++ b/packages/cli/tests/constants.ts @@ -44,32 +44,32 @@ export const testProcessMessagesWasmPath = export const testTallyVotesWasmPath = "./zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test_js/TallyVotes_10-1-2_test.wasm"; export const testRapidsnarkPath = `${homedir()}/rapidsnark/build/prover`; -export const ceremonyProcessMessagesZkeyPath = "./zkeys/ProcessMessages_6-9-2-3/processMessages_6-9-2-3.zkey"; +export const ceremonyProcessMessagesZkeyPath = "./zkeys/ProcessMessages_14-9-2-3/processMessages_14-9-2-3.zkey"; export const ceremonyProcessMessagesNonQvZkeyPath = - "./zkeys/ProcessMessagesNonQv_6-9-2-3/processMessagesNonQv_6-9-2-3.zkey"; -export const ceremonyTallyVotesZkeyPath = "./zkeys/TallyVotes_6-2-3/tallyVotes_6-2-3.zkey"; -export const ceremonyTallyVotesNonQvZkeyPath = "./zkeys/TallyVotesNonQv_6-2-3/tallyVotesNonQv_6-2-3.zkey"; + "./zkeys/ProcessMessagesNonQv_14-9-2-3/processMessagesNonQv_14-9-2-3.zkey"; +export const ceremonyTallyVotesZkeyPath = "./zkeys/TallyVotes_14-5-3/tallyVotes_14-5-3.zkey"; +export const ceremonyTallyVotesNonQvZkeyPath = "./zkeys/TallyVotesNonQv_14-5-3/tallyVotesNonQv_14-5-3.zkey"; export const ceremonyProcessMessagesWitnessPath = - "./zkeys/ProcessMessages_6-9-2-3/ProcessMessages_6-9-2-3_cpp/ProcessMessages_6-9-2-3"; + "./zkeys/ProcessMessages_14-9-2-3/ProcessMessages_14-9-2-3_cpp/ProcessMessages_14-9-2-3"; export const ceremonyProcessMessagesNonQvWitnessPath = - "./zkeys/ProcessMessagesNonQv_6-9-2-3/ProcessMessagesNonQv_6-9-2-3_cpp/ProcessMessagesNonQv_6-9-2-3"; + "./zkeys/ProcessMessagesNonQv_14-9-2-3/ProcessMessagesNonQv_14-9-2-3_cpp/ProcessMessagesNonQv_14-9-2-3"; export const ceremonyProcessMessagesDatPath = - "./zkeys/ProcessMessages_6-9-2-3/ProcessMessages_6-9-2-3_cpp/ProcessMessages_6-9-2-3.dat"; + "./zkeys/ProcessMessages_14-9-2-3/ProcessMessages_14-9-2-3_cpp/ProcessMessages_14-9-2-3.dat"; export const ceremonyProcessMessagesNonQvDatPath = - "./zkeys/ProcessMessagesNonQv_6-9-2-3/ProcessMessagesNonQv_6-9-2-3_cpp/ProcessMessagesNonQv_6-9-2-3.dat"; -export const ceremonyTallyVotesWitnessPath = "./zkeys/TallyVotes_6-2-3/TallyVotes_6-2-3_cpp/TallyVotes_6-2-3"; + "./zkeys/ProcessMessagesNonQv_14-9-2-3/ProcessMessagesNonQv_14-9-2-3_cpp/ProcessMessagesNonQv_14-9-2-3.dat"; +export const ceremonyTallyVotesWitnessPath = "./zkeys/TallyVotes_14-5-3/TallyVotes_14-5-3_cpp/TallyVotes_14-5-3"; export const ceremonyTallyVotesNonQvWitnessPath = - "./zkeys/TallyVotesNonQv_6-2-3/TallyVotesNonQv_6-2-3_cpp/TallyVotesNonQv_6-2-3"; -export const ceremonyTallyVotesDatPath = "./zkeys/TallyVotes_6-2-3/TallyVotes_6-2-3_cpp/TallyVotes_6-2-3.dat"; + "./zkeys/TallyVotesNonQv_14-5-3/TallyVotesNonQv_14-5-3_cpp/TallyVotesNonQv_14-5-3"; +export const ceremonyTallyVotesDatPath = "./zkeys/TallyVotes_14-5-3/TallyVotes_14-5-3_cpp/TallyVotes_14-5-3.dat"; export const ceremonyTallyVotesNonQvDatPath = - "./zkeys/TallyVotesNonQv_6-2-3/TallyVotesNonQv_6-2-3_cpp/TallyVotesNonQv_6-2-3.dat"; + "./zkeys/TallyVotesNonQv_14-5-3/TallyVotesNonQv_14-5-3_cpp/TallyVotesNonQv_14-5-3.dat"; export const ceremonyProcessMessagesWasmPath = - "./zkeys/ProcessMessages_6-9-2-3/ProcessMessages_6-9-2-3_js/ProcessMessages_6-9-2-3.wasm"; + "./zkeys/ProcessMessages_14-9-2-3/ProcessMessages_14-9-2-3_js/ProcessMessages_14-9-2-3.wasm"; export const ceremonyProcessMessagesNonQvWasmPath = - "./zkeys/ProcessMessagesNonQv_6-9-2-3/ProcessMessagesNonQv_6-9-2-3_js/ProcessMessagesNonQv_6-9-2-3.wasm"; -export const ceremonyTallyVotesWasmPath = "./zkeys/TallyVotes_6-2-3/TallyVotes_6-2-3_js/TallyVotes_6-2-3.wasm"; + "./zkeys/ProcessMessagesNonQv_14-9-2-3/ProcessMessagesNonQv_14-9-2-3_js/ProcessMessagesNonQv_14-9-2-3.wasm"; +export const ceremonyTallyVotesWasmPath = "./zkeys/TallyVotes_14-5-3/TallyVotes_14-5-3_js/TallyVotes_14-5-3.wasm"; export const ceremonyTallyVotesNonQvWasmPath = - "./zkeys/TallyVotesNonQv_6-2-3/TallyVotesNonQv_6-2-3_js/TallyVotesNonQv_6-2-3.wasm"; + "./zkeys/TallyVotesNonQv_14-5-3/TallyVotesNonQv_14-5-3_js/TallyVotesNonQv_14-5-3.wasm"; export const testProcessMessagesNonQvWitnessPath = "./zkeys/ProcessMessagesNonQv_10-2-1-2_test/ProcessMessagesNonQv_10-2-1-2_test_cpp/ProcessMessagesNonQv_10-2-1-2_test"; export const testProcessMessagesNonQvWitnessDatPath = @@ -84,8 +84,6 @@ export const testTallyVotesNonQvWasmPath = "./zkeys/TallyVotesNonQv_10-1-2_test/TallyVotesNonQv_10-1-2_test_js/TallyVotesNonQv_10-1-2_test.wasm"; export const pollDuration = 90; -export const maxMessages = 25; -export const maxVoteOptions = 25; export const setVerifyingKeysArgs: Omit = { quiet: true,