Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(coordinator): update maci packages #546

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/coordinator-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ env:
COORDINATOR_PUBLIC_KEY_PATH: "./pub.key"
COORDINATOR_PRIVATE_KEY_PATH: "./priv.key"
COORDINATOR_TALLY_ZKEY_NAME: "TallyVotes_10-1-2_test"
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME: "ProcessMessages_10-2-1-2_test"
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME: "ProcessMessages_10-20-2_test"
COORDINATOR_POLL_JOINING_ZKEY_NAME: "PollJoining_10_test"
COORDINATOR_ZKEY_PATH: "./zkeys/"
COORDINATOR_RAPIDSNARK_EXE: "~/rapidsnark/build/prover"
PIMLICO_API_KEY: "pim_"
RPC_API_KEY: "rpc_"
SUBGRAPH_FOLDER: "./node_modules/maci-subgraph"
SUBGRAPH_FOLDER: "./node_modules/maci-platform-subgraph"
SUBGRAPH_NAME: ${{ secrets.SUBGRAPH_NAME }}
SUBGRAPH_PROVIDER_URL: ${{ secrets.SUBGRAPH_PROVIDER_URL }}
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}
Expand Down Expand Up @@ -103,7 +104,7 @@ jobs:

- name: Download zkeys
run: |
pnpm download-zkeys:test
pnpm download-zkeys:latest

- name: Generate keypair
run: |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "lerna run build",
"clean": "lerna exec -- rm -rf node_modules build && rm -rf node_modules",
"commit": "git cz",
"download-zkeys:latest": "lerna run download-zkeys:latest --scope=maci-coordinator",
"download-zkeys:test": "lerna run download-zkeys:test --scope=maci-coordinator",
"download-zkeys:prod": "lerna run download-zkeys:prod --scope=maci-coordinator",
"prettier": "prettier -c .",
Expand Down
10 changes: 7 additions & 3 deletions packages/coordinator/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ COORDINATOR_TALLY_ZKEY_NAME=TallyVotes_10-1-2_test

# Make sure you have zkeys folder
# https://maci.pse.dev/docs/trusted-setup
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME=ProcessMessages_10-2-1-2_test
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME=ProcessMessages_10-20-2_test

# Make sure you have zkeys folder
# https://maci.pse.dev/docs/trusted-setup
COORDINATOR_POLL_JOINING_ZKEY_NAME=PollJoining_10_test

# Rapidsnark executable path
COORDINATOR_RAPIDSNARK_EXE=
Expand All @@ -34,7 +38,7 @@ COORDINATOR_ALLOWED_ORIGINS=
COORDINATOR_PORT=

# Subgraph name
SUBGRAPH_NAME="maci-subgraph"
SUBGRAPH_NAME="maci-platform-subgraph"

# Subgraph provider url
SUBGRAPH_PROVIDER_URL=https://api.studio.thegraph.com/deploy/
Expand All @@ -43,7 +47,7 @@ SUBGRAPH_PROVIDER_URL=https://api.studio.thegraph.com/deploy/
SUBGRAPH_DEPLOY_KEY=

# Subgraph project folder
SUBGRAPH_FOLDER=./node_modules/maci-subgraph
SUBGRAPH_FOLDER=./node_modules/maci-platform-subgraph

# API Key for Pimlico RPC Bundler
PIMLICO_API_KEY="pim_"
Expand Down
11 changes: 6 additions & 5 deletions packages/coordinator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"types": "tsc -p tsconfig.json --noEmit",
"generate-maci-keypair": "pnpm run run:node ./scripts/generateMaciKeypair.ts",
"generate-keypair": "pnpm run run:node ./scripts/generateKeypair.ts",
"download-zkeys:latest": "pnpm run run:node ./scripts/downloadZKeys.ts latest ./zkeys",
"download-zkeys:test": "pnpm run run:node ./scripts/downloadZKeys.ts test ./zkeys",
"download-zkeys:prod": "pnpm run run:node ./scripts/downloadZKeys.ts prod ./zkeys",
"upload-round-metadata": "pnpm run run:node ./scripts/uploadRoundMetadata.ts"
Expand Down Expand Up @@ -52,11 +53,11 @@
"hardhat": "^2.22.15",
"helmet": "^8.0.0",
"lowdb": "^1.0.0",
"maci-circuits": "^2.4.0",
"maci-cli": "^2.3.0",
"maci-contracts": "^2.3.0",
"maci-domainobjs": "^2.0.0",
"maci-subgraph": "^2.3.0",
"maci-circuits": "0.0.0-ci.30f517a",
"maci-cli": "0.0.0-ci.30f517a",
"maci-contracts": "0.0.0-ci.30f517a",
"maci-domainobjs": "0.0.0-ci.30f517a",
"maci-subgraph": "0.0.0-ci.30f517a",
"date-fns": "^4.1.0",
"mustache": "^4.2.0",
"permissionless": ">=0.1.18 <=0.1.29",
Expand Down
1 change: 1 addition & 0 deletions packages/coordinator/scripts/downloadZKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from "path";

