Skip to content

Commit

Permalink
Merge pull request #91 from numtel/circom_default_optmization
Browse files Browse the repository at this point in the history
Change default optimization level (1 --> 2)
  • Loading branch information
erhant authored Sep 2, 2024
2 parents dad6498 + 4cfbfad commit f506672
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ npx circomkit calldata <circuit> <input>

### 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
Expand Down
5 changes: 3 additions & 2 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +66,7 @@ export const DEFAULT = Object.seal<Readonly<CircomkitConfig>>({
dirBuild: './build',
circomPath: 'circom',
// compiler-specific
optimization: 1,
optimization: 2,
inspect: true,
include: ['./node_modules'],
cWitness: false,
Expand Down
14 changes: 10 additions & 4 deletions tests/configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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}`,
});
});

Expand All @@ -150,5 +156,5 @@ describe('compiling under different directories', () => {
expect(isVerified).toBe(true);
});
})
);
));
});

0 comments on commit f506672

Please sign in to comment.