diff --git a/README.md b/README.md index 8622578..536cdd8 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ npx circomkit calldata ### Circomkit Configurations -Everything used by Circomkit can be optionally overridden by providing the selected fields in its constructor. Circomkit CLI does this automatically by checking out `circomkit.json` and overriding the defaults with that. You can print the active configuration via the following command: +Everything used by Circomkit can be optionally overridden by providing the selected fields in its constructor. Circomkit CLI does this automatically by checking out [`circomkit.json`](src/configs/index.ts#L56) and overriding the defaults with that. You can print the active configuration via the following command: ```sh npx circomkit config diff --git a/src/configs/index.ts b/src/configs/index.ts index 2d02ecb..f5804f0 100644 --- a/src/configs/index.ts +++ b/src/configs/index.ts @@ -31,9 +31,10 @@ export type CircomkitConfig = { version: `${number}.${number}.${number}`; /** * [Optimization level](https://docs.circom.io/getting-started/compilation-options/#flags-and-options-related-to-the-r1cs-optimization). + * Defaults to `2` as per the Circom defaults, see [`circom/src/input_user.rs`](https://github.com/iden3/circom/blob/master/circom/src/input_user.rs#L249). * - `0`: No simplification is applied. * - `1`: Only applies `var` to `var` and `var` to `constant` simplification. - * - `2`: Full constraint simplificiation via Gaussian eliminations. + * - `2`: Full constraint simplificiation via Gaussian eliminations. (Default) * - `>2`: Any number higher than 2 will use `--O2round` with the number as simplification rounds. */ optimization: number; @@ -65,7 +66,7 @@ export const DEFAULT = Object.seal>({ dirBuild: './build', circomPath: 'circom', // compiler-specific - optimization: 1, + optimization: 2, inspect: true, include: ['./node_modules'], cWitness: false, diff --git a/tests/configs.test.ts b/tests/configs.test.ts index c73d772..97d575f 100644 --- a/tests/configs.test.ts +++ b/tests/configs.test.ts @@ -100,6 +100,11 @@ describe('compiling circuits with custom_templates', () => { }); describe('compiling under different directories', () => { + + // Fibonacci circuits have only addition constraints so + // optimization levels >= 2 result in zero constraints and an invalid r1cs + const optimizationLevels = [0, 1]; + const cases = [ { file: 'fibonacci/vanilla', @@ -113,20 +118,21 @@ describe('compiling under different directories', () => { }, ] as const; - cases.map(testcase => - describe(`circomkit with explicit config & input (${testcase.circuit})`, () => { + optimizationLevels.map(optimization => cases.map(testcase => + describe(`circomkit with explicit config (--O${optimization}) & input (${testcase.circuit})`, () => { let circomkit: Circomkit; beforeAll(() => { circomkit = new Circomkit({ protocol: 'groth16', + optimization, verbose: false, logLevel: 'silent', circuits: './tests/circuits.json', dirPtau: './tests/ptau', dirCircuits: './tests/circuits', dirInputs: './tests/inputs', - dirBuild: './tests/build', + dirBuild: `./tests/build/o${optimization}`, }); }); @@ -150,5 +156,5 @@ describe('compiling under different directories', () => { expect(isVerified).toBe(true); }); }) - ); + )); });