From 8e16a9c3b5513d9993d8da579ad19f3de498b864 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 13:22:51 +0300 Subject: [PATCH 01/11] Added logic to ignore unsupported contexts --- .../parser/CircomTemplateInputsVisitor.ts | 12 ++++++++++++ src/reporter/ReporterFacade.ts | 7 +++++++ src/reporter/reporters/WarningsReporter.ts | 11 +++++++++++ src/reporter/reporters/index.ts | 1 + 4 files changed, 31 insertions(+) create mode 100644 src/reporter/reporters/WarningsReporter.ts diff --git a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts index f4c824c..782bdce 100644 --- a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts +++ b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts @@ -10,10 +10,13 @@ import { VarDefinitionContext, RhsValueContext, TemplateStmtContext, + BlockInstantiationExpressionContext, + DotExpressionContext, } from "@distributedlab/circom-parser"; import { InputData } from "../../../types/core"; import { HardhatZKitError } from "../../../errors"; +import { Reporter } from "../../../reporter"; /** * Visitor class for the {@link https://www.npmjs.com/package/@distributedlab/circom-parser | @distributedlab/circom-parser} package. @@ -134,6 +137,15 @@ export class CircomTemplateInputsVisitor extends CircomVisitor { const expressionVisitor = new CircomExpressionVisitor(true, this.vars); if (ctx.expression()) { + if ( + ctx.expression() instanceof BlockInstantiationExpressionContext || + ctx.expression() instanceof DotExpressionContext + ) { + Reporter?.reportUnsupportedExpression(ctx.expression().getText()); + + return [0n]; + } + const expressionResult = expressionVisitor.visitExpression(ctx.expression()); if (Array.isArray(expressionResult)) { diff --git a/src/reporter/ReporterFacade.ts b/src/reporter/ReporterFacade.ts index 4575f0a..79b7eea 100644 --- a/src/reporter/ReporterFacade.ts +++ b/src/reporter/ReporterFacade.ts @@ -15,6 +15,7 @@ import { VerifiersGenerationReporter, VKeyFilesGenerationReporter, ZKeyFilesGenerationReporter, + WarningsReporter, } from "./reporters"; import { createProgressBarProcessor } from "./ProgressBarProcessor"; @@ -31,6 +32,7 @@ class ReporterFacade { private _setupReporter!: SetupReporter; private _progressReporter!: ProgressReporter; private _ptauFileReporter!: PtauFileReporter; + private _warningsReporter!: WarningsReporter; private _circomCompilerReporter!: CircomCompilerReporter; private _circuitCompilationReporter!: CircuitCompilationReporter; private _verifiersGenerationReporter!: VerifiersGenerationReporter; @@ -55,6 +57,7 @@ class ReporterFacade { this._vKeyFilesGenerationReporter = new VKeyFilesGenerationReporter(quiet); this._zKeyFilesGenerationReporter = new ZKeyFilesGenerationReporter(quiet); this._circuitFilesResolvingReporter = new CircuitFilesResolvingReporter(quiet); + this._warningsReporter = new WarningsReporter(quiet); } public setQuiet(newValue: boolean) { @@ -219,6 +222,10 @@ class ReporterFacade { this._progressReporter.updateProgressBarValue(valueToAdd); } + public reportUnsupportedExpression(contextText: string) { + this._warningsReporter.reportUnsupportedExpression(contextText); + } + public verboseLog(namespace: string, formatterStr: string, logArgs: any[] = []) { debug(`hardhat-zkit:${namespace}`)(formatterStr, ...logArgs); } diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts new file mode 100644 index 0000000..10cc82d --- /dev/null +++ b/src/reporter/reporters/WarningsReporter.ts @@ -0,0 +1,11 @@ +import { BaseReporter } from "@src/reporter/reporters/BaseReporter"; + +export class WarningsReporter extends BaseReporter { + public reportUnsupportedExpression(contextText: string) { + if (this.isQuiet()) return; + + console.warn( + `Expression structure: ${contextText} not supported if the expression is used to determine the dimension of input signal!`, + ); + } +} diff --git a/src/reporter/reporters/index.ts b/src/reporter/reporters/index.ts index 97c1d1d..49e25db 100644 --- a/src/reporter/reporters/index.ts +++ b/src/reporter/reporters/index.ts @@ -2,6 +2,7 @@ export * from "./BaseReporter"; export * from "./SetupReporter"; export * from "./ProgressReporter"; export * from "./PtauFileReporter"; +export * from "./WarningsReporter"; export * from "./CircomCompilerReporter"; export * from "./CircuitCompilationReporter"; export * from "./CircuitFilesResolvingReporter"; From 36e559da01097c4d9b5f7141b21ef225b9fdcf41 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 13:49:31 +0300 Subject: [PATCH 02/11] Fixed typo --- src/reporter/reporters/WarningsReporter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index 10cc82d..ce054d4 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -1,11 +1,11 @@ -import { BaseReporter } from "@src/reporter/reporters/BaseReporter"; +import { BaseReporter } from "../../reporter/reporters/BaseReporter"; export class WarningsReporter extends BaseReporter { public reportUnsupportedExpression(contextText: string) { if (this.isQuiet()) return; console.warn( - `Expression structure: ${contextText} not supported if the expression is used to determine the dimension of input signal!`, + `Expression structure: ${contextText} not supported if used to determine the dimension of an input signal!`, ); } } From 9db402b3b6910010a9c191e9a7ef92ebf04255f0 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 15:20:14 +0300 Subject: [PATCH 03/11] Improved message structure --- src/core/compile/CompilationFilesResolver.ts | 1 + .../parser/CircomTemplateInputsVisitor.ts | 2 +- src/reporter/ReporterFacade.ts | 12 ++++-- src/reporter/SpinnerProcessor.ts | 10 +++++ src/reporter/reporters/WarningsReporter.ts | 39 +++++++++++++++++-- .../parser/circom-files-visitor.ts | 17 ++++++++ 6 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/core/compile/CompilationFilesResolver.ts b/src/core/compile/CompilationFilesResolver.ts index 2299d13..6428949 100644 --- a/src/core/compile/CompilationFilesResolver.ts +++ b/src/core/compile/CompilationFilesResolver.ts @@ -117,6 +117,7 @@ export class CompilationFilesResolver { filteredResolvedFilesInfo = resolvedFilesInfoToCompile; } + Reporter!.reportAllWarnings(spinnerId); Reporter!.reportCircuitFilesResolvingResult(spinnerId); const filteredSourceNamesToCompile: string[] = filteredResolvedFilesInfo.map( diff --git a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts index 782bdce..c86e5f2 100644 --- a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts +++ b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts @@ -141,7 +141,7 @@ export class CircomTemplateInputsVisitor extends CircomVisitor { ctx.expression() instanceof BlockInstantiationExpressionContext || ctx.expression() instanceof DotExpressionContext ) { - Reporter?.reportUnsupportedExpression(ctx.expression().getText()); + Reporter?.reportUnsupportedExpression(this._templateName, ctx.expression()); return [0n]; } diff --git a/src/reporter/ReporterFacade.ts b/src/reporter/ReporterFacade.ts index 79b7eea..60011c1 100644 --- a/src/reporter/ReporterFacade.ts +++ b/src/reporter/ReporterFacade.ts @@ -4,7 +4,7 @@ import debug from "debug"; import { VerifierLanguageType } from "@solarity/zkit"; import { CircuitArtifact } from "../types/artifacts/circuit-artifacts"; -import { CompilationInfo, CircuitSetupInfo } from "../types/core"; +import { CompilationInfo, CircuitSetupInfo, SimpleParserRuleContext } from "../types/core"; import { ProgressReporter, CircuitFilesResolvingReporter, @@ -222,8 +222,14 @@ class ReporterFacade { this._progressReporter.updateProgressBarValue(valueToAdd); } - public reportUnsupportedExpression(contextText: string) { - this._warningsReporter.reportUnsupportedExpression(contextText); + public reportUnsupportedExpression(templateName: string, context: SimpleParserRuleContext) { + this._warningsReporter.reportUnsupportedExpression(templateName, context); + } + + public reportAllWarnings(spinnerId: string | null) { + if (!this._warningsReporter.hasWarnings()) return; + + this._warningsReporter.reportAllWarnings(spinnerId); } public verboseLog(namespace: string, formatterStr: string, logArgs: any[] = []) { diff --git a/src/reporter/SpinnerProcessor.ts b/src/reporter/SpinnerProcessor.ts index 0357c21..90ea619 100644 --- a/src/reporter/SpinnerProcessor.ts +++ b/src/reporter/SpinnerProcessor.ts @@ -31,6 +31,16 @@ export class BaseSpinnerProcessor { this._idToSpinnerData.delete(spinnerId); } + public warnSpinner(spinnerId: string, warningMessage: string) { + const spinnerData = this._idToSpinnerData.get(spinnerId); + + if (!spinnerData) return; + + spinnerData.spinner.warn(warningMessage); + + this._idToSpinnerData.delete(spinnerId); + } + public getWorkingTime(spinnerId: string, fractionDigits: number = 2): string | undefined { const spinnerData = this._idToSpinnerData.get(spinnerId); diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index ce054d4..e926993 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -1,11 +1,44 @@ +import { SimpleParserRuleContext } from "../../types/core"; + +import { SpinnerProcessor } from "../../reporter"; import { BaseReporter } from "../../reporter/reporters/BaseReporter"; export class WarningsReporter extends BaseReporter { - public reportUnsupportedExpression(contextText: string) { + public warnings: Set = new Set(); + + constructor(quiet: boolean) { + super(quiet); + + this.warnings = new Set(); + } + + public reportUnsupportedExpression(templateName: string, context: SimpleParserRuleContext) { if (this.isQuiet()) return; - console.warn( - `Expression structure: ${contextText} not supported if used to determine the dimension of an input signal!`, + this.warnings.add( + `Inside the ${templateName} circuit (${context.start.line}:${context.start.column})\r + \rThe expression structure: ${context.getText()} not supported if used to determine the dimension of an input signal!`, + ); + } + + public reportAllWarnings(spinnerId: string | null) { + if (this.isQuiet() || !spinnerId) return; + + const resolvingTimeMessage: string = this._getSpinnerWorkingTimeMessage( + SpinnerProcessor!.getWorkingTime(spinnerId), + ); + + SpinnerProcessor!.warnSpinner( + spinnerId, + `Circuits are ready for the compilation ${resolvingTimeMessage}. But the analysis ended with warnings:`, ); + + for (const warning of this.warnings) { + console.warn(warning); + } + } + + public hasWarnings(): boolean { + return this.warnings.size > 0; } } diff --git a/src/types/core/dependencies/parser/circom-files-visitor.ts b/src/types/core/dependencies/parser/circom-files-visitor.ts index 10ed457..43bec4d 100644 --- a/src/types/core/dependencies/parser/circom-files-visitor.ts +++ b/src/types/core/dependencies/parser/circom-files-visitor.ts @@ -21,3 +21,20 @@ export type CircomFileData = { mainComponentInfo: MainComponent; templates: Templates; }; + +export interface Token { + tokenIndex: number; + line: number; + column: number; + channel: number; + text: string; + type: number; + start: number; + stop: number; +} + +export interface SimpleParserRuleContext { + start: Token; + + getText(): string; +} From 678b50cb10ba9d2c26a622c4e04754e3795f119a Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 15:24:28 +0300 Subject: [PATCH 04/11] Fixed typo --- src/reporter/reporters/WarningsReporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index e926993..586b9df 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -16,7 +16,7 @@ export class WarningsReporter extends BaseReporter { if (this.isQuiet()) return; this.warnings.add( - `Inside the ${templateName} circuit (${context.start.line}:${context.start.column})\r + `Inside the ${templateName} circuit (${context.start.line}:${context.start.column}) \rThe expression structure: ${context.getText()} not supported if used to determine the dimension of an input signal!`, ); } From 29bf387d5dc3d8290672f55bfffdb5199c473309 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 15:29:25 +0300 Subject: [PATCH 05/11] Fixed typo --- src/reporter/reporters/WarningsReporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index 586b9df..ad316db 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -17,7 +17,7 @@ export class WarningsReporter extends BaseReporter { this.warnings.add( `Inside the ${templateName} circuit (${context.start.line}:${context.start.column}) - \rThe expression structure: ${context.getText()} not supported if used to determine the dimension of an input signal!`, + \rExpression structure: ${context.getText()} is not supported if used to determine the dimension of an input signal!`, ); } From 56f65d6650fad74f80df03a864b7965a152a8212 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 15:32:44 +0300 Subject: [PATCH 06/11] Simplified logic --- src/reporter/ReporterFacade.ts | 2 -- src/reporter/reporters/WarningsReporter.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/reporter/ReporterFacade.ts b/src/reporter/ReporterFacade.ts index 60011c1..310f11e 100644 --- a/src/reporter/ReporterFacade.ts +++ b/src/reporter/ReporterFacade.ts @@ -227,8 +227,6 @@ class ReporterFacade { } public reportAllWarnings(spinnerId: string | null) { - if (!this._warningsReporter.hasWarnings()) return; - this._warningsReporter.reportAllWarnings(spinnerId); } diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index ad316db..52c7d31 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -22,7 +22,7 @@ export class WarningsReporter extends BaseReporter { } public reportAllWarnings(spinnerId: string | null) { - if (this.isQuiet() || !spinnerId) return; + if (this.isQuiet() || !spinnerId || !this.hasWarnings()) return; const resolvingTimeMessage: string = this._getSpinnerWorkingTimeMessage( SpinnerProcessor!.getWorkingTime(spinnerId), From d29e49e1650bfec0157ab81882f6a35cb51d9334 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 16:24:11 +0300 Subject: [PATCH 07/11] Added comment --- .../dependencies/parser/CircomTemplateInputsVisitor.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts index c86e5f2..c6957e2 100644 --- a/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts +++ b/src/core/dependencies/parser/CircomTemplateInputsVisitor.ts @@ -136,6 +136,14 @@ export class CircomTemplateInputsVisitor extends CircomVisitor { _parseRHSValue = (ctx: RhsValueContext): bigint[] => { const expressionVisitor = new CircomExpressionVisitor(true, this.vars); + /** + * Due to the filtering below following expressions are skipped during the input signals resolution: + * + * ```circom + * var var1 = functionCall(); + * var var2 = component.out; + * ``` + */ if (ctx.expression()) { if ( ctx.expression() instanceof BlockInstantiationExpressionContext || From 2c63a6e5179b76f15b1ddac1e209ecba9491b31a Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 16:38:38 +0300 Subject: [PATCH 08/11] Resolved imports --- src/reporter/reporters/WarningsReporter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index 52c7d31..be439c5 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -1,8 +1,8 @@ -import { SimpleParserRuleContext } from "../../types/core"; - import { SpinnerProcessor } from "../../reporter"; import { BaseReporter } from "../../reporter/reporters/BaseReporter"; +import { SimpleParserRuleContext } from "../../types/core"; + export class WarningsReporter extends BaseReporter { public warnings: Set = new Set(); From f6b66c6a1fe4fe00669316ef301270e57289d535 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 16:38:57 +0300 Subject: [PATCH 09/11] Updated versions --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b746a04..121ca36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@solarity/hardhat-zkit", - "version": "0.4.8", + "version": "0.4.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@solarity/hardhat-zkit", - "version": "0.4.8", + "version": "0.4.9", "license": "MIT", "workspaces": [ "test/fixture-projects/*" diff --git a/package.json b/package.json index cfdaebb..e4fc8cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-zkit", - "version": "0.4.8", + "version": "0.4.9", "description": "The ultimate TypeScript environment for Circom development", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", From ce07e409902ce29a45d337fa3772b03e8e74fcfa Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 16:40:09 +0300 Subject: [PATCH 10/11] Fixed typos --- src/reporter/reporters/WarningsReporter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index be439c5..f83f8fb 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -16,8 +16,8 @@ export class WarningsReporter extends BaseReporter { if (this.isQuiet()) return; this.warnings.add( - `Inside the ${templateName} circuit (${context.start.line}:${context.start.column}) - \rExpression structure: ${context.getText()} is not supported if used to determine the dimension of an input signal!`, + `\nInside the ${templateName} circuit (${context.start.line}:${context.start.column}) + \rExpression structure: "${context.getText()}" is not supported if used to determine the dimension of an input signal!`, ); } @@ -30,7 +30,7 @@ export class WarningsReporter extends BaseReporter { SpinnerProcessor!.warnSpinner( spinnerId, - `Circuits are ready for the compilation ${resolvingTimeMessage}. But the analysis ended with warnings:`, + `Circuits are ready for the compilation ${resolvingTimeMessage}, however, the analysis ended with warnings:`, ); for (const warning of this.warnings) { From 9423c89909ea88c67d33c88baa835915d5fb7e7d Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Tue, 22 Oct 2024 16:41:02 +0300 Subject: [PATCH 11/11] Deleted colon --- src/reporter/reporters/WarningsReporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter/reporters/WarningsReporter.ts b/src/reporter/reporters/WarningsReporter.ts index f83f8fb..49698ae 100644 --- a/src/reporter/reporters/WarningsReporter.ts +++ b/src/reporter/reporters/WarningsReporter.ts @@ -17,7 +17,7 @@ export class WarningsReporter extends BaseReporter { this.warnings.add( `\nInside the ${templateName} circuit (${context.start.line}:${context.start.column}) - \rExpression structure: "${context.getText()}" is not supported if used to determine the dimension of an input signal!`, + \rExpression structure "${context.getText()}" is not supported if used to determine the dimension of an input signal!`, ); }