Skip to content

Commit

Permalink
feat(coordinator): rebase with sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoSerranoP committed Feb 27, 2025
1 parent 7d12ae1 commit b4358b4
Show file tree
Hide file tree
Showing 17 changed files with 1,430 additions and 162 deletions.
1 change: 1 addition & 0 deletions packages/coordinator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"helmet": "^8.0.0",
"lowdb": "^1.0.0",
"maci-cli": "^2.5.0",
"maci-crypto": "^2.5.0",
"maci-contracts": "^2.5.0",
"maci-domainobjs": "^2.5.0",
"maci-subgraph": "^2.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/coordinator/scripts/generateMaciKeyPair.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { genKeyPair } from "maci-cli";
import { genKeypair } from "maci-crypto";

genKeyPair({ seed: undefined, quiet: false });
genKeypair();
29 changes: 14 additions & 15 deletions packages/coordinator/tests/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/*
// TODO: Uncomment this, solve errors and change from maci-contracts to maci-sdk
import { HttpStatus, ValidationPipe, type INestApplication } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import { ValidationError } from "class-validator";
import dotenv from "dotenv";
import { type Signer } from "ethers";
import hardhat from "hardhat";
import { type DeployedContracts, type PollContracts, deploy, timeTravel } from "maci-cli";
import {
type DeployedContracts,
type PollContracts,
deploy,
deployPoll,
deployVkRegistryContract,
setVerifyingKeys,
signup,
publish,
timeTravel,
mergeSignups,
} from "maci-cli";
import { type Proof, type TallyData, Poll__factory as PollFactory, getBlockTimestamp } from "maci-contracts";
type Proof,
type TallyData,
Poll__factory as PollFactory,
getBlockTimestamp,
deployVkRegistry,
} from "maci-contracts";
import { Keypair } from "maci-domainobjs";
import { mergeSignups, signup, setVerifyingKeys, deployPoll, publish } from "maci-sdk";
import { io, Socket } from "socket.io-client";
import request from "supertest";
Expand Down Expand Up @@ -57,10 +56,9 @@ describe("e2e", () => {
process.env.COORDINATOR_ADDRESSES = await signer.getAddress();
const vkRegistry = await deployVkRegistryContract({ signer });
const vkRegistry = await deployVkRegistry(signer);
await setVerifyingKeys({
quiet: true,
vkRegistry,
vkRegistryAddress: await vkRegistry.getAddress(),
stateTreeDepth: STATE_TREE_DEPTH,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
voteOptionTreeDepth: VOTE_OPTION_TREE_DEPTH,
Expand Down Expand Up @@ -851,3 +849,4 @@ describe("e2e", () => {
});
});
});
*/
11 changes: 11 additions & 0 deletions packages/coordinator/tests/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AbiCoder } from "ethers";

import { homedir } from "os";

export const pollJoiningTestZkeyPath = "./zkeys/PollJoining_10_test/PollJoining_10_test.0.zkey";
export const testPollJoiningWasmPath = "./zkeys/PollJoining_10_test/PollJoining_10_test_js/PollJoining_10_test.wasm";
export const testPollJoiningWitnessPath = "./zkeys/PollJoining_10_test/PollJoining_10_test_cpp/PollJoining_10_test";
export const testRapidsnarkPath = `${homedir()}/rapidsnark/build/prover`;

export const zeroUint256Encoded = AbiCoder.defaultAbiCoder().encode(["uint256"], [0]);
export const oneUint256Encoded = AbiCoder.defaultAbiCoder().encode(["uint256"], [1]);
74 changes: 37 additions & 37 deletions packages/coordinator/tests/e2e.deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import { ValidationPipe, type INestApplication } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import dotenv from "dotenv";
import { AbiCoder, type Signer } from "ethers";
import { type Signer } from "ethers";
import hardhat from "hardhat";
import { Poll__factory as PollFactory, MACI__factory as MACIFactory, Poll as PollContract, MACI } from "maci-contracts";
import { Keypair } from "maci-domainobjs";
import { signup } from "maci-sdk";
import { Socket, io } from "socket.io-client";
import { Hex, pad, zeroAddress } from "viem";
import { Hex, zeroAddress } from "viem";

import { AppModule } from "../ts/app.module";
import { ESupportedNetworks } from "../ts/common";
Expand All @@ -20,6 +20,7 @@ import { generateApproval, getKernelAccount } from "../ts/sessionKeys/__tests__/
import { IGenerateSessionKeyReturn } from "../ts/sessionKeys/types";
import { IDeploySubgraphArgs } from "../ts/subgraph/types";

import { zeroUint256Encoded } from "./constants";
import { getAuthorizationHeader, rechargeGasIfNeeded, replacer } from "./utils";

