Skip to content

Commit f506672

Browse files
authored
Merge pull request #91 from numtel/circom_default_optmization
Change default optimization level (1 --> 2)
2 parents dad6498 + 4cfbfad commit f506672

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ npx circomkit calldata <circuit> <input>
9595

9696
### Circomkit Configurations
9797

98-
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:
98+
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:
9999

100100
```sh
101101
npx circomkit config

src/configs/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ export type CircomkitConfig = {
3131
version: `${number}.${number}.${number}`;
3232
/**
3333
* [Optimization level](https://docs.circom.io/getting-started/compilation-options/#flags-and-options-related-to-the-r1cs-optimization).
34+
* 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).
3435
* - `0`: No simplification is applied.
3536
* - `1`: Only applies `var` to `var` and `var` to `constant` simplification.
36-
* - `2`: Full constraint simplificiation via Gaussian eliminations.
37+
* - `2`: Full constraint simplificiation via Gaussian eliminations. (Default)
3738
* - `>2`: Any number higher than 2 will use `--O2round` with the number as simplification rounds.
3839
*/
3940
optimization: number;
@@ -65,7 +66,7 @@ export const DEFAULT = Object.seal<Readonly<CircomkitConfig>>({
6566
dirBuild: './build',
6667
circomPath: 'circom',
6768
// compiler-specific
68-
optimization: 1,
69+
optimization: 2,
6970
inspect: true,
7071
include: ['./node_modules'],
7172
cWitness: false,

tests/configs.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ describe('compiling circuits with custom_templates', () => {
100100
});
101101

102102
describe('compiling under different directories', () => {
103+
104+
// Fibonacci circuits have only addition constraints so
105+
// optimization levels >= 2 result in zero constraints and an invalid r1cs
106+
const optimizationLevels = [0, 1];
107+
103108
const cases = [
104109
{
105110
file: 'fibonacci/vanilla',
@@ -113,20 +118,21 @@ describe('compiling under different directories', () => {
113118
},
114119
] as const;
115120

116-
cases.map(testcase =>
117-
describe(`circomkit with explicit config & input (${testcase.circuit})`, () => {
121+
optimizationLevels.map(optimization => cases.map(testcase =>
122+
describe(`circomkit with explicit config (--O${optimization}) & input (${testcase.circuit})`, () => {
118123
let circomkit: Circomkit;
119124

120125
beforeAll(() => {
121126
circomkit = new Circomkit({
122127
protocol: 'groth16',
128+
optimization,
123129
verbose: false,
124130
logLevel: 'silent',
125131
circuits: './tests/circuits.json',
126132
dirPtau: './tests/ptau',
127133
dirCircuits: './tests/circuits',
128134
dirInputs: './tests/inputs',
129-
dirBuild: './tests/build',
135+
dirBuild: `./tests/build/o${optimization}`,
130136
});
131137
});
132138

@@ -150,5 +156,5 @@ describe('compiling under different directories', () => {
150156
expect(isVerified).toBe(true);
151157
});
152158
})
153-
);
159+
));
154160
});

0 commit comments

Comments
 (0)