Skip to content

Commit

Permalink
Merge pull request ethereum#4674 from ethereum/circom_version_update
Browse files Browse the repository at this point in the history
Circom version update
  • Loading branch information
ioedeveloper authored Mar 29, 2024
2 parents 0592510 + 87ca610 commit a736967
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
21 changes: 21 additions & 0 deletions apps/circuit-compiler/src/app/components/configurations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ export function Configurations ({primeValue, setPrimeValue, versionValue}: Confi
<option value="vesta">vesta</option>
</>
</RenderIf>
<RenderIf condition={versionValue === '2.1.7'}>
<>
<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>
<RenderIf condition={versionValue === '2.1.8'}>
<>
<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>
<option value="secq256r1">secq256r1</option>
</>
</RenderIf>
</select>
</div>
</CustomTooltip>
Expand Down
25 changes: 16 additions & 9 deletions apps/circuit-compiler/src/app/services/circomPluginClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<string, string> = {}
private lastCompiledFile: string = ''
private compiler: typeof compilerV215 | typeof compilerV216 = compilerV216
private compiler: typeof compilerV215 & typeof compilerV216 & typeof compilerV217 & typeof compilerV218

constructor() {
super()
Expand All @@ -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
}

Expand All @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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' })
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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' })
}
}

Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions apps/remix-ide-e2e/src/tests/circom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ 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
.click('[data-id="hide_circuit_warnings_checkbox_input"]')
.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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10544,10 +10544,9 @@ [email protected]:
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"
Expand Down

0 comments on commit a736967

Please sign in to comment.