Skip to content

Commit

Permalink
refactor: contract imports and proofs (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 authored Jan 29, 2025
1 parent 44c9e1e commit 66dfab7
Show file tree
Hide file tree
Showing 59 changed files with 486 additions and 336 deletions.
2 changes: 1 addition & 1 deletion apps/relayer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"helia": "^5.2.0",
"helmet": "^8.0.0",
"lodash": "^4.17.21",
"maci-circuits": "workspace:^2.5.0",
"maci-cli": "workspace:^2.5.0",
"maci-contracts": "workspace:^2.5.0",
"maci-sdk": "workspace:^0.0.1",
"maci-domainobjs": "workspace:^2.5.0",
"mongoose": "^8.9.5",
"multiformats": "^13.3.1",
Expand Down
22 changes: 4 additions & 18 deletions apps/relayer/tests/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { jest } from "@jest/globals";
import { HttpStatus, ValidationPipe, type INestApplication } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import hardhat from "hardhat";
import { genProof } from "maci-circuits";
import { deploy, deployPoll, deployVkRegistryContract, joinPoll, setVerifyingKeys, signup } from "maci-cli";
import { formatProofForVerifierContract, genMaciStateFromContract } from "maci-contracts";
import { Keypair } from "maci-domainobjs";
import { genProofSnarkjs } from "maci-sdk";
import request from "supertest";

import type { App } from "supertest/types";
Expand All @@ -22,9 +22,6 @@ import {
processMessagesZkeyPathNonQv,
tallyVotesZkeyPathNonQv,
pollWasm,
pollWitgen,
rapidsnark,
pollJoinedWitgen,
pollJoinedWasm,
} from "./constants";

Expand Down Expand Up @@ -81,8 +78,6 @@ describe("Integration messages", () => {
stateIndex: 1n,
pollJoiningZkey,
pollWasm,
pollWitgen,
rapidsnark,
signer,
useWasm: true,
quiet: true,
Expand Down Expand Up @@ -156,12 +151,9 @@ describe("Integration messages", () => {
});

test("should throw an error if dto is invalid", async () => {
const { proof } = await genProof({
const { proof } = await genProofSnarkjs({
inputs: circuitInputs,
zkeyPath: pollJoinedZkey,
useWasm: true,
rapidsnarkExePath: rapidsnark,
witnessExePath: pollJoinedWitgen,
wasmPath: pollJoinedWasm,
});

Expand Down Expand Up @@ -189,12 +181,9 @@ describe("Integration messages", () => {
});

test("should throw an error if messages dto is invalid", async () => {
const { proof } = await genProof({
const { proof } = await genProofSnarkjs({
inputs: circuitInputs,
zkeyPath: pollJoinedZkey,
useWasm: true,
rapidsnarkExePath: rapidsnark,
witnessExePath: pollJoinedWitgen,
wasmPath: pollJoinedWasm,
});

Expand All @@ -217,12 +206,9 @@ describe("Integration messages", () => {
});

test("should publish user messages properly", async () => {
const { proof } = await genProof({
const { proof } = await genProofSnarkjs({
inputs: circuitInputs,
zkeyPath: pollJoinedZkey,
useWasm: true,
rapidsnarkExePath: rapidsnark,
witnessExePath: pollJoinedWitgen,
wasmPath: pollJoinedWasm,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from "@jest/globals";
import { ZeroAddress } from "ethers";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory } from "maci-contracts";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory } from "maci-sdk";

import { IpfsService } from "../../ipfs/ipfs.service";
import { MessageBatchDto } from "../messageBatch.dto";
Expand Down
2 changes: 1 addition & 1 deletion apps/relayer/ts/messageBatch/messageBatch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable, Logger } from "@nestjs/common";
import { validate } from "class-validator";
import flatten from "lodash/flatten";
import uniqBy from "lodash/uniqBy";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory } from "maci-contracts";
import { PubKey } from "maci-domainobjs";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory } from "maci-sdk";

import type { MessageBatchDto } from "./messageBatch.dto";

Expand Down
2 changes: 1 addition & 1 deletion packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"maci-core": "^2.5.0",
"maci-crypto": "^2.5.0",
"maci-domainobjs": "^2.5.0",
"snarkjs": "^0.7.5"
"maci-sdk": "^0.0.1"
},
"devDependencies": {
"@types/chai": "^4.3.11",
Expand Down
3 changes: 1 addition & 2 deletions packages/circuits/ts/genZkeys.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { type CircomkitConfig, type CircuitConfig, Circomkit } from "circomkit";
import { cleanThreads } from "maci-sdk";

import fs from "fs";
import path from "path";

import type { CircuitConfigWithName } from "./types";

import { cleanThreads } from "./utils";

/**
* Generate the zkeys for MACI's circuits using circomkit
* @dev This should only be used for testing purposes, or to generate the genesis zkey
Expand Down
3 changes: 0 additions & 3 deletions packages/circuits/ts/index.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/circuits/ts/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { CircuitConfig } from "circomkit";
import type { CircuitInputs } from "maci-core";
import type { Groth16Proof, PublicSignals } from "snarkjs";

export type BigNumberish = number | string | bigint;

Expand All @@ -19,27 +17,6 @@ export interface ISnarkJSVerificationKey {
IC: BigNumberish[][];
}

/**
* Return type for proof generation function
*/
export interface FullProveResult {
proof: Groth16Proof;
publicSignals: PublicSignals;
}

/**
* Parameters for the genProof function
*/
export interface IGenProofOptions {
inputs: CircuitInputs;
zkeyPath: string;
useWasm?: boolean;
rapidsnarkExePath?: string;
witnessExePath?: string;
wasmPath?: string;
silent?: boolean;
}

/**
* Inputs for circuit PollJoining
*/
Expand Down
35 changes: 0 additions & 35 deletions packages/circuits/ts/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli/tests/ceremony-params/ceremonyParams.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDefaultSigner } from "maci-contracts";
import { genRandomSalt } from "maci-crypto";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import type { Signer } from "ethers";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/e2e/e2e.nonQv.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDefaultSigner } from "maci-contracts";
import { genRandomSalt } from "maci-crypto";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import type { Signer } from "ethers";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { getDefaultSigner } from "maci-contracts";
import { genRandomSalt } from "maci-crypto";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import fs from "fs";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/e2e/keyChange.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { getDefaultSigner } from "maci-contracts";
import { genRandomSalt } from "maci-crypto";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import fs from "fs";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/unit/fundWallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { ZeroAddress } from "ethers";
import { getDefaultSigner } from "maci-contracts";
import { getDefaultSigner } from "maci-sdk";

import { fundWallet } from "../../ts";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/unit/joinPoll.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { Signer } from "ethers";
import { getDefaultSigner } from "maci-contracts";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import {
deploy,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/unit/poll.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { getDefaultSigner } from "maci-contracts";
import { getDefaultSigner } from "maci-sdk";

import type { Signer } from "ethers";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/unit/publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";
import { getDefaultSigner } from "maci-contracts";
import { Poll__factory as PollFactory } from "maci-contracts/typechain-types";
import { SNARK_FIELD_SIZE } from "maci-crypto";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import type { Signer } from "ethers";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/unit/signup.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { Signer } from "ethers";
import { getDefaultSigner } from "maci-contracts";
import { Keypair } from "maci-domainobjs";
import { getDefaultSigner } from "maci-sdk";

import {
deploy,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tests/unit/timeTravel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { getDefaultSigner } from "maci-contracts";
import { getDefaultSigner } from "maci-sdk";

import { timeTravel } from "../../ts";

Expand Down
3 changes: 1 addition & 2 deletions packages/cli/ts/commands/checkVerifyingKeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EMode } from "maci-contracts";
import { extractAllVks, compareVks, getAllOnChainVks } from "maci-sdk";
import { extractAllVks, compareVks, getAllOnChainVks, EMode } from "maci-sdk";

import fs from "fs";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ts/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
deployFreeForAllSignUpGatekeeper,
deployVerifier,
deployMaci,
} from "maci-contracts";
} from "maci-sdk";

import {
banner,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/ts/commands/deployPoll.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PubKey } from "maci-domainobjs";
import {
MACI__factory as MACIFactory,
EMode,
deployFreeForAllSignUpGatekeeper,
deployConstantInitialVoiceCreditProxy,
} from "maci-contracts";
import { PubKey } from "maci-domainobjs";
} from "maci-sdk";

import {
banner,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ts/commands/deployVkRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deployVkRegistry } from "maci-contracts";
import { deployVkRegistry } from "maci-sdk";

import fs from "fs";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ts/commands/extractVkToFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractVk } from "maci-circuits";
import { extractVk } from "maci-sdk";

import fs from "fs";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ts/commands/genLocalState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonRpcProvider } from "ethers";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory, genMaciStateFromContract } from "maci-contracts";
import { Keypair, PrivKey } from "maci-domainobjs";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory, genMaciStateFromContract } from "maci-sdk";

import fs from "fs";

Expand Down
Loading

0 comments on commit 66dfab7

Please sign in to comment.