Merge pull request #4314 from ethereum/circom-versions-update

Circom v2.1.6 support
pull/4319/head
yann300 11 months ago committed by GitHub
commit 796cb93bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      apps/circuit-compiler/src/app/components/configurations.tsx
  2. 6
      apps/circuit-compiler/src/app/components/container.tsx
  3. 42
      apps/circuit-compiler/src/app/services/circomPluginClient.ts
  4. 5
      apps/circuit-compiler/src/app/types/index.ts
  5. 4
      apps/remix-ide-e2e/src/tests/circom.test.ts
  6. 2
      package.json
  7. 8
      yarn.lock

@ -1,8 +1,8 @@
import { CustomTooltip } from "@remix-ui/helper"
import { CustomTooltip, RenderIf } from "@remix-ui/helper"
import { FormattedMessage } from "react-intl"
import { ConfigurationsProps, PrimeValue } from "../types"
export function Configurations ({primeValue, setPrimeValue}: ConfigurationsProps) {
export function Configurations ({primeValue, setPrimeValue, versionValue}: ConfigurationsProps) {
return (
<div className="pb-2 border-bottom flex-column">
<div className="flex-column d-flex">
@ -14,7 +14,7 @@ export function Configurations ({primeValue, setPrimeValue}: ConfigurationsProps
placement={"auto"}
tooltipId="circuitPrimeLabelTooltip"
tooltipClasses="text-nowrap"
tooltipText={<span>{'To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks) [default: bn128]'}</span>}
tooltipText={<span>{'To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks, grumpkin, pallas, vesta)'}</span>}
>
<div>
<select
@ -25,9 +25,23 @@ export function Configurations ({primeValue, setPrimeValue}: ConfigurationsProps
pointerEvents: 'auto'
}}
>
<RenderIf condition={versionValue === '2.1.5'}>
<>
<option value="bn128">bn128</option>
<option value="bls12381">bls12381</option>
<option value="goldilocks">goldilocks</option>
</>
</RenderIf>
<RenderIf condition={versionValue === '2.1.6'}>
<>
<option value="bn128">bn128</option>
<option value="bls12381">bls12381</option>
<option value="goldilocks">goldilocks</option>
<option value="grumpkin">grumpkin</option>
<option value="pallas">pallas</option>
<option value="vesta">vesta</option>
</>
</RenderIf>
</select>
</div>
</CustomTooltip>

@ -29,6 +29,7 @@ export function Container () {
}
const handleVersionSelect = (version: string) => {
circuitApp.plugin.compilerVersion = version
circuitApp.dispatch({ type: 'SET_COMPILER_VERSION', payload: version })
}
@ -44,7 +45,8 @@ export function Container () {
}
}
const handlePrimeChange = (value: string) => {
const handlePrimeChange = (value: PrimeValue) => {
circuitApp.plugin.compilerPrime = value
circuitApp.dispatch({ type: 'SET_PRIME_VALUE', payload: value as PrimeValue })
}
@ -75,7 +77,7 @@ export function Container () {
<VersionList setVersion={handleVersionSelect} versionList={circuitApp.appState.versionList} currentVersion={circuitApp.appState.version} />
<CompileOptions setCircuitAutoCompile={handleCircuitAutoCompile} setCircuitHideWarnings={handleCircuitHideWarnings} autoCompile={circuitApp.appState.autoCompile} hideWarnings={circuitApp.appState.hideWarnings} />
<ConfigToggler>
<Configurations setPrimeValue={handlePrimeChange} primeValue={circuitApp.appState.primeValue} />
<Configurations setPrimeValue={handlePrimeChange} primeValue={circuitApp.appState.primeValue} versionValue={circuitApp.appState.version} />
</ConfigToggler>
<CircuitActions />
<RenderIf condition={circuitApp.appState.signalInputs.length > 0}>

@ -2,19 +2,22 @@ import { PluginClient } from '@remixproject/plugin'
import { createClient } from '@remixproject/plugin-webview'
import EventManager from 'events'
import pathModule from 'path'
import { parse, compile, generate_witness, generate_r1cs, compiler_list } from 'circom_wasm'
import { compiler_list } from 'circom_wasm'
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'
import { CompilationConfig, CompilerReport, ResolverOutput } from '../types'
import { CompilationConfig, CompilerReport, PrimeValue, ResolverOutput } from '../types'
export class CircomPluginClient extends PluginClient {
public internalEvents: EventManager
private _compilationConfig: CompilationConfig = {
version: "2.1.5",
version: "2.1.6",
prime: "bn128"
}
private lastCompiledCircuitPath: string = ''
private lastParsedFiles: Record<string, string> = {}
private lastCompiledFile: string = ''
private compiler: typeof compilerV215 | typeof compilerV216 = compilerV216
constructor() {
super()
@ -32,13 +35,26 @@ export class CircomPluginClient extends PluginClient {
this.internalEvents.emit('circom_activated')
}
set compilerVersion (version: string) {
if (!compiler_list.versions.includes(version)) throw new Error("Unsupported compiler version")
this._compilationConfig.version = version
if (version === '2.1.5') this.compiler = compilerV215
else if (version === '2.1.6') this.compiler = compilerV216
}
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')
this._compilationConfig.prime = prime
}
async parse(path: string, fileContent?: string): Promise<[CompilerReport[], Record<string, string>]> {
if (!fileContent) {
// @ts-ignore
fileContent = await this.call('fileManager', 'readFile', path)
}
this.lastParsedFiles = await this.resolveDependencies(path, fileContent, { [path]: { content: fileContent, parent: null } })
const parsedOutput = parse(path, this.lastParsedFiles)
const parsedOutput = this.compiler.parse(path, this.lastParsedFiles)
try {
const result: CompilerReport[] = JSON.parse(parsedOutput.report())
@ -122,12 +138,10 @@ export class CircomPluginClient extends PluginClient {
if (compilationConfig) {
const { prime, version } = compilationConfig
if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks")) throw new Error('Invalid prime value')
if (!compiler_list.versions.includes(version)) throw new Error("Unsupported compiler version")
this._compilationConfig.prime = prime
this._compilationConfig.version = version
this.compilerVersion = version
this.compilerPrime = prime
}
const circuitApi = compile(path, this.lastParsedFiles, { prime: this._compilationConfig.prime })
const circuitApi = this.compiler.compile(path, this.lastParsedFiles, { prime: this._compilationConfig.prime })
const circuitProgram = circuitApi.program()
if (circuitProgram.length < 1) {
@ -172,12 +186,10 @@ export class CircomPluginClient extends PluginClient {
if (compilationConfig) {
const { prime, version } = compilationConfig
if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks")) throw new Error('Invalid prime value')
if (!compiler_list.versions.includes(version)) throw new Error("Unsupported compiler version")
this._compilationConfig.prime = prime
this._compilationConfig.version = version
this.compilerVersion = version
this.compilerPrime = prime
}
const r1csApi = generate_r1cs(path, this.lastParsedFiles, { prime: this._compilationConfig.prime })
const r1csApi = this.compiler.generate_r1cs(path, this.lastParsedFiles, { prime: this._compilationConfig.prime })
const r1csProgram = r1csApi.program()
if (r1csProgram.length < 1) {
@ -202,7 +214,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 generate_witness(dataRead, input)
const witness = await this.compiler.generate_witness(dataRead, input)
// @ts-ignore
await this.call('fileManager', 'writeFile', wasmPath.replace('.wasm', '.wtn'), witness, true)
this.internalEvents.emit('circuit_computing_witness_done')

@ -45,7 +45,7 @@ export type CompilationConfig = {
version: string
}
export type PrimeValue = "bn128" | "bls12381" | "goldilocks"
export type PrimeValue = "bn128" | "bls12381" | "goldilocks" | "grumpkin" | "pallas" | "vesta"
export type CompilerFeedbackProps = {
feedback: string | CompilerReport[],
@ -76,7 +76,8 @@ export type FeedbackAlertProps = {
export type ConfigurationsProps = {
setPrimeValue: (prime: PrimeValue) => void,
primeValue: PrimeValue
primeValue: PrimeValue,
versionValue: string
}
export type CompileOptionsProps = {

@ -107,7 +107,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, 5)')
.waitForElementContainsText('[data-id="circuit_feedback"]', 'File circuits/simple.circom does not include pragma version. Assuming pragma version (2, 1, 6)')
},
'Should hide/show warnings for compiled circuit #group4': function (browser: NightwatchBrowser) {
browser
@ -115,7 +115,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, 5)')
.waitForElementContainsText('[data-id="circuit_feedback"]', 'File circuits/simple.circom does not include pragma version. Assuming pragma version (2, 1, 6)')
},
'Should display error for invalid circuit #group4': function (browser: NightwatchBrowser) {
browser

@ -157,7 +157,7 @@
"brace": "^0.8.0",
"change-case": "^4.1.1",
"chokidar": "^2.1.8",
"circom_wasm": "^0.1.0",
"circom_wasm": "^0.2.0",
"color-support": "^1.1.3",
"commander": "^9.4.1",
"core-js": "^3.6.5",

@ -10062,10 +10062,10 @@ circom_runtime@0.1.22:
dependencies:
ffjavascript "0.2.57"
circom_wasm@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.1.0.tgz#dda76c7ae9046ea6f1e1cd3754c017ad753bd5c1"
integrity sha512-F7ihfVGjfSz+01yFXLHjKocQFm8j9KBageqMw5+olFWB6+7CXHLjnUaFuU6u+7T0FsL7+JuP18jdcAVQEXoQgw==
circom_wasm@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.2.0.tgz#c35537f0b1f5bfd3d88898306f46c3a3457e5589"
integrity sha512-eqDCbAXJQkKnrAg0Ow3bdaGciGTooRKL20941JGzX8IcqgHoGiZxaSLATkYy97dbmJFrxe8Wr+mOGnvdbqN9bw==
circular-json@^0.3.0:
version "0.3.3"

Loading…
Cancel
Save