diff --git a/packages/circuits/circom/anon/pollJoining.circom b/packages/circuits/circom/anon/pollJoining.circom index 29358356b5..4931b66655 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 5161ab3881..43fff8456b 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 d252a86e31..1a4edba2a9 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( @@ -86,15 +84,15 @@ describe("ProcessMessage circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - for (let i = 0; i < users.length; i += 1) { - const { privKey } = users[i]; - const { pubKey: pollPubKey } = pollKeys[i]; + users.forEach((user) => { + const { privKey } = user; + const { pubKey: pollPubKey } = user; const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); poll.joinPoll(nullifier, pollPubKey, voiceCreditBalance, timestamp); - } + }); const nothing = new Message([ 8370432830353022751713833565135785980866757267633941821328460903436894336785n, @@ -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 d9ae595eea..a3f4fe36ac 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); } @@ -249,28 +242,28 @@ describe("TallyVotes circuit", function test() { poll.updatePoll(BigInt(maciState.pubKeys.length)); // Join the poll - for (let i = 0; i < x; i += 1) { - const { privKey } = userKeypairs[i]; + userKeypairs.forEach((user) => { + const { privKey: userPrivKey } = user; - const nullifier = poseidon([BigInt(privKey.rawPrivKey.toString())]); + const nullifier = poseidon([BigInt(userPrivKey.rawPrivKey.toString())]); const timestamp = BigInt(Math.floor(Date.now() / 1000)); - poll.joinPoll(nullifier, pollKeypairs[i].pubKey, voiceCreditBalance, timestamp); - } + poll.joinPoll(nullifier, user.pubKey, voiceCreditBalance, timestamp); + }); // Commands const numMessages = messageBatchSize * NUM_BATCHES; 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 2d9bdba101..97a9d40619 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 bc9e1fa347..a4abbc8549 100644 --- a/packages/cli/tests/e2e/e2e.test.ts +++ b/packages/cli/tests/e2e/e2e.test.ts @@ -107,7 +107,6 @@ describe("e2e tests", function test() { }); const user = new Keypair(); - const pollKeys = new Keypair(); before(async () => { // deploy the smart contracts @@ -129,7 +128,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, @@ -144,7 +142,7 @@ describe("e2e tests", function test() { it("should publish one message", async () => { await publish({ - pubkey: pollKeys.pubKey.serialize(), + pubkey: user.pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -152,7 +150,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys.privKey.serialize(), + privateKey: user.privKey.serialize(), signer, }); }); @@ -176,7 +174,6 @@ describe("e2e tests", function test() { }); const user = new Keypair(); - const pollKeys = new Keypair(); before(async () => { // deploy the smart contracts @@ -193,7 +190,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, @@ -208,7 +204,7 @@ describe("e2e tests", function test() { it("should publish one message", async () => { await publish({ - pubkey: pollKeys.pubKey.serialize(), + pubkey: user.pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -216,7 +212,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys.privKey.serialize(), + privateKey: user.privKey.serialize(), signer, }); }); @@ -242,7 +238,6 @@ describe("e2e tests", function test() { }); const users = [new Keypair(), new Keypair(), new Keypair(), new Keypair()]; - const pollKeys = [new Keypair(), new Keypair(), new Keypair(), new Keypair()]; before(async () => { // deploy the smart contracts @@ -266,7 +261,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 +276,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 +284,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 +296,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 +308,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 +320,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 +332,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 +344,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 +356,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 +368,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[3].privKey.serialize(), + privateKey: users[3].privKey.serialize(), signer, }); }); @@ -405,18 +399,6 @@ describe("e2e tests", function test() { new Keypair(), ]; - const pollKeys = [ - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - ]; - before(async () => { // deploy the smart contracts maciAddresses = await deploy({ ...deployArgs, signer }); @@ -439,7 +421,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 +436,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 +444,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[0].privKey.serialize(), + privateKey: users[0].privKey.serialize(), signer, }); }); @@ -483,7 +464,6 @@ describe("e2e tests", function test() { }); const user = new Keypair(); - const pollKeys = new Keypair(); before(async () => { // deploy the smart contracts @@ -504,7 +484,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, @@ -521,7 +500,7 @@ describe("e2e tests", function test() { for (let i = 0; i < 12; i += 1) { // eslint-disable-next-line no-await-in-loop await publish({ - pubkey: pollKeys.pubKey.serialize(), + pubkey: user.pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -529,7 +508,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys.privKey.serialize(), + privateKey: user.privKey.serialize(), signer, }); } @@ -550,7 +529,6 @@ describe("e2e tests", function test() { }); const users = Array.from({ length: 30 }, () => new Keypair()); - const pollKeys = Array.from({ length: 30 }, () => new Keypair()); before(async () => { // deploy the smart contracts @@ -574,7 +552,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 +569,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, }); }); @@ -668,7 +645,6 @@ describe("e2e tests", function test() { }); const user = new Keypair(); - const pollKeys = new Keypair(); before(async () => { // deploy the smart contracts @@ -681,7 +657,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 +699,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, @@ -739,7 +713,7 @@ describe("e2e tests", function test() { it("should publish a new message", async () => { await publish({ - pubkey: pollKeys.pubKey.serialize(), + pubkey: user.pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 0n, nonce: 1n, @@ -747,7 +721,7 @@ describe("e2e tests", function test() { newVoteWeight: 7n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys.privKey.serialize(), + privateKey: user.privKey.serialize(), signer, }); }); @@ -767,7 +741,6 @@ describe("e2e tests", function test() { }); const users = Array.from({ length: 4 }, () => new Keypair()); - const pollKeys = Array.from({ length: 4 }, () => new Keypair()); before(async () => { // deploy the smart contracts @@ -780,7 +753,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 +766,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 +774,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 +786,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 +823,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 +837,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 +851,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 +859,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 +874,7 @@ describe("e2e tests", function test() { newVoteWeight: 7n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[1].privKey.serialize(), + privateKey: users[1].privKey.serialize(), signer, }); }); @@ -929,15 +898,6 @@ describe("e2e tests", function test() { new Keypair(), new Keypair(), ]; - const pollKeys = [ - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - new Keypair(), - ]; after(async () => { await clean(); @@ -976,7 +936,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 +950,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 +962,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 +970,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 +998,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 +1012,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 +1026,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 +1034,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 +1047,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 +1060,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 +1075,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 +1088,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 +1101,7 @@ describe("e2e tests", function test() { newVoteWeight: 9n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys[5].privKey.serialize(), + privateKey: users[5].privKey.serialize(), signer, }); }); @@ -1191,7 +1149,6 @@ describe("e2e tests", function test() { const stateOutPath = "./state.json"; const user = new Keypair(); - const pollKeys = new Keypair(); after(async () => { await clean(); @@ -1217,7 +1174,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, @@ -1232,7 +1188,7 @@ describe("e2e tests", function test() { it("should publish one message", async () => { await publish({ - pubkey: pollKeys.pubKey.serialize(), + pubkey: user.pubKey.serialize(), stateIndex: 1n, voteOptionIndex: 5n, nonce: 1n, @@ -1240,7 +1196,7 @@ describe("e2e tests", function test() { newVoteWeight: 3n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollKeys.privKey.serialize(), + privateKey: user.privKey.serialize(), signer, }); }); diff --git a/packages/cli/tests/e2e/keyChange.test.ts b/packages/cli/tests/e2e/keyChange.test.ts index 4513607dfe..87be6d186f 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,6 @@ describe("keyChange tests", function test() { }); const user1Keypair = new Keypair(); - const { privKey: pollPrivKey1, pubKey: pollPubKey1 } = new Keypair(); const { pubKey: pollPubKey2 } = new Keypair(); const initialNonce = 1n; @@ -204,7 +202,6 @@ describe("keyChange tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user1Keypair.privKey.serialize(), - pollPrivKey: pollPrivKey1.serialize(), stateIndex, pollId, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -216,7 +213,7 @@ describe("keyChange tests", function test() { quiet: true, }); await publish({ - pubkey: pollPubKey1.serialize(), + pubkey: user1Keypair.pubKey.serialize(), stateIndex, voteOptionIndex: initialVoteOption, nonce: initialNonce, @@ -224,12 +221,12 @@ describe("keyChange tests", function test() { newVoteWeight: initialVoteAmount, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollPrivKey1.serialize(), + privateKey: user1Keypair.privKey.serialize(), signer, }); }); - it("should publish a message to change the poll and cast a new vote", async () => { + it("should publish a message to change the key and cast a new vote", async () => { await publish({ pubkey: pollPubKey2.serialize(), stateIndex, @@ -239,7 +236,7 @@ describe("keyChange tests", function test() { newVoteWeight: initialVoteAmount - 1n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollPrivKey1.serialize(), + privateKey: user1Keypair.privKey.serialize(), signer, }); }); @@ -267,8 +264,7 @@ describe("keyChange tests", function test() { }); const user1Keypair = new Keypair(); - const { privKey: pollPrivKey1, pubKey: pollPubKey1 } = new Keypair(); - const { pubKey: pollPubKey2 } = new Keypair(); + const secondKeypair = new Keypair(); const initialNonce = 1n; const initialVoteOption = 0n; @@ -293,7 +289,6 @@ describe("keyChange tests", function test() { await joinPoll({ maciAddress: maciAddresses.maciAddress, privateKey: user1Keypair.privKey.serialize(), - pollPrivKey: pollPrivKey1.serialize(), stateIndex, pollId, pollJoiningZkey: pollJoiningTestZkeyPath, @@ -306,7 +301,7 @@ describe("keyChange tests", function test() { }); await publish({ - pubkey: pollPubKey1.serialize(), + pubkey: user1Keypair.pubKey.serialize(), stateIndex, voteOptionIndex: initialVoteOption, nonce: initialNonce, @@ -314,14 +309,14 @@ describe("keyChange tests", function test() { newVoteWeight: initialVoteAmount, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollPrivKey1.serialize(), + privateKey: user1Keypair.privKey.serialize(), signer, }); }); it("should publish a message to change the poll key, and a new vote", async () => { await publish({ - pubkey: pollPubKey2.serialize(), + pubkey: secondKeypair.pubKey.serialize(), stateIndex, voteOptionIndex: initialVoteOption + 2n, nonce: initialNonce, @@ -329,7 +324,7 @@ describe("keyChange tests", function test() { newVoteWeight: initialVoteAmount - 3n, maciAddress: maciAddresses.maciAddress, salt: genRandomSalt(), - privateKey: pollPrivKey1.serialize(), + privateKey: user1Keypair.privKey.serialize(), signer, }); }); diff --git a/packages/cli/tests/unit/joinPoll.test.ts b/packages/cli/tests/unit/joinPoll.test.ts index a20c86c413..a67e96bb99 100644 --- a/packages/cli/tests/unit/joinPoll.test.ts +++ b/packages/cli/tests/unit/joinPoll.test.ts @@ -30,7 +30,6 @@ describe("joinPoll", function test() { const userPrivateKey = user.privKey.serialize(); const userPublicKey = user.pubKey.serialize(); - const { privKey: pollPrivateKey, pubKey: pollPublicKey } = new Keypair(); const mockStateIndex = 1n; const mockPollId = 9000n; @@ -64,7 +63,6 @@ describe("joinPoll", function test() { stateIndex: 1n, signer, pollId: 0n, - pollPrivKey: pollPrivateKey.serialize(), pollJoiningZkey: pollJoiningTestZkeyPath, useWasm: true, pollWasm: testPollJoiningWasmPath, @@ -76,7 +74,7 @@ describe("joinPoll", function test() { const registeredUserData = await isJoinedUser({ maciAddress: maciAddresses.maciAddress, pollId: 0n, - pollPubKey: pollPublicKey.serialize(), + pollPubKey: user.pubKey.serialize(), signer, startBlock: startBlock || 0, quiet: true, @@ -94,7 +92,6 @@ describe("joinPoll", function test() { stateIndex: mockStateIndex, signer, pollId: mockPollId, - pollPrivKey: pollPrivateKey.serialize(), pollJoiningZkey: pollJoiningTestZkeyPath, quiet: true, }), @@ -109,7 +106,6 @@ describe("joinPoll", function test() { stateIndex: -1n, signer, pollId: 0n, - pollPrivKey: pollPrivateKey.serialize(), pollJoiningZkey: pollJoiningTestZkeyPath, quiet: true, }), @@ -124,7 +120,6 @@ describe("joinPoll", function test() { stateIndex: mockStateIndex, signer, pollId: -1n, - pollPrivKey: pollPrivateKey.serialize(), pollJoiningZkey: pollJoiningTestZkeyPath, quiet: true, }), diff --git a/packages/cli/ts/commands/joinPoll.ts b/packages/cli/ts/commands/joinPoll.ts index 4eb1e3bb2c..9c7ea5bf71 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 6c77ec630f..1c428054d4 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 e31fdc1362..448d8298c4 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 8e87fe88f6..7c853eb4ab 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 ad6139992a..7e30791f60 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 d17fc2a659..1e2cc84381 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); }