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

Add logic to ignore unsupported contexts #44

Merged
merged 11 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/core/compile/CompilationFilesResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class CompilationFilesResolver {
filteredResolvedFilesInfo = resolvedFilesInfoToCompile;
}

Reporter!.reportAllWarnings(spinnerId);
Reporter!.reportCircuitFilesResolvingResult(spinnerId);

const filteredSourceNamesToCompile: string[] = filteredResolvedFilesInfo.map(
Expand Down
20 changes: 20 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 @@ -133,7 +136,24 @@ export class CircomTemplateInputsVisitor extends CircomVisitor<void> {
_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 ||
ctx.expression() instanceof DotExpressionContext
) {
Reporter?.reportUnsupportedExpression(this._templateName, ctx.expression());

return [0n];
}

const expressionResult = expressionVisitor.visitExpression(ctx.expression());

if (Array.isArray(expressionResult)) {
Expand Down
13 changes: 12 additions & 1 deletion src/reporter/ReporterFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,14 @@ class ReporterFacade {
this._progressReporter.updateProgressBarValue(valueToAdd);
}

public reportUnsupportedExpression(templateName: string, context: SimpleParserRuleContext) {
this._warningsReporter.reportUnsupportedExpression(templateName, context);
}

public reportAllWarnings(spinnerId: string | null) {
this._warningsReporter.reportAllWarnings(spinnerId);
}

public verboseLog(namespace: string, formatterStr: string, logArgs: any[] = []) {
debug(`hardhat-zkit:${namespace}`)(formatterStr, ...logArgs);
}
Expand Down
10 changes: 10 additions & 0 deletions src/reporter/SpinnerProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
44 changes: 44 additions & 0 deletions src/reporter/reporters/WarningsReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { SpinnerProcessor } from "../../reporter";
import { BaseReporter } from "../../reporter/reporters/BaseReporter";

import { SimpleParserRuleContext } from "../../types/core";

export class WarningsReporter extends BaseReporter {
public warnings: Set<string> = new Set();

constructor(quiet: boolean) {
super(quiet);

this.warnings = new Set();
}

public reportUnsupportedExpression(templateName: string, context: SimpleParserRuleContext) {
if (this.isQuiet()) return;

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!`,
);
}

public reportAllWarnings(spinnerId: string | null) {
if (this.isQuiet() || !spinnerId || !this.hasWarnings()) return;

const resolvingTimeMessage: string = this._getSpinnerWorkingTimeMessage(
SpinnerProcessor!.getWorkingTime(spinnerId),
);

SpinnerProcessor!.warnSpinner(
spinnerId,
`Circuits are ready for the compilation ${resolvingTimeMessage}, however, the analysis ended with warnings:`,
);

for (const warning of this.warnings) {
console.warn(warning);
}
}

public hasWarnings(): boolean {
return this.warnings.size > 0;
}
}
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
17 changes: 17 additions & 0 deletions src/types/core/dependencies/parser/circom-files-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading