From 56c044a1ac8a754f86d4235b44c6584d13ca90b0 Mon Sep 17 00:00:00 2001 From: mllwchrry Date: Mon, 4 Nov 2024 17:11:30 +0200 Subject: [PATCH 1/5] updated latest supported Circom version to 2.2.0 --- src/constants.ts | 3 +- .../parser/CircomTemplateInputsVisitor.ts | 5 ++++ test/integration/tasks.test.ts | 28 +++++++++++-------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 1b4e17f..b374813 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -29,10 +29,11 @@ export const COMPILER_AMD_REPOSITORY_URL = "https://github.com/iden3/circom/rele export const COMPILER_ARM_REPOSITORY_URL = "https://github.com/distributed-lab/circom/releases/download"; export const COMPILER_WASM_REPOSITORY_URL = "https://github.com/distributed-lab/circom-wasm/releases/download"; -export const LATEST_SUPPORTED_CIRCOM_VERSION = "2.1.9"; +export const LATEST_SUPPORTED_CIRCOM_VERSION = "2.2.0"; export const OLDEST_SUPPORTED_CIRCOM_VERSION = "2.0.5"; export const WASM_COMPILER_VERSIONING: { [key: string]: string } = { "2.1.8": "0.2.18-rc.3", "2.1.9": "0.2.19-rc.0", + "2.2.0": "0.2.20-rc.0", }; diff --git a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts index eed0b7f..b1ebbce 100644 --- a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts +++ b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts @@ -1,4 +1,5 @@ import { + BusDeclarationContext, CircomValueType, CircomVisitor, ExpressionContext, @@ -143,6 +144,10 @@ export class CircomTemplateInputsVisitor extends CircomVisitor { throw new Error("INTERNAL ERROR: SignalIdentifier should have a SignalDeclarationContext as a parent of parent"); } + if (ctx.parentCtx!.parentCtx instanceof BusDeclarationContext) { + return; + } + const signalDeclarationContext = ctx.parentCtx!.parentCtx as SignalDeclarationContext; let signalType = "intermediate"; diff --git a/test/integration/tasks.test.ts b/test/integration/tasks.test.ts index 50b1bb2..c7cf40b 100644 --- a/test/integration/tasks.test.ts +++ b/test/integration/tasks.test.ts @@ -8,6 +8,8 @@ import { expect } from "chai"; import { before } from "mocha"; import { stub, SinonStub } from "sinon"; +import * as snarkjs from "snarkjs"; + import { HardhatUserConfig } from "hardhat/config"; import { @@ -25,7 +27,6 @@ import { cleanUp, useEnvironment } from "@test-helpers"; import { getNormalizedFullPath } from "@src/utils/path-utils"; import { getCompileCacheEntry, getSetupCacheEntry } from "../utils"; -import { HardhatZKit } from "@src/types/hardhat-zkit"; import { BaseCircomCompilerFactory } from "@src/core"; import { CircomCompilerDownloader } from "@src/core/compiler/CircomCompilerDownloader"; @@ -58,7 +59,7 @@ describe("ZKit tasks", async function () { return circuitFullPaths; } - async function checkMake(config: HardhatUserConfig, zkit: HardhatZKit) { + async function checkMake(config: HardhatUserConfig) { const cacheFullPath: string = getNormalizedFullPath(config.paths!.root!, "cache"); expect(fsExtra.readdirSync(cacheFullPath)).to.be.deep.eq([ @@ -70,7 +71,9 @@ describe("ZKit tasks", async function () { expect(entry).to.be.deep.eq(await getSetupCacheEntry(entry.circuitSourceName, entry.r1csSourcePath)); }); - getZkitCircuitFullPaths(config).forEach((path, index) => { + const circuitFullPaths = getZkitCircuitFullPaths(config); + + circuitFullPaths.forEach((path, index) => { expect(fsExtra.readdirSync(path)).to.be.deep.eq([ `${circuitNames[index]}.r1cs`, `${circuitNames[index]}.sym`, @@ -84,12 +87,15 @@ describe("ZKit tasks", async function () { const ptauFullPath: string = getNormalizedFullPath(config.paths!.root!, "zkit/ptau"); expect(fsExtra.readdirSync(ptauFullPath)).to.be.deep.eq(["powers-of-tau-8.ptau"]); - const circuit = await zkit.getCircuit("Multiplier2"); - await expect(circuit).with.witnessInputs({ in1: "3", in2: "7" }).to.have.witnessOutputs(["21"]); + const proof = await snarkjs.groth16.fullProve( + { in: ["3", "7", "2"] }, + `${circuitFullPaths[1]}/Multiplier3Arr_js/Multiplier3Arr.wasm`, + `${circuitFullPaths[1]}/Multiplier3Arr.zkey`, + ); - const proof = await circuit.generateProof({ in1: "4", in2: "2" }); + const verifier = JSON.parse(fsExtra.readFileSync(`${circuitFullPaths[1]}/Multiplier3Arr.vkey.json`).toString()); - await expect(circuit).to.verifyProof(proof); + expect(await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof)).to.be.true; } function updateInclude(filePath: string, newIncludePath: string) { @@ -342,7 +348,7 @@ describe("ZKit tasks", async function () { await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_CIRCUITS_COMPILE }); await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_CIRCUITS_SETUP }); - await checkMake(this.hre.config, this.hre.zkit); + await checkMake(this.hre.config); }); }); @@ -352,7 +358,7 @@ describe("ZKit tasks", async function () { it("should correctly compile circuits and generate vkey, zkey files", async function () { await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_CIRCUITS_MAKE }); - await checkMake(this.hre.config, this.hre.zkit); + await checkMake(this.hre.config); }); }); @@ -362,7 +368,7 @@ describe("ZKit tasks", async function () { it("should correctly generate verifiers after running the verifiers task", async function () { await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_GENERATE_VERIFIERS }); - await checkMake(this.hre.config, this.hre.zkit); + await checkMake(this.hre.config); const verifiersFullPath: string = getNormalizedFullPath(this.hre.config.paths.root, "contracts/verifiers"); expect(fsExtra.readdirSync(verifiersFullPath)).to.be.deep.eq(circuitNames.map((name) => `${name}Verifier.sol`)); @@ -392,7 +398,7 @@ describe("ZKit tasks", async function () { const cacheDir: string = getNormalizedFullPath(this.hre.config.paths.root, "cache"); const zkitDir: string = getNormalizedFullPath(this.hre.config.paths.root, "zkit"); - await checkMake(this.hre.config, this.hre.zkit); + await checkMake(this.hre.config); await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_ZKIT_CLEAN }); From 8687f02a084a14c48e1580f47ad468de5779cdea Mon Sep 17 00:00:00 2001 From: mllwchrry Date: Mon, 4 Nov 2024 18:22:28 +0200 Subject: [PATCH 2/5] fixed unsupported versions test --- test/unit/core/compile/circom-compiler-factory.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/core/compile/circom-compiler-factory.test.ts b/test/unit/core/compile/circom-compiler-factory.test.ts index 7fedc0c..627c623 100644 --- a/test/unit/core/compile/circom-compiler-factory.test.ts +++ b/test/unit/core/compile/circom-compiler-factory.test.ts @@ -97,12 +97,12 @@ describe("CircomCompilerFactory", () => { it("should correctly throw error if pass invalid version", async function () { let invalidVersion = "2.1.10"; - let reason = `Unsupported Circom compiler version - ${invalidVersion}. Please provide another version.`; + let reason = `Unsupported WASM version - ${invalidVersion}`; createCircomCompilerFactory(); await expect(CircomCompilerFactory!.createCircomCompiler(invalidVersion, true)).to.be.rejectedWith(reason); - invalidVersion = "2.2.0"; + invalidVersion = "2.2.1"; reason = `Unsupported Circom compiler version - ${invalidVersion}. Please provide another version.`; await expect(CircomCompilerFactory!.createCircomCompiler(invalidVersion, false)).to.be.rejectedWith(reason); From 7c03f7cd626a6b67b3b5a290c7cf1d22fa5e9e8e Mon Sep 17 00:00:00 2001 From: mllwchrry Date: Mon, 4 Nov 2024 19:49:37 +0200 Subject: [PATCH 3/5] fixed platform-specific test --- test/unit/core/compile/circom-compiler-factory.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/core/compile/circom-compiler-factory.test.ts b/test/unit/core/compile/circom-compiler-factory.test.ts index 627c623..f192c25 100644 --- a/test/unit/core/compile/circom-compiler-factory.test.ts +++ b/test/unit/core/compile/circom-compiler-factory.test.ts @@ -38,7 +38,7 @@ describe("CircomCompilerFactory", () => { }); async function checkPlatformSpecificCompiler(osType: NodeJS.Platform) { - const compilerDir = path.join(os.homedir(), ".zkit", "compilers", LATEST_SUPPORTED_CIRCOM_VERSION); + const compilerDir = path.join(os.homedir(), ".zkit", "compilers"); fsExtra.rmSync(compilerDir, { recursive: true, force: true }); const platformStub = stub(os, "platform").callsFake(() => { @@ -55,7 +55,7 @@ describe("CircomCompilerFactory", () => { expect(compiler).to.be.instanceof(BinaryCircomCompiler); } - expect(fsExtra.readdirSync(compilerDir)).to.be.deep.equal([platform]); + expect(fsExtra.readdirSync(path.join(compilerDir, LATEST_SUPPORTED_CIRCOM_VERSION))).to.be.deep.equal([platform]); fsExtra.rmSync(compilerDir, { recursive: true, force: true }); platformStub.restore(); From e4566801243355914800baa4d286af9efa6ea221 Mon Sep 17 00:00:00 2001 From: mllwchrry Date: Tue, 5 Nov 2024 15:35:23 +0200 Subject: [PATCH 4/5] restricted bus usage --- src/core/dependencies/parser/CircomTemplateInputsVisitor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts index b1ebbce..410a038 100644 --- a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts +++ b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts @@ -145,7 +145,7 @@ export class CircomTemplateInputsVisitor extends CircomVisitor { } if (ctx.parentCtx!.parentCtx instanceof BusDeclarationContext) { - return; + throw new Error("INTERNAL ERROR: Buses are not supported"); } const signalDeclarationContext = ctx.parentCtx!.parentCtx as SignalDeclarationContext; From a39096475dcdbeb4b1ae196f059337d1c0a1bb00 Mon Sep 17 00:00:00 2001 From: mllwchrry Date: Tue, 5 Nov 2024 16:18:27 +0200 Subject: [PATCH 5/5] fixed error message --- src/core/dependencies/parser/CircomTemplateInputsVisitor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts index 410a038..2640a19 100644 --- a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts +++ b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts @@ -145,7 +145,7 @@ export class CircomTemplateInputsVisitor extends CircomVisitor { } if (ctx.parentCtx!.parentCtx instanceof BusDeclarationContext) { - throw new Error("INTERNAL ERROR: Buses are not supported"); + throw new Error("Buses are not supported"); } const signalDeclarationContext = ctx.parentCtx!.parentCtx as SignalDeclarationContext;