diff --git a/apps/circuit-compiler/src/app/components/configurations.tsx b/apps/circuit-compiler/src/app/components/configurations.tsx index a9583c093a..057dc567e8 100644 --- a/apps/circuit-compiler/src/app/components/configurations.tsx +++ b/apps/circuit-compiler/src/app/components/configurations.tsx @@ -42,6 +42,27 @@ export function Configurations ({primeValue, setPrimeValue, versionValue}: Confi + + <> + + + + + + + + + + <> + + + + + + + + + diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index 9f01635edb..8ba5bb4672 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -2,7 +2,9 @@ import { PluginClient } from '@remixproject/plugin' import { createClient } from '@remixproject/plugin-webview' import EventManager from 'events' import pathModule from 'path' -import { compiler_list } from 'circom_wasm' +import { compiler_list, parse, compile, generate_r1cs, generate_witness } from 'circom_wasm' +import * as compilerV218 from 'circom_wasm/v2.1.8' +import * as compilerV217 from 'circom_wasm/v2.1.7' import * as compilerV216 from 'circom_wasm/v2.1.6' import * as compilerV215 from 'circom_wasm/v2.1.5' import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' @@ -11,13 +13,13 @@ import { CompilationConfig, CompilerReport, PrimeValue, ResolverOutput } from '. export class CircomPluginClient extends PluginClient { public internalEvents: EventManager private _compilationConfig: CompilationConfig = { - version: "2.1.6", + version: "2.1.8", prime: "bn128" } private lastCompiledCircuitPath: string = '' private lastParsedFiles: Record = {} private lastCompiledFile: string = '' - private compiler: typeof compilerV215 | typeof compilerV216 = compilerV216 + private compiler: typeof compilerV215 & typeof compilerV216 & typeof compilerV217 & typeof compilerV218 constructor() { super() @@ -40,11 +42,16 @@ export class CircomPluginClient extends PluginClient { this._compilationConfig.version = version if (version === '2.1.5') this.compiler = compilerV215 else if (version === '2.1.6') this.compiler = compilerV216 + else if (version === '2.1.7') this.compiler = compilerV217 + else if (version === '2.1.8') this.compiler = compilerV218 + else this.compiler = null } set compilerPrime (prime: PrimeValue) { if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks") && (this._compilationConfig.version === '2.1.5')) throw new Error('Invalid prime value') if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks") && (prime !== "grumpkin") && (prime !== "pallas") && (prime !== "vesta") && (this._compilationConfig.version === '2.1.6')) throw new Error('Invalid prime value') + if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks") && (prime !== "grumpkin") && (prime !== "pallas") && (prime !== "vesta") && (this._compilationConfig.version === '2.1.7')) throw new Error('Invalid prime value') + if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks") && (prime !== "grumpkin") && (prime !== "pallas") && (prime !== "vesta") && (prime !== "secq256r1") && (this._compilationConfig.version === '2.1.8')) throw new Error('Invalid prime value') this._compilationConfig.prime = prime } @@ -54,7 +61,7 @@ export class CircomPluginClient extends PluginClient { fileContent = await this.call('fileManager', 'readFile', path) } this.lastParsedFiles = await this.resolveDependencies(path, fileContent) - const parsedOutput = this.compiler.parse(path, this.lastParsedFiles) + const parsedOutput = this.compiler ? this.compiler.parse(path, this.lastParsedFiles) : parse(path, this.lastParsedFiles) try { const result: CompilerReport[] = JSON.parse(parsedOutput.report()) @@ -145,7 +152,7 @@ export class CircomPluginClient extends PluginClient { this.compilerVersion = version this.compilerPrime = prime } - const circuitApi = this.compiler.compile(path, this.lastParsedFiles, { prime: this._compilationConfig.prime }) + const circuitApi = this.compiler ? this.compiler.compile(path, this.lastParsedFiles, { prime: this._compilationConfig.prime }) : compile(path, this.lastParsedFiles, { prime: this._compilationConfig.prime }) const circuitProgram = circuitApi.program() if (circuitProgram.length < 1) { @@ -175,7 +182,7 @@ export class CircomPluginClient extends PluginClient { log && this.call('terminal', 'log', { type: 'log', value: log }) }) // @ts-ignore - this.call('terminal', 'log', { type: 'typewritersuccess', value: 'Everything went okay, circom safe' }) + this.call('terminal', 'log', { type: 'typewritersuccess', value: 'Everything went okay' }) } } @@ -203,7 +210,7 @@ export class CircomPluginClient extends PluginClient { this.compilerVersion = version this.compilerPrime = prime } - const r1csApi = this.compiler.generate_r1cs(path, this.lastParsedFiles, { prime: this._compilationConfig.prime }) + const r1csApi = this.compiler ? this.compiler.generate_r1cs(path, this.lastParsedFiles, { prime: this._compilationConfig.prime }) : generate_r1cs(path, this.lastParsedFiles, { prime: this._compilationConfig.prime }) const r1csProgram = r1csApi.program() if (r1csProgram.length < 1) { @@ -222,7 +229,7 @@ export class CircomPluginClient extends PluginClient { log && this.call('terminal', 'log', { type: 'log', value: log }) }) // @ts-ignore - this.call('terminal', 'log', { type: 'typewritersuccess', value: 'Everything went okay, circom safe' }) + this.call('terminal', 'log', { type: 'typewritersuccess', value: 'Everything went okay' }) } } @@ -234,7 +241,7 @@ export class CircomPluginClient extends PluginClient { // @ts-ignore const buffer: any = await this.call('fileManager', 'readFile', wasmPath, { encoding: null }) const dataRead = new Uint8Array(buffer) - const witness = await this.compiler.generate_witness(dataRead, input) + const witness = this.compiler ? await this.compiler.generate_witness(dataRead, input) : await generate_witness(dataRead, input) // @ts-ignore await this.call('fileManager', 'writeFile', wasmPath.replace('.wasm', '.wtn'), witness, true) this.internalEvents.emit('circuit_computing_witness_done') diff --git a/apps/remix-ide-e2e/src/tests/circom.test.ts b/apps/remix-ide-e2e/src/tests/circom.test.ts index 5fa9f279bb..0f7d9e87ec 100644 --- a/apps/remix-ide-e2e/src/tests/circom.test.ts +++ b/apps/remix-ide-e2e/src/tests/circom.test.ts @@ -111,7 +111,7 @@ module.exports = { .waitForElementPresent('[data-id="circuit_feedback"]') .waitForElementVisible('[data-id="circuit_feedback"]') .assert.hasClass('[data-id="circuit_feedback"]', 'alert-warning') - .waitForElementContainsText('[data-id="circuit_feedback"]', 'File circuits/simple.circom does not include pragma version. Assuming pragma version (2, 1, 6)') + .waitForElementContainsText('[data-id="circuit_feedback"]', 'File circuits/simple.circom does not include pragma version. Assuming pragma version (2, 1, 8)') }, 'Should hide/show warnings for compiled circuit #group4': function (browser: NightwatchBrowser) { browser @@ -119,7 +119,7 @@ module.exports = { .waitForElementNotPresent('[data-id="circuit_feedback"]') .click('[data-id="hide_circuit_warnings_checkbox_input"]') .waitForElementVisible('[data-id="circuit_feedback"]') - .waitForElementContainsText('[data-id="circuit_feedback"]', 'File circuits/simple.circom does not include pragma version. Assuming pragma version (2, 1, 6)') + .waitForElementContainsText('[data-id="circuit_feedback"]', 'File circuits/simple.circom does not include pragma version. Assuming pragma version (2, 1, 8)') }, 'Should display error for invalid circuit #group4': function (browser: NightwatchBrowser) { browser diff --git a/package.json b/package.json index 60f353a7cc..b7adab73c1 100644 --- a/package.json +++ b/package.json @@ -167,7 +167,7 @@ "brace": "^0.8.0", "change-case": "^4.1.1", "chokidar": "^2.1.8", - "circom_wasm": "^0.2.1", + "circom_wasm": "https://github.com/remix-project-org/circom_wasm.git", "color-support": "^1.1.3", "commander": "^9.4.1", "core-js": "^3.6.5", diff --git a/yarn.lock b/yarn.lock index 73ace25456..38e930493f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10544,10 +10544,9 @@ circom_runtime@0.1.22: dependencies: ffjavascript "0.2.57" -circom_wasm@^0.2.1: +"circom_wasm@https://github.com/remix-project-org/circom_wasm.git": version "0.2.1" - resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.2.1.tgz#11eeceb497c03461676b3bc21d7d71ac3310dd58" - integrity sha512-57Xhg3nUcQX+aMr+sH8XyxklpPgAWohjGkaEbiJDv3UiUveFAB2pOFOOE4whoMm7mjxKbO4n4mVs1oC031ApQQ== + resolved "https://github.com/remix-project-org/circom_wasm.git#f96a79cc231dfb5ae506a7f71bb628159c0b27c0" circular-json@^0.3.0: version "0.3.3"