const ZKEY_PATH = path.resolve(process.argv.slice(3)[0]);
const ZKEYS_URLS = {
latest: "https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v3.0.0/maci_artifacts_v3.0.0_test.tar.gz",
test: "https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v2.0.0/maci_artifacts_10-2-1-2_test.tar.gz",
prod: "https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v2.0.0/maci_artifacts_14-9-2-3_prod.tar.gz",
};
Expand Down
90 changes: 20 additions & 70 deletions packages/coordinator/tests/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
signup,
publish,
timeTravel,
mergeMessages,
mergeSignups,
} from "maci-cli";
import { type Proof, type TallyData, Poll__factory as PollFactory } from "maci-contracts";
Expand All @@ -35,9 +34,8 @@ import { ESubgraphEvents, type IDeploySubgraphArgs } from "../ts/subgraph/types"

const STATE_TREE_DEPTH = 10;
const INT_STATE_TREE_DEPTH = 1;
const MSG_TREE_DEPTH = 2;
const VOTE_OPTION_TREE_DEPTH = 2;
const MSG_BATCH_DEPTH = 1;
const MSG_BATCH_SIZE = 20;

describe("e2e", () => {
const coordinatorKeypair = new Keypair();
Expand All @@ -61,22 +59,23 @@ describe("e2e", () => {

process.env.COORDINATOR_ADDRESSES = await signer.getAddress();

await deployVkRegistryContract({ signer });
const vkRegistry = await deployVkRegistryContract({ signer });
await setVerifyingKeys({
quiet: true,
vkRegistry,
stateTreeDepth: STATE_TREE_DEPTH,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
messageTreeDepth: MSG_TREE_DEPTH,
voteOptionTreeDepth: VOTE_OPTION_TREE_DEPTH,
messageBatchDepth: MSG_BATCH_DEPTH,
messageBatchSize: MSG_BATCH_SIZE,
processMessagesZkeyPathNonQv: path.resolve(
__dirname,
"../zkeys/ProcessMessagesNonQv_10-2-1-2_test/ProcessMessagesNonQv_10-2-1-2_test.0.zkey",
"../zkeys/ProcessMessagesNonQv_10-20-2_test/ProcessMessagesNonQv_10-20-2_test.0.zkey",
),
tallyVotesZkeyPathNonQv: path.resolve(
__dirname,
"../zkeys/TallyVotesNonQv_10-1-2_test/TallyVotesNonQv_10-1-2_test.0.zkey",
),
pollJoiningZkeyPath: path.resolve(__dirname, "../zkeys/PollJoining_10_test/PollJoining_10_test.0.zkey"),
useQuadraticVoting: false,
signer,
});
Expand All @@ -86,8 +85,7 @@ describe("e2e", () => {
pollContracts = await deployPoll({
pollDuration: 30,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
messageTreeSubDepth: MSG_BATCH_DEPTH,
messageTreeDepth: MSG_TREE_DEPTH,
messageBatchSize: MSG_BATCH_SIZE,
voteOptionTreeDepth: VOTE_OPTION_TREE_DEPTH,
coordinatorPubkey: coordinatorKeypair.pubKey.serialize(),
useQuadraticVoting: false,
Expand Down Expand Up @@ -561,7 +559,7 @@ describe("e2e", () => {

expect(result.body).toStrictEqual({
statusCode: HttpStatus.BAD_REQUEST,
message: ErrorCodes.NOT_MERGED_STATE_TREE,
message: ErrorCodes.NOT_MERGED_STATE_TREE.toString(),
});
});

Expand All @@ -583,7 +581,7 @@ describe("e2e", () => {
});
});

expect(result.message).toBe(ErrorCodes.NOT_MERGED_STATE_TREE);
expect(result.message).toBe(ErrorCodes.NOT_MERGED_STATE_TREE.toString());
});

test("should throw an error if signups are not merged", async () => {
Expand All @@ -605,7 +603,7 @@ describe("e2e", () => {

expect(result.body).toStrictEqual({
statusCode: HttpStatus.BAD_REQUEST,
message: ErrorCodes.NOT_MERGED_STATE_TREE,
message: ErrorCodes.NOT_MERGED_STATE_TREE.toString(),
});
});

Expand All @@ -627,10 +625,10 @@ describe("e2e", () => {
});
});

expect(result.message).toBe(ErrorCodes.NOT_MERGED_STATE_TREE);
expect(result.message).toBe(ErrorCodes.NOT_MERGED_STATE_TREE.toString());
});

test("should throw an error if messages are not merged", async () => {
test("should throw an error if coordinator key decryption is failed", async () => {
const pollContract = PollFactory.connect(pollContracts.poll, signer);
const isStateMerged = await pollContract.stateMerged();

Expand All @@ -639,16 +637,14 @@ describe("e2e", () => {
await mergeSignups({ pollId: 0n, signer });
}

const publicKey = await fs.promises.readFile(process.env.COORDINATOR_PUBLIC_KEY_PATH!);
const encryptedCoordinatorPrivateKey = cryptoService.encrypt(publicKey, coordinatorKeypair.privKey.serialize());
const encryptedHeader = await getAuthorizationHeader();

const result = await request(app.getHttpServer() as App)
.post("/v1/proof/generate")
.set("Authorization", encryptedHeader)
.send({
poll: 0,
encryptedCoordinatorPrivateKey,
encryptedCoordinatorPrivateKey: coordinatorKeypair.privKey.serialize(),
maciContractAddress: maciAddresses.maciAddress,
tallyContractAddress: pollContracts.tally,
useQuadraticVoting: false,
Expand All @@ -657,11 +653,11 @@ describe("e2e", () => {

expect(result.body).toStrictEqual({
statusCode: HttpStatus.BAD_REQUEST,
message: ErrorCodes.NOT_MERGED_MESSAGE_TREE,
message: ErrorCodes.DECRYPTION.toString(),
});
});

test("should throw an error if messages are not merged (ws)", async () => {
test("should throw an error if coordinator key decryption is failed (ws)", async () => {
const pollContract = PollFactory.connect(pollContracts.poll, signer);
const isStateMerged = await pollContract.stateMerged();

Expand All @@ -670,52 +666,6 @@ describe("e2e", () => {
await mergeSignups({ pollId: 0n, signer });
}

const publicKey = await fs.promises.readFile(process.env.COORDINATOR_PUBLIC_KEY_PATH!);
const encryptedCoordinatorPrivateKey = cryptoService.encrypt(publicKey, coordinatorKeypair.privKey.serialize());

const args: IGenerateArgs = {
poll: 0,
maciContractAddress: maciAddresses.maciAddress,
tallyContractAddress: pollContracts.tally,
useQuadraticVoting: false,
encryptedCoordinatorPrivateKey,
};

const result = await new Promise<Error>((resolve) => {
socket.emit(EProofGenerationEvents.START, args).on(EProofGenerationEvents.ERROR, (error: Error) => {
resolve(error);
});
});

expect(result.message).toBe(ErrorCodes.NOT_MERGED_MESSAGE_TREE);
});

test("should throw an error if coordinator key decryption is failed", async () => {
await mergeMessages({ pollId: 0n, signer });

const encryptedHeader = await getAuthorizationHeader();

const result = await request(app.getHttpServer() as App)
.post("/v1/proof/generate")
.set("Authorization", encryptedHeader)
.send({
poll: 0,
encryptedCoordinatorPrivateKey: coordinatorKeypair.privKey.serialize(),
maciContractAddress: maciAddresses.maciAddress,
tallyContractAddress: pollContracts.tally,
useQuadraticVoting: false,
})
.expect(400);

expect(result.body).toStrictEqual({
statusCode: HttpStatus.BAD_REQUEST,
message: ErrorCodes.DECRYPTION,
});
});

test("should throw an error if coordinator key decryption is failed (ws)", async () => {
await mergeMessages({ pollId: 0n, signer });

const args: IGenerateArgs = {
poll: 0,
maciContractAddress: maciAddresses.maciAddress,
Expand All @@ -730,7 +680,7 @@ describe("e2e", () => {
});
});

expect(result.message).toBe(ErrorCodes.DECRYPTION);
expect(result.message).toBe(ErrorCodes.DECRYPTION.toString());
});

test("should throw an error if there is no such poll", async () => {
Expand All @@ -750,7 +700,7 @@ describe("e2e", () => {

expect(result.body).toStrictEqual({
statusCode: HttpStatus.BAD_REQUEST,
message: ErrorCodes.POLL_NOT_FOUND,
message: ErrorCodes.POLL_NOT_FOUND.toString(),
});
});

Expand All @@ -769,7 +719,7 @@ describe("e2e", () => {
});
});

expect(result.message).toBe(ErrorCodes.POLL_NOT_FOUND);
expect(result.message).toBe(ErrorCodes.POLL_NOT_FOUND.toString());
});

test("should throw an error if there is no authorization header", async () => {
Expand Down Expand Up @@ -828,7 +778,7 @@ describe("e2e", () => {

expect(result.body).toStrictEqual({
statusCode: HttpStatus.BAD_REQUEST,
message: ErrorCodes.DECRYPTION,
message: ErrorCodes.DECRYPTION.toString(),
});
});

Expand All @@ -847,7 +797,7 @@ describe("e2e", () => {
});
});

expect(result.message).toBe(ErrorCodes.DECRYPTION);
expect(result.message).toBe(ErrorCodes.DECRYPTION.toString());
});

test("should generate proofs properly", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/coordinator/tests/e2e.aa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ describe("E2E Account Abstraction Tests", () => {
approval,
chain: ESupportedNetworks.OPTIMISM_SEPOLIA,
}),
).rejects.toThrow(ErrorCodes.POLL_NOT_FOUND);
).rejects.toThrow(ErrorCodes.POLL_NOT_FOUND.toString());
});
});
2 changes: 1 addition & 1 deletion packages/coordinator/ts/common/__tests__/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("common", () => {

test("should throw when PIMLICO_API_KEY is not set", () => {
delete process.env.PIMLICO_API_KEY;
expect(() => genPimlicoRPCUrl("optimism-sepolia")).toThrow(ErrorCodes.PIMLICO_API_KEY_NOT_SET);
expect(() => genPimlicoRPCUrl("optimism-sepolia")).toThrow(ErrorCodes.PIMLICO_API_KEY_NOT_SET.toString());
});
});
});
6 changes: 3 additions & 3 deletions packages/coordinator/ts/common/accountAbstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const genPimlicoRPCUrl = (network: string): string => {
const pimlicoAPIKey = process.env.PIMLICO_API_KEY;

if (!pimlicoAPIKey) {
throw new Error(ErrorCodes.PIMLICO_API_KEY_NOT_SET);
throw new Error(ErrorCodes.PIMLICO_API_KEY_NOT_SET.toString());
}

return `https://api.pimlico.io/v2/${network}/rpc?apikey=${pimlicoAPIKey}`;
Expand All @@ -39,7 +39,7 @@ export const genAlchemyRPCUrl = (network: ESupportedNetworks): string => {
const rpcAPIKey = process.env.RPC_API_KEY;

if (!rpcAPIKey) {
throw new Error(ErrorCodes.RPC_API_KEY_NOT_SET);
throw new Error(ErrorCodes.RPC_API_KEY_NOT_SET.toString());
}

switch (network) {
Expand All @@ -48,7 +48,7 @@ export const genAlchemyRPCUrl = (network: ESupportedNetworks): string => {
case ESupportedNetworks.ETHEREUM_SEPOLIA:
return `https://eth-sepolia.g.alchemy.com/v2/${rpcAPIKey}`;
default:
throw new Error(ErrorCodes.UNSUPPORTED_NETWORK);
throw new Error(ErrorCodes.UNSUPPORTED_NETWORK.toString());
}
};

Expand Down
Loading
Loading