Skip to content

Commit

Permalink
Added logic to ignore unsupported contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Oct 22, 2024
1 parent 9c0f597 commit 8e16a9c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/dependencies/parser/CircomTemplateInputsVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -134,6 +137,15 @@ export class CircomTemplateInputsVisitor extends CircomVisitor<void> {
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)) {
Expand Down
7 changes: 7 additions & 0 deletions src/reporter/ReporterFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
VerifiersGenerationReporter,
VKeyFilesGenerationReporter,
ZKeyFilesGenerationReporter,
WarningsReporter,
} from "./reporters";

import { createProgressBarProcessor } from "./ProgressBarProcessor";
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions src/reporter/reporters/WarningsReporter.ts
Original file line number Diff line number Diff line change
@@ -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!`,
);
}
}
1 change: 1 addition & 0 deletions src/reporter/reporters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 8e16a9c

Please sign in to comment.