diff --git a/packages/circuits/circom/anon/pollJoining.circom b/packages/circuits/circom/anon/pollJoining.circom index 29358356b..4931b6665 100644 --- a/packages/circuits/circom/anon/pollJoining.circom +++ b/packages/circuits/circom/anon/pollJoining.circom @@ -11,8 +11,6 @@ template PollJoining(stateTreeDepth) { // User's private key signal input privKey; - // Poll's private key - signal input pollPrivKey; // Poll's public key signal input pollPubKey[2]; // Siblings @@ -37,18 +35,17 @@ template PollJoining(stateTreeDepth) { // Hash the public key var pubKeyHash = PoseidonHasher(2)([derivedPubKey[0], derivedPubKey[1]]); - // Poll private to public key to verify the correct one is used to join the poll (public input) - var derivedPollPubKey[2] = PrivToPubKey()(pollPrivKey); - derivedPollPubKey[0] === pollPubKey[0]; - derivedPollPubKey[1] === pollPubKey[1]; + // Ensure the poll public key is the same as the maci one (public input) + derivedPubKey[0] === pollPubKey[0]; + derivedPubKey[1] === pollPubKey[1]; // Inclusion proof - var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)( + var calculatedRoot = BinaryMerkleRoot(stateTreeDepth)( pubKeyHash, actualStateTreeDepth, indices, siblings ); - stateLeafQip === stateRoot; + calculatedRoot === stateRoot; } diff --git a/packages/circuits/ts/__tests__/PollJoining.test.ts b/packages/circuits/ts/__tests__/PollJoining.test.ts index 5161ab388..43fff8456 100644 --- a/packages/circuits/ts/__tests__/PollJoining.test.ts +++ b/packages/circuits/ts/__tests__/PollJoining.test.ts @@ -16,7 +16,6 @@ describe("Poll Joining circuit", function test() { type PollJoiningCircuitInputs = [ "privKey", - "pollPrivKey", "pollPubKey", "stateLeaf", "siblings", @@ -42,7 +41,6 @@ describe("Poll Joining circuit", function test() { let pollId: bigint; let poll: Poll; let users: Keypair[]; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); const messages: Message[] = []; const commands: PCommand[] = []; @@ -65,24 +63,24 @@ describe("Poll Joining circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = users[0]; + const { privKey, pubKey } = users[0]; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); - const stateIndex = BigInt(poll.joinPoll(nullifier, pollPubKey, voiceCreditBalance, timestamp)); + const stateIndex = BigInt(poll.joinPoll(nullifier, pubKey, voiceCreditBalance, timestamp)); // First command (valid) const command = new PCommand( stateIndex, - pollPubKey, + pubKey, BigInt(0), // voteOptionIndex, BigInt(9), // vote weight BigInt(1), // nonce BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -97,13 +95,12 @@ describe("Poll Joining circuit", function test() { }); it("should produce a proof", async () => { - const privateKey = users[0].privKey; + const { privKey: privateKey, pubKey: pollPubKey } = users[0]; const stateLeafIndex = BigInt(1); const inputs = poll.joiningCircuitInputs({ maciPrivKey: privateKey, stateLeafIndex, - pollPrivKey, pollPubKey, }) as unknown as IPollJoiningInputs; const witness = await circuit.calculateWitness(inputs); @@ -111,13 +108,12 @@ describe("Poll Joining circuit", function test() { }); it("should fail for fake witness", async () => { - const privateKey = users[0].privKey; + const { privKey: privateKey, pubKey: pollPubKey } = users[0]; const stateLeafIndex = BigInt(1); const inputs = poll.joiningCircuitInputs({ maciPrivKey: privateKey, stateLeafIndex, - pollPrivKey, pollPubKey, }) as unknown as IPollJoiningInputs; const witness = await circuit.calculateWitness(inputs); diff --git a/packages/circuits/ts/__tests__/ProcessMessages.test.ts b/packages/circuits/ts/__tests__/ProcessMessages.test.ts index d252a86e3..9c93ec48f 100644 --- a/packages/circuits/ts/__tests__/ProcessMessages.test.ts +++ b/packages/circuits/ts/__tests__/ProcessMessages.test.ts @@ -68,11 +68,9 @@ describe("ProcessMessage circuit", function test() { before(() => { // Sign up and publish const users = new Array(5).fill(0).map(() => new Keypair()); - const pollKeys: Keypair[] = []; users.forEach((userKeypair) => { maciState.signUp(userKeypair.pubKey); - pollKeys.push(new Keypair()); }); pollId = maciState.deployPoll( @@ -88,7 +86,7 @@ describe("ProcessMessage circuit", function test() { // Join the poll for (let i = 0; i < users.length; i += 1) { const { privKey } = users[i]; - const { pubKey: pollPubKey } = pollKeys[i]; + const { pubKey: pollPubKey } = users[i]; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); @@ -119,14 +117,14 @@ describe("ProcessMessage circuit", function test() { // First command (valid) const command = new PCommand( 5n, - pollKeys[4].pubKey, + users[4].pubKey, voteOptionIndex, // voteOptionIndex, voteWeight, // vote weight BigInt(2), // nonce BigInt(pollId), ); - const signature = command.sign(pollKeys[4].privKey); + const signature = command.sign(users[4].privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -172,8 +170,7 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); @@ -190,7 +187,7 @@ describe("ProcessMessage circuit", function test() { BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -209,7 +206,7 @@ describe("ProcessMessage circuit", function test() { BigInt(1), // nonce BigInt(pollId), ); - const signature2 = command2.sign(pollPrivKey); + const signature2 = command2.sign(privKey); const ecdhKeypair2 = new Keypair(); const sharedKey2 = Keypair.genEcdhSharedKey(ecdhKeypair2.privKey, coordinatorKeypair.pubKey); @@ -277,8 +274,7 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(1); @@ -294,7 +290,7 @@ describe("ProcessMessage circuit", function test() { BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -360,16 +356,13 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(1); const stateIndex = poll.joinPoll(nullifier, pollPubKey, voiceCreditBalance, timestamp); - const { privKey: pollPrivKey2, pubKey: pollPubKey2 } = new Keypair(); - // Vote for option 0 const command = new PCommand( BigInt(stateIndex), // BigInt(1), @@ -380,7 +373,7 @@ describe("ProcessMessage circuit", function test() { BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -399,7 +392,7 @@ describe("ProcessMessage circuit", function test() { BigInt(2), // nonce BigInt(pollId), ); - const signature2 = command2.sign(pollPrivKey); + const signature2 = command2.sign(privKey); const ecdhKeypair2 = new Keypair(); const sharedKey2 = Keypair.genEcdhSharedKey(ecdhKeypair2.privKey, coordinatorKeypair.pubKey); @@ -411,14 +404,14 @@ describe("ProcessMessage circuit", function test() { // Change key const command3 = new PCommand( BigInt(stateIndex), // BigInt(1), - pollPubKey2, + pollPubKey, BigInt(1), // voteOptionIndex, BigInt(0), // vote weight BigInt(1), // nonce BigInt(pollId), ); - const signature3 = command3.sign(pollPrivKey2); + const signature3 = command3.sign(privKey); const ecdhKeypair3 = new Keypair(); const sharedKey3 = Keypair.genEcdhSharedKey(ecdhKeypair3.privKey, coordinatorKeypair.pubKey); @@ -483,8 +476,7 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); @@ -503,7 +495,7 @@ describe("ProcessMessage circuit", function test() { BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -547,8 +539,7 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); @@ -585,7 +576,7 @@ describe("ProcessMessage circuit", function test() { pollId, ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -604,7 +595,7 @@ describe("ProcessMessage circuit", function test() { 1n, // nonce pollId, ); - const signature2 = command2.sign(pollPrivKey); + const signature2 = command2.sign(privKey); const ecdhKeypair2 = new Keypair(); const sharedKey2 = Keypair.genEcdhSharedKey(ecdhKeypair2.privKey, coordinatorKeypair.pubKey); @@ -670,8 +661,7 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); @@ -708,7 +698,7 @@ describe("ProcessMessage circuit", function test() { pollId, ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -732,7 +722,7 @@ describe("ProcessMessage circuit", function test() { 1n, // nonce pollId, ); - const signature2 = command2.sign(pollPrivKey); + const signature2 = command2.sign(privKey); const ecdhKeypair2 = new Keypair(); const sharedKey2 = Keypair.genEcdhSharedKey(ecdhKeypair2.privKey, coordinatorKeypair.pubKey); @@ -800,8 +790,7 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); @@ -837,7 +826,7 @@ describe("ProcessMessage circuit", function test() { pollId, ); - const signatureFinal = commandFinal.sign(pollPrivKey); + const signatureFinal = commandFinal.sign(privKey); const ecdhKeypairFinal = new Keypair(); const sharedKeyFinal = Keypair.genEcdhSharedKey(ecdhKeypairFinal.privKey, coordinatorKeypair.pubKey); @@ -857,7 +846,7 @@ describe("ProcessMessage circuit", function test() { pollId, ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -881,7 +870,7 @@ describe("ProcessMessage circuit", function test() { 1n, // nonce pollId, ); - const signature2 = command2.sign(pollPrivKey); + const signature2 = command2.sign(privKey); const ecdhKeypair2 = new Keypair(); const sharedKey2 = Keypair.genEcdhSharedKey(ecdhKeypair2.privKey, coordinatorKeypair.pubKey); diff --git a/packages/circuits/ts/__tests__/TallyVotes.test.ts b/packages/circuits/ts/__tests__/TallyVotes.test.ts index d9ae595ee..5820fb9f5 100644 --- a/packages/circuits/ts/__tests__/TallyVotes.test.ts +++ b/packages/circuits/ts/__tests__/TallyVotes.test.ts @@ -45,6 +45,9 @@ describe("TallyVotes circuit", function test() { let circuitNonQv: WitnessTester; + const userKeypair = new Keypair(); + const { privKey, pubKey: pollPubKey } = userKeypair; + before(async () => { circuit = await circomkitInstance.WitnessTester("tallyVotes", { file: "./core/qv/tallyVotes", @@ -72,7 +75,6 @@ describe("TallyVotes circuit", function test() { const messages: Message[] = []; const commands: PCommand[] = []; // Sign up and publish - const userKeypair = new Keypair(); maciState.signUp(userKeypair.pubKey); pollId = maciState.deployPoll( @@ -86,10 +88,7 @@ describe("TallyVotes circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); - - const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); + const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString()), pollId]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); stateIndex = BigInt(poll.joinPoll(nullifier, pollPubKey, voiceCreditBalance, timestamp)); @@ -104,7 +103,7 @@ describe("TallyVotes circuit", function test() { BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -152,7 +151,6 @@ describe("TallyVotes circuit", function test() { const messages: Message[] = []; const commands: PCommand[] = []; // Sign up and publish - const userKeypair = new Keypair(); maciState.signUp(userKeypair.pubKey); pollId = maciState.deployPoll( @@ -166,10 +164,7 @@ describe("TallyVotes circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - const { privKey } = userKeypair; - const { privKey: pollPrivKey, pubKey: pollPubKey } = new Keypair(); - - const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); + const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString()), pollId]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); stateIndex = BigInt(poll.joinPoll(nullifier, pollPubKey, voiceCreditBalance, timestamp)); @@ -184,7 +179,7 @@ describe("TallyVotes circuit", function test() { BigInt(pollId), ); - const signature = command.sign(pollPrivKey); + const signature = command.sign(privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); @@ -227,13 +222,11 @@ describe("TallyVotes circuit", function test() { it("should produce the correct state root and ballot root", async () => { const maciState = new MaciState(STATE_TREE_DEPTH); const userKeypairs: Keypair[] = []; - const pollKeypairs: Keypair[] = []; // Sign up for (let i = 0; i < x; i += 1) { const k = new Keypair(); userKeypairs.push(k); - pollKeypairs.push(new Keypair()); maciState.signUp(k.pubKey); } @@ -255,7 +248,7 @@ describe("TallyVotes circuit", function test() { const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); - poll.joinPoll(nullifier, pollKeypairs[i].pubKey, voiceCreditBalance, timestamp); + poll.joinPoll(nullifier, userKeypairs[i].pubKey, voiceCreditBalance, timestamp); } // Commands @@ -263,14 +256,14 @@ describe("TallyVotes circuit", function test() { for (let i = 0; i < numMessages; i += 1) { const command = new PCommand( BigInt(i), - pollKeypairs[i].pubKey, + userKeypairs[i].pubKey, BigInt(i), // vote option index BigInt(1), // vote weight BigInt(1), // nonce BigInt(pollId), ); - const signature = command.sign(pollKeypairs[i].privKey); + const signature = command.sign(userKeypairs[i].privKey); const ecdhKeypair = new Keypair(); const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, coordinatorKeypair.pubKey); diff --git a/packages/circuits/ts/types.ts b/packages/circuits/ts/types.ts index 2d9bdba10..97a9d4061 100644 --- a/packages/circuits/ts/types.ts +++ b/packages/circuits/ts/types.ts @@ -45,7 +45,6 @@ export interface IGenProofOptions { */ export interface IPollJoiningInputs { privKey: bigint; - pollPrivKey: bigint; pollPubKey: bigint[][]; stateLeaf: bigint[]; siblings: bigint[][]; diff --git a/packages/cli/tests/e2e/e2e.test.ts b/packages/cli/tests/e2e/e2e.test.ts index bc9e1fa34..95b97779d 100644 --- a/packages/cli/tests/e2e/e2e.test.ts +++ b/packages/cli/tests/e2e/e2e.test.ts @@ -129,7 +129,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user.privKey.serialize(), - pollPrivKey: pollKeys.privKey.serialize(), stateIndex: 1n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -193,7 +192,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user.privKey.serialize(), - pollPrivKey: pollKeys.privKey.serialize(), stateIndex: 1n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -266,7 +264,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[i].privKey.serialize(), - pollPrivKey: pollKeys[i].privKey.serialize(), stateIndex: BigInt(i + 1), pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -282,7 +279,7 @@ describe("e2e tests", function test() { it("should publish eight messages", async () => { await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 2n, @@ -290,11 +287,11 @@ describe("e2e tests", function test() { newVoteWeight: 4n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 2n, @@ -302,11 +299,11 @@ describe("e2e tests", function test() { newVoteWeight: 3n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -314,11 +311,11 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[1].pubKey.serialize(), + pubkey: users[1].pubKey.serialize(), stateIndex: 2n, voteOptionIndex: 2n, nonce: 1n, @@ -326,11 +323,11 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[1].privKey.serialize(), + privateKey: users[1].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[2].pubKey.serialize(), + pubkey: users[2].pubKey.serialize(), stateIndex: 3n, voteOptionIndex: 2n, nonce: 1n, @@ -338,11 +335,11 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[2].privKey.serialize(), + privateKey: users[2].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[3].pubKey.serialize(), + pubkey: users[3].pubKey.serialize(), stateIndex: 4n, voteOptionIndex: 2n, nonce: 3n, @@ -350,11 +347,11 @@ describe("e2e tests", function test() { newVoteWeight: 3n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[3].privKey.serialize(), + privateKey: users[3].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[3].pubKey.serialize(), + pubkey: users[3].pubKey.serialize(), stateIndex: 4n, voteOptionIndex: 2n, nonce: 2n, @@ -362,11 +359,11 @@ describe("e2e tests", function test() { newVoteWeight: 2n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[3].privKey.serialize(), + privateKey: users[3].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[3].pubKey.serialize(), + pubkey: users[3].pubKey.serialize(), stateIndex: 4n, voteOptionIndex: 1n, nonce: 1n, @@ -374,7 +371,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[3].privKey.serialize(), + privateKey: users[3].privKey.serialize(), signer, }); }); @@ -439,7 +436,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[i].privKey.serialize(), - pollPrivKey: pollKeys[i].privKey.serialize(), stateIndex: BigInt(i + 1), pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -455,7 +451,7 @@ describe("e2e tests", function test() { it("should publish one message", async () => { await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -463,7 +459,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); }); @@ -504,7 +500,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user.privKey.serialize(), - pollPrivKey: pollKeys.privKey.serialize(), stateIndex: 1n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -574,7 +569,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[i].privKey.serialize(), - pollPrivKey: pollKeys[i].privKey.serialize(), stateIndex: BigInt(i + 1), pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -592,53 +586,53 @@ describe("e2e tests", function test() { // publish four different messages await publish({ maciAddress: maciAddresses.maciAddress, - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, pollId: 0n, newVoteWeight: 9n, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); await publish({ maciAddress: maciAddresses.maciAddress, - pubkey: pollKeys[1].pubKey.serialize(), + pubkey: users[1].pubKey.serialize(), stateIndex: 2n, voteOptionIndex: 1n, nonce: 1n, pollId: 0n, newVoteWeight: 9n, salt: genRandomSalt(), - privateKey: pollKeys[1].privKey.serialize(), + privateKey: users[1].privKey.serialize(), signer, }); await publish({ maciAddress: maciAddresses.maciAddress, - pubkey: pollKeys[2].pubKey.serialize(), + pubkey: users[2].pubKey.serialize(), stateIndex: 3n, voteOptionIndex: 2n, nonce: 1n, pollId: 0n, newVoteWeight: 9n, salt: genRandomSalt(), - privateKey: pollKeys[2].privKey.serialize(), + privateKey: users[2].privKey.serialize(), signer, }); await publish({ maciAddress: maciAddresses.maciAddress, - pubkey: pollKeys[3].pubKey.serialize(), + pubkey: users[3].pubKey.serialize(), stateIndex: 4n, voteOptionIndex: 3n, nonce: 1n, pollId: 0n, newVoteWeight: 9n, salt: genRandomSalt(), - privateKey: pollKeys[3].privKey.serialize(), + privateKey: users[3].privKey.serialize(), signer, }); }); @@ -681,7 +675,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user.privKey.serialize(), - pollPrivKey: pollKeys.privKey.serialize(), stateIndex: 1n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -724,7 +717,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user.privKey.serialize(), - pollPrivKey: pollKeys.privKey.serialize(), stateIndex: 1n, pollId: 1n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -780,7 +772,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[0].privKey.serialize(), - pollPrivKey: pollKeys[0].privKey.serialize(), stateIndex: 1n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -794,7 +785,7 @@ describe("e2e tests", function test() { // publish await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -802,7 +793,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); @@ -814,7 +805,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[1].privKey.serialize(), - pollPrivKey: pollKeys[1].privKey.serialize(), stateIndex: 2n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -852,7 +842,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[2].privKey.serialize(), - pollPrivKey: pollKeys[2].privKey.serialize(), stateIndex: 4n, pollId: 1n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -867,7 +856,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[3].privKey.serialize(), - pollPrivKey: pollKeys[3].privKey.serialize(), stateIndex: 5n, pollId: 1n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -882,7 +870,7 @@ describe("e2e tests", function test() { it("should publish a new message from the first poll voter", async () => { await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -890,14 +878,14 @@ describe("e2e tests", function test() { newVoteWeight: 7n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); }); it("should publish a new message by the new poll voters", async () => { await publish({ - pubkey: pollKeys[1].pubKey.serialize(), + pubkey: users[1].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -905,7 +893,7 @@ describe("e2e tests", function test() { newVoteWeight: 7n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[1].privKey.serialize(), + privateKey: users[1].privKey.serialize(), signer, }); }); @@ -976,7 +964,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[i].privKey.serialize(), - pollPrivKey: pollKeys[i].privKey.serialize(), stateIndex: BigInt(i + 1), pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -991,7 +978,7 @@ describe("e2e tests", function test() { const { isJoined, pollStateIndex } = await isJoinedUser({ maciAddress: maciAddresses.maciAddress, pollId: 0n, - pollPubKey: pollKeys[i].pubKey.serialize(), + pollPubKey: users[i].pubKey.serialize(), signer, startBlock: 0, quiet: true, @@ -1003,7 +990,7 @@ describe("e2e tests", function test() { // publish await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -1011,7 +998,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); @@ -1039,7 +1026,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: users[i].privKey.serialize(), - pollPrivKey: pollKeys[i].privKey.serialize(), stateIndex: BigInt(i + 1), pollId: BigInt(p), pollJoiningZkey: pollJoiningTestZkeyPath, @@ -1054,7 +1040,7 @@ describe("e2e tests", function test() { const { isJoined, pollStateIndex } = await isJoinedUser({ maciAddress: maciAddresses.maciAddress, pollId: BigInt(p), - pollPubKey: pollKeys[i].pubKey.serialize(), + pollPubKey: users[i].pubKey.serialize(), signer, startBlock: 0, quiet: true, @@ -1068,7 +1054,7 @@ describe("e2e tests", function test() { it("should publish messages to the second poll", async () => { await publish({ - pubkey: pollKeys[0].pubKey.serialize(), + pubkey: users[0].pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -1076,12 +1062,12 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[1].pubKey.serialize(), + pubkey: users[1].pubKey.serialize(), stateIndex: 2n, voteOptionIndex: 3n, nonce: 1n, @@ -1089,12 +1075,12 @@ describe("e2e tests", function test() { newVoteWeight: 1n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[1].privKey.serialize(), + privateKey: users[1].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[2].pubKey.serialize(), + pubkey: users[2].pubKey.serialize(), stateIndex: 3n, voteOptionIndex: 5n, nonce: 1n, @@ -1102,14 +1088,14 @@ describe("e2e tests", function test() { newVoteWeight: 3n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[2].privKey.serialize(), + privateKey: users[2].privKey.serialize(), signer, }); }); it("should publish messages to the third poll", async () => { await publish({ - pubkey: pollKeys[3].pubKey.serialize(), + pubkey: users[3].pubKey.serialize(), stateIndex: 3n, voteOptionIndex: 5n, nonce: 1n, @@ -1117,12 +1103,12 @@ describe("e2e tests", function test() { newVoteWeight: 3n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[3].privKey.serialize(), + privateKey: users[3].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[4].pubKey.serialize(), + pubkey: users[4].pubKey.serialize(), stateIndex: 4n, voteOptionIndex: 7n, nonce: 1n, @@ -1130,12 +1116,12 @@ describe("e2e tests", function test() { newVoteWeight: 2n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[4].privKey.serialize(), + privateKey: users[4].privKey.serialize(), signer, }); await publish({ - pubkey: pollKeys[5].pubKey.serialize(), + pubkey: users[5].pubKey.serialize(), stateIndex: 5n, voteOptionIndex: 5n, nonce: 1n, @@ -1143,7 +1129,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[5].privKey.serialize(), + privateKey: users[5].privKey.serialize(), signer, }); }); @@ -1217,7 +1203,6 @@ describe("e2e tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user.privKey.serialize(), - pollPrivKey: pollKeys.privKey.serialize(), stateIndex: 1n, pollId: 0n, pollJoiningZkey: pollJoiningTestZkeyPath, diff --git a/packages/cli/tests/e2e/keyChange.test.ts b/packages/cli/tests/e2e/keyChange.test.ts index 4513607df..ba9e16375 100644 --- a/packages/cli/tests/e2e/keyChange.test.ts +++ b/packages/cli/tests/e2e/keyChange.test.ts @@ -89,7 +89,7 @@ describe("keyChange tests", function test() { }); const user1Keypair = new Keypair(); - const { privKey: pollPrivKey1, pubKey: pollPubKey1 } = new Keypair(); + const { privKey: pollPrivKey1, pubKey: pollPubKey1 } = user1Keypair; const { pubKey: pollPubKey2 } = new Keypair(); const initialNonce = 1n; @@ -115,7 +115,6 @@ describe("keyChange tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user1Keypair.privKey.serialize(), - pollPrivKey: pollPrivKey1.serialize(), stateIndex, pollId, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -178,7 +177,7 @@ describe("keyChange tests", function test() { }); const user1Keypair = new Keypair(); - const { privKey: pollPrivKey1, pubKey: pollPubKey1 } = new Keypair(); + const { privKey: pollPrivKey1, pubKey: pollPubKey1 } = user1Keypair; const { pubKey: pollPubKey2 } = new Keypair(); const initialNonce = 1n; @@ -204,7 +203,6 @@ describe("keyChange tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user1Keypair.privKey.serialize(), - pollPrivKey: pollPrivKey1.serialize(), stateIndex, pollId, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -293,7 +291,6 @@ describe("keyChange tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user1Keypair.privKey.serialize(), - pollPrivKey: pollPrivKey1.serialize(), stateIndex, pollId, pollJoiningZkey: pollJoiningTestZkeyPath, diff --git a/packages/cli/ts/commands/joinPoll.ts b/packages/cli/ts/commands/joinPoll.ts index 4eb1e3bb2..9c7ea5bf7 100644 --- a/packages/cli/ts/commands/joinPoll.ts +++ b/packages/cli/ts/commands/joinPoll.ts @@ -99,7 +99,6 @@ const joiningCircuitInputs = ( stateTreeDepth: bigint, maciPrivKey: PrivKey, stateLeafIndex: bigint, - pollPrivKey: PrivKey, pollPubKey: PubKey, pollId: bigint, ): IPollJoiningCircuitInputs => { @@ -141,7 +140,6 @@ const joiningCircuitInputs = ( const circuitInputs = { privKey: maciPrivKey.asCircuitInputs(), - pollPrivKey: pollPrivKey.asCircuitInputs(), pollPubKey: pollPubKey.asCircuitInputs(), siblings: siblingsArray, indices, @@ -162,7 +160,6 @@ const joiningCircuitInputs = ( export const joinPoll = async ({ maciAddress, privateKey, - pollPrivKey, stateIndex, stateFile, pollId, @@ -198,11 +195,6 @@ export const joinPoll = async ({ const userMaciPubKey = new Keypair(userMaciPrivKey).pubKey; const nullifier = poseidon([BigInt(userMaciPrivKey.asCircuitInputs()), pollId]); - // Create poll public key from poll private key - const pollPrivKeyDeserialized = PrivKey.deserialize(pollPrivKey); - const pollKeyPair = new Keypair(pollPrivKeyDeserialized); - const pollPubKey = pollKeyPair.pubKey; - const maciContract = MACIFactory.connect(maciAddress, signer); const pollContracts = await maciContract.getPoll(pollId); @@ -246,8 +238,7 @@ export const joinPoll = async ({ circuitInputs = poll.joiningCircuitInputs({ maciPrivKey: userMaciPrivKey, stateLeafIndex: loadedStateIndex!, - pollPrivKey: pollPrivKeyDeserialized, - pollPubKey, + pollPubKey: userMaciPubKey, }) as unknown as CircuitInputs; } else { // build an off-chain representation of the MACI contract using data in the contract storage @@ -292,8 +283,7 @@ export const joinPoll = async ({ stateTreeDepth, userMaciPrivKey, loadedStateIndex!, - pollPrivKeyDeserialized, - pollPubKey, + userMaciPubKey, pollId, ) as unknown as CircuitInputs; } @@ -321,7 +311,7 @@ export const joinPoll = async ({ // submit the message onchain as well as the encryption public key const tx = await pollContract.joinPoll( nullifier, - pollPubKey.asContractParam(), + userMaciPubKey.asContractParam(), currentStateRootIndex, proof, sgData, diff --git a/packages/cli/ts/index.ts b/packages/cli/ts/index.ts index 6c77ec630..1c428054d 100644 --- a/packages/cli/ts/index.ts +++ b/packages/cli/ts/index.ts @@ -219,7 +219,6 @@ program .requiredOption("-k, --priv-key ", "the private key") .option("-i, --state-index ", "the user's state index", BigInt) .requiredOption("-s, --sg-data ", "the signup gateway data") - .requiredOption("-e, --poll-priv-key ", "the user ephemeral private key for the poll") .option("-v, --ivcp-data ", "the initial voice credit proxy data") .option( "-n, --new-voice-credit-balance ", @@ -253,7 +252,6 @@ program await joinPoll({ maciAddress, privateKey, - pollPrivKey: cmdObj.pollPrivKey, stateIndex: cmdObj.stateIndex || undefined, stateFile: cmdObj.stateFile, pollId: cmdObj.pollId, diff --git a/packages/cli/ts/utils/interfaces.ts b/packages/cli/ts/utils/interfaces.ts index e31fdc136..448d8298c 100644 --- a/packages/cli/ts/utils/interfaces.ts +++ b/packages/cli/ts/utils/interfaces.ts @@ -459,11 +459,6 @@ export interface IJoinPollArgs { */ pollWasm?: string; - /** - * Poll private key for the poll - */ - pollPrivKey: string; - /** * The signup gatekeeper data */ diff --git a/packages/core/ts/Poll.ts b/packages/core/ts/Poll.ts index 8e87fe88f..7c853eb4a 100644 --- a/packages/core/ts/Poll.ts +++ b/packages/core/ts/Poll.ts @@ -434,14 +434,12 @@ export class Poll implements IPoll { * Create circuit input for pollJoining * @param maciPrivKey User's private key for signing up * @param stateLeafIndex Index where the user is stored in the state leaves - * @param pollPrivKey Poll's private key for the poll joining - * @param pollPubKey Poll's public key for the poll joining + * @param pollPubKey Poll's public key for joining the poll * @returns stringified circuit inputs */ joiningCircuitInputs = ({ maciPrivKey, stateLeafIndex, - pollPrivKey, pollPubKey, }: IJoiningCircuitArgs): IPollJoiningCircuitInputs => { // calculate the path elements for the state tree given the original state tree @@ -476,7 +474,6 @@ export class Poll implements IPoll { const circuitInputs = { privKey: maciPrivKey.asCircuitInputs(), - pollPrivKey: pollPrivKey.asCircuitInputs(), pollPubKey: pollPubKey.asCircuitInputs(), siblings: siblingsArray, indices, diff --git a/packages/core/ts/utils/types.ts b/packages/core/ts/utils/types.ts index ad6139992..7e30791f6 100644 --- a/packages/core/ts/utils/types.ts +++ b/packages/core/ts/utils/types.ts @@ -139,7 +139,6 @@ export interface IProcessMessagesOutput { export interface IJoiningCircuitArgs { maciPrivKey: PrivKey; stateLeafIndex: bigint; - pollPrivKey: PrivKey; pollPubKey: PubKey; } /** @@ -147,7 +146,6 @@ export interface IJoiningCircuitArgs { */ export interface IPollJoiningCircuitInputs { privKey: string; - pollPrivKey: string; pollPubKey: string[]; stateLeaf: string[]; siblings: string[][]; diff --git a/packages/integrationTests/ts/__tests__/integration.test.ts b/packages/integrationTests/ts/__tests__/integration.test.ts index d17fc2a65..1e2cc8438 100644 --- a/packages/integrationTests/ts/__tests__/integration.test.ts +++ b/packages/integrationTests/ts/__tests__/integration.test.ts @@ -155,12 +155,10 @@ describe("Integration tests", function test() { data.suites.forEach((testCase) => { it(testCase.description, async () => { const users = genTestUserCommands(testCase.numUsers, testCase.numVotesPerUser, testCase.bribers, testCase.votes); - const pollKeys: Keypair[] = Array.from({ length: testCase.numUsers }, () => new Keypair()); // loop through all users and generate keypair + signup for (let i = 0; i < users.length; i += 1) { const user = users[i]; - const pollKey = pollKeys[i]; const timestamp = Date.now(); // signup const stateIndex = BigInt( @@ -175,7 +173,6 @@ describe("Integration tests", function test() { await joinPoll({ maciAddress: contracts.maciAddress, privateKey: user.keypair.privKey.serialize(), - pollPrivKey: pollKey.privKey.serialize(), stateIndex, pollId, pollJoiningZkey: path.resolve(__dirname, "../../../cli/zkeys/PollJoining_10_test/PollJoining_10_test.0.zkey"), @@ -200,7 +197,7 @@ describe("Integration tests", function test() { const inputNullifier = BigInt(user.keypair.privKey.asCircuitInputs()); const nullifier = poseidon([inputNullifier]); const poll = maciState.polls.get(pollId); - poll?.joinPoll(nullifier, pollKey.pubKey, BigInt(initialVoiceCredits), BigInt(timestamp)); + poll?.joinPoll(nullifier, user.keypair.pubKey, BigInt(initialVoiceCredits), BigInt(timestamp)); // publish messages for (let j = 0; j < user.votes.length; j += 1) { @@ -221,7 +218,7 @@ describe("Integration tests", function test() { // actually publish it const encryptionKey = await publish({ - pubkey: pollKey.pubKey.serialize(), + pubkey: user.keypair.pubKey.serialize(), stateIndex, voteOptionIndex: voteOptionIndex!, nonce, @@ -230,7 +227,7 @@ describe("Integration tests", function test() { maciAddress: contracts.maciAddress, salt, // if it's a key change command, then we pass the old private key otherwise just pass the current - privateKey: isKeyChange ? oldKeypair.privKey.serialize() : pollKey.privKey.serialize(), + privateKey: isKeyChange ? oldKeypair.privKey.serialize() : user.keypair.privKey.serialize(), signer, }); @@ -240,14 +237,14 @@ describe("Integration tests", function test() { // create the command to add to the local state const command = new PCommand( stateIndex, - pollKey.pubKey, + user.keypair.pubKey, voteOptionIndex!, newVoteWeight!, nonce, pollId, salt, ); - const signature = command.sign(isKeyChange ? oldKeypair.privKey : pollKey.privKey); + const signature = command.sign(isKeyChange ? oldKeypair.privKey : user.keypair.privKey); const message = command.encrypt(signature, Keypair.genEcdhSharedKey(encPrivKey, coordinatorKeypair.pubKey)); maciState.polls.get(pollId)?.publishMessage(message, encPubKey); }