dotenv.config();
Expand All @@ -33,15 +34,13 @@ describe("E2E Deployment Tests", () => {
let coordinatorKeypair: Keypair;
let sessionKeyAddress: Hex;
let approval: string;
let maciContract: MACI;
let pollContract: PollContract;

let app: INestApplication;
let socket: Socket;
const publicClient = getPublicClient(ESupportedNetworks.OPTIMISM_SEPOLIA);

let maciAddress: Hex;
let pollId: number;
// let pollId: bigint;

// set up coordinator address
beforeAll(async () => {
Expand Down Expand Up @@ -155,7 +154,8 @@ describe("E2E Deployment Tests", () => {
expect(body.pollId).toBeDefined();

// save them for next tests
pollId = Number(body.pollId);
// TODO: uncomment this!
// pollId = BigInt(body.pollId);
});

test("should deploy a subgraph correctly", async () => {
Expand Down Expand Up @@ -186,44 +186,44 @@ describe("E2E Deployment Tests", () => {
});

test("should allow voting on a poll", async () => {
const zeroUint256Encoded = AbiCoder.defaultAbiCoder().encode(["uint256"], [0]);
const oneUint256Encoded = AbiCoder.defaultAbiCoder().encode(["uint256"], [1]);

maciAddress = "0x311d3e3ddb88c6d0e29ce2cc2953b53850d7195b";
pollId = 1;

// get poll contract address
maciContract = MACIFactory.connect(maciAddress, signer);

const pollContracts = await maciContract.getPoll(BigInt(pollId));
pollContract = PollFactory.connect(pollContracts.poll, signer);

for (let i = 0; i < NUM_USERS; i += 1) {
const keypairUser = new Keypair();
const pubkeyUser = keypairUser.pubKey.asContractParam();
const pubkeyUser = keypairUser.pubKey.serialize();
// make users sign up to MACI
// eslint-disable-next-line no-await-in-loop
await maciContract.signUp(pubkeyUser, oneUint256Encoded);
await signup({
maciAddress,
maciPubKey: pubkeyUser,
sgData: zeroUint256Encoded,
signer,
});

const mockProof = [0, 0, 0, 0, 0, 0, 0, 0];
const mockNullifier = zeroUint256Encoded;
/*
// make users join the poll
// eslint-disable-next-line no-await-in-loop
const response = await pollContract.joinPoll(
mockNullifier,
pubkeyUser,
0,
mockProof,
oneUint256Encoded,
oneUint256Encoded,
);
// eslint-disable-next-line no-await-in-loop
const receipt = await response.wait();
expect(receipt).toBeDefined();
expect(receipt?.hash).not.toBe(pad("0x"));
const jp = await joinPoll({
maciAddress,
privateKey: keypairUser.privKey.serialize(),
stateIndex: BigInt(i),
pollId,
pollJoiningZkey: pollJoiningTestZkeyPath,
useWasm: true,
pollWasm: testPollJoiningWasmPath,
pollWitgen: testPollJoiningWitnessPath,
rapidsnark: testRapidsnarkPath,
sgDataArg: zeroUint256Encoded,
ivcpDataArg: zeroUint256Encoded,
signer,
});
expect(jp.pollStateIndex).toBe(String(i));
expect(jp.hash).not.toBe(pad("0x"));
expect(jp.nullifier).toBeDefined();
*/

// TODO: make user publish message to Poll
// TODO: make users publish messages in batch to Poll
}
// TODO: make user publish message to Poll
// TODO: make users publish messages in batch to Poll
});

/*
Expand Down
1 change: 0 additions & 1 deletion packages/coordinator/ts/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { ErrorCodes } from "./errors";
export { ESupportedNetworks } from "./networks";
export { transformToString } from "./utils";
export const MESSAGE_TREE_ARITY = 5n;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
GitcoinPassportGatekeeper__factory as GitcoinPassportGatekeeperFactory,
MACI__factory as MACIFactory,
Verifier__factory as VerifierFactory,
} from "maci-contracts";
} from "maci-sdk";
import { zeroAddress } from "viem";

import path from "path";
Expand Down
2 changes: 1 addition & 1 deletion packages/coordinator/ts/deployer/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EGatekeepers, EInitialVoiceCreditProxies } from "maci-contracts";
import { Keypair } from "maci-domainobjs";
import { EGatekeepers, EInitialVoiceCreditProxies } from "maci-sdk";

import { IDeployMaciConfig, IDeployPollConfig } from "../types";

Expand Down
9 changes: 4 additions & 5 deletions packages/coordinator/ts/deployer/deployer.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Injectable, Logger } from "@nestjs/common";
import { KernelAccountClient, KernelSmartAccount } from "@zerodev/sdk";
import { BaseContract, InterfaceAbi } from "ethers";
import { genEmptyBallotRoots } from "maci-contracts";
import { IVkObjectParams, PubKey, VerifyingKey } from "maci-domainobjs";
import {
ConstantInitialVoiceCreditProxy__factory as ConstantInitialVoiceCreditProxyFactory,
ContractStorage,
Expand All @@ -26,12 +28,10 @@ import {
MACI__factory as MACIFactory,
EContracts,
EInitialVoiceCreditProxies,
genEmptyBallotRoots,
EMode,
IVerifyingKeyStruct,
extractVk,
} from "maci-contracts";
import { IVkObjectParams, PubKey, VerifyingKey } from "maci-domainobjs";
IVerifyingKeyStruct,
} from "maci-sdk";
import { BundlerClient, GetUserOperationReceiptReturnType } from "permissionless";
import { ENTRYPOINT_ADDRESS_V07_TYPE } from "permissionless/types";
import { Abi, Chain, encodeFunctionData, HttpTransport, PublicClient, Transport, type Hex } from "viem";
Expand Down Expand Up @@ -667,7 +667,6 @@ export class DeployerService {

// 5. maci (here we don't check whether one is already deployed, we just deploy it)
const emptyBallotRoots = genEmptyBallotRoots(config.MACI.stateTreeDepth);

const maciAddress = await this.deployAndStore(
EContracts.MACI,
[
Expand Down
2 changes: 1 addition & 1 deletion packages/coordinator/ts/deployer/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EGatekeepers, EInitialVoiceCreditProxies } from "maci-contracts";
import { EGatekeepers, EInitialVoiceCreditProxies } from "maci-sdk";
import { PrepareUserOperationRequestParameters } from "permissionless/actions/smartAccount";
import { ENTRYPOINT_ADDRESS_V07_TYPE } from "permissionless/types";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Test } from "@nestjs/testing";

import type { IGetPublicKeyData } from "../../file/types";
import type { IGenerateArgs, IGenerateData, IMergeArgs } from "../types";
import type { TallyData } from "maci-cli";
import type { ITallyData } from "maci-sdk";

import { ESupportedNetworks } from "../../common";
import { FileService } from "../../file/file.service";
Expand Down Expand Up @@ -33,7 +33,7 @@ describe("ProofController", () => {
const defaultProofGeneratorData: IGenerateData = {
tallyProofs: [],
processProofs: [],
tallyData: {} as TallyData,
tallyData: {} as ITallyData,
};

const defaultPublicKeyData: IGetPublicKeyData = {
Expand Down
5 changes: 2 additions & 3 deletions packages/coordinator/ts/proof/__tests__/proof.gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Test } from "@nestjs/testing";
import { Server } from "socket.io";

import type { IGenerateArgs, IGenerateData } from "../types";
import type { TallyData } from "maci-cli";
import type { IGenerateProofsOptions } from "maci-contracts";
import type { ITallyData, IGenerateProofsOptions } from "maci-sdk";

import { ProofGateway } from "../proof.gateway";
import { ProofGeneratorService } from "../proof.service";
Expand All @@ -24,7 +23,7 @@ describe("ProofGateway", () => {
const defaultProofGeneratorData: IGenerateData = {
tallyProofs: [],
processProofs: [],
tallyData: {} as TallyData,
tallyData: {} as ITallyData,
};

const mockGeneratorService = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dotenv from "dotenv";
import { Deployment, ProofGenerator } from "maci-contracts";
import { Keypair, PrivKey } from "maci-domainobjs";
import { Deployment, ProofGenerator } from "maci-sdk";
import { zeroAddress } from "viem";

import type { IGenerateArgs } from "../types";
Expand Down
4 changes: 2 additions & 2 deletions packages/coordinator/ts/proof/proof.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Logger, UseGuards, UsePipes, ValidationPipe } from "@nestjs/common";
import { MessageBody, SubscribeMessage, WebSocketGateway, WebSocketServer, WsException } from "@nestjs/websockets";

import type { IGenerateProofsBatchData, Proof, TallyData } from "maci-contracts";
import type { IGenerateProofsBatchData, IProof, ITallyData } from "maci-sdk";
import type { Server } from "socket.io";

import { AccountSignatureGuard } from "../auth/AccountSignatureGuard.service";
Expand Down Expand Up @@ -65,7 +65,7 @@ export class ProofGateway {
onBatchComplete: (result: IGenerateProofsBatchData) => {
this.server.emit(EProofGenerationEvents.PROGRESS, result);
},
onComplete: (proofs: Proof[], tallyData?: TallyData) => {
onComplete: (proofs: IProof[], tallyData?: ITallyData) => {
this.server.emit(EProofGenerationEvents.FINISH, { proofs, tallyData });
},
onFail: (error: Error) => {
Expand Down
Loading

0 comments on commit b4358b4

Please sign in to comment.