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

Feature/plonk #47

Merged
merged 17 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
setupSettings: {
contributionSettings: {
provingSystem: "groth16",
contributions: 1,
contributions: 2,
},
onlyFiles: [],
skipFiles: [],
Expand Down
10 changes: 6 additions & 4 deletions src/core/zkit/CircuitZKitBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ export class CircuitZKitBuilder implements ICircuitZKitBuilder {
if (this._isTSProject) {
if (circuitArtifact.baseCircuitInfo.protocol.length > 1 && !provingSystem) {
Arvolear marked this conversation as resolved.
Show resolved Hide resolved
throw new HardhatZKitError(
"Found several proving systems. Please specify the exact proving system in getCircuit function",
"Found several proving systems. Please specify the exact proving system in the getCircuit function.",
);
} else if (circuitArtifact.baseCircuitInfo.protocol.length === 1) {
}

if (circuitArtifact.baseCircuitInfo.protocol.length === 1) {
const existingProvingSystem: ProvingSystemType = circuitArtifact.baseCircuitInfo.protocol[0];

if (provingSystem && provingSystem !== existingProvingSystem) {
throw new HardhatZKitError(
`Passed invalid proving system. Please pass ${existingProvingSystem} proving system or run make task with needed proving systems`,
`Invalid proving system is passed. Please pass ${existingProvingSystem} proving system or recompile the circuits with the needed one.`,
);
}

Expand All @@ -64,7 +66,7 @@ export class CircuitZKitBuilder implements ICircuitZKitBuilder {
} else {
if (!provingSystem || !circuitArtifact.baseCircuitInfo.protocol.includes(provingSystem)) {
throw new HardhatZKitError(
"Passed undefined or invalid proving system. Please run make task or change proving system.",
"Undefined or invalid proving system is passed. Please recompile the circuits or change the proving system.",
);
}

Expand Down
30 changes: 27 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "path";
import fs from "fs";

import { lazyObject } from "hardhat/plugins";
import { extendConfig, extendEnvironment, scope, task, types } from "hardhat/config";
import { extendConfig, extendEnvironment, scope, subtask, task, types } from "hardhat/config";
import { ActionType, HardhatRuntimeEnvironment, RunSuperFunction } from "hardhat/types";
import { TASK_CLEAN, TASK_COMPILE_SOLIDITY_READ_FILE as TASK_READ_FILE } from "hardhat/builtin-tasks/task-names";

Expand All @@ -18,6 +18,7 @@ import {
TASK_CIRCUITS_SETUP,
TASK_GENERATE_VERIFIERS,
TASK_ZKIT_CLEAN,
SUBTASK_ZKIT_GET_CIRCUIT_ZKIT,
} from "./task-names";

import { zkitConfigExtender } from "./config/config";
Expand All @@ -44,7 +45,13 @@ import { CircuitArtifacts } from "./artifacts/CircuitArtifacts";
import { CIRCUITS_COMPILE_CACHE_FILENAME, CIRCUITS_SETUP_CACHE_FILENAME } from "./constants";
import { getNormalizedFullPath, getUniqueProvingSystems } from "./utils";

import { MakeTaskConfig, CompileTaskConfig, GenerateVerifiersTaskConfig, SetupTaskConfig } from "./types/tasks";
import {
MakeTaskConfig,
CompileTaskConfig,
GenerateVerifiersTaskConfig,
SetupTaskConfig,
GetCircuitZKitConfig,
} from "./types/tasks";
import { CircuitArtifact } from "./types/artifacts/circuit-artifacts";
import { CompileFlags, CircomResolvedFileInfo, CircuitSetupInfo, SetupContributionSettings } from "./types/core";
import { ProvingSystemData } from "./types/cache";
Expand All @@ -67,7 +74,7 @@ extendEnvironment((hre) => {
circuitName: string,
provingSystem?: ProvingSystemType,
): Promise<CircuitZKit<ProvingSystemType>> => {
return circuitZKitBuilder.getCircuitZKit(circuitName, provingSystem);
return hre.run(SUBTASK_ZKIT_GET_CIRCUIT_ZKIT, { circuitName, provingSystem });
},
};
});
Expand Down Expand Up @@ -317,6 +324,17 @@ const clean: ActionType<any> = async (_taskArgs: any, env: HardhatRuntimeEnviron
fs.rmSync(circuitTypesFullPath, { recursive: true, force: true });
};

const getCircuitZKit: ActionType<GetCircuitZKitConfig> = async (
taskArgs: GetCircuitZKitConfig,
env: HardhatRuntimeEnvironment,
): Promise<CircuitZKit<ProvingSystemType>> => {
return env.zkit.circuitZKitBuilder.getCircuitZKit(
taskArgs.circuitName,
taskArgs.provingSystem,
taskArgs.verifiersDir,
);
};

task(TASK_CLEAN).setAction(async (_taskArgs: any, env: HardhatRuntimeEnvironment, runSuper: RunSuperFunction<any>) => {
await runSuper();

Expand Down Expand Up @@ -370,3 +388,9 @@ zkitScope
.setAction(generateVerifiers);

zkitScope.task(TASK_ZKIT_CLEAN, "Clean all circuit artifacts, keys, types and etc").setAction(clean);

subtask(SUBTASK_ZKIT_GET_CIRCUIT_ZKIT)
.addOptionalParam("verifiersDir", undefined, undefined, types.string)
.addOptionalParam("verifierTemplateType", undefined, undefined, types.any)
.addParam("circuitName", undefined, undefined, types.string)
Arvolear marked this conversation as resolved.
Show resolved Hide resolved
.setAction(getCircuitZKit);
2 changes: 2 additions & 0 deletions src/task-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export const TASK_CIRCUITS_COMPILE = "compile";
export const TASK_CIRCUITS_SETUP = "setup";
export const TASK_GENERATE_VERIFIERS = "verifiers";
export const TASK_ZKIT_CLEAN = "clean";

export const SUBTASK_ZKIT_GET_CIRCUIT_ZKIT = "zkit:get-circuit-zkit";
8 changes: 7 additions & 1 deletion src/types/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VerifierLanguageType } from "@solarity/zkit";
import { ProvingSystemType, VerifierLanguageType } from "@solarity/zkit";

export type MakeTaskConfig = {
force: boolean;
Expand Down Expand Up @@ -27,3 +27,9 @@ export type GenerateVerifiersTaskConfig = {
quiet: boolean;
force: boolean;
};

export type GetCircuitZKitConfig = {
circuitName: string;
verifiersDir?: string;
provingSystem?: ProvingSystemType;
};
Loading