Skip to content

Commit

Permalink
Added support for compilation mode 'c'
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamsaxena12 committed Mar 22, 2023
1 parent a5a29ae commit f0ed56e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
18 changes: 13 additions & 5 deletions src/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from "path";
import log from "log"

const {wasm: wasmTester} = require("./vendors/circom_tester")
const {c: cTester} = require("./vendors/circom_tester")

import {CircuitConfig, Networks, Witness, ZK_PROOF} from "./types";
import {genGrothZKey, genPlonkZKey, genVerificationKey} from "./utils/zKey";
Expand All @@ -28,11 +29,18 @@ export class Circuit {
fs.mkdirSync(this._circuitConfig.outputDir, {recursive:true})
}

this._wasmTester = await wasmTester(this._circuitConfig.inputFilePath, {
output: this._circuitConfig.outputDir,
...this._circuitConfig.compileOptions
})

if(this._circuitConfig.compilationMode =='wasm'){
this._wasmTester = await wasmTester(this._circuitConfig.inputFilePath, {
output: this._circuitConfig.outputDir,
...this._circuitConfig.compileOptions
})
} else if (this._circuitConfig.compilationMode =='c'){
this._wasmTester = await cTester(this._circuitConfig.inputFilePath, {
output: this._circuitConfig.outputDir,
...this._circuitConfig.compileOptions
})
}


}

Expand Down
1 change: 1 addition & 0 deletions src/configParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class ConfigParser {
zKeyPath: path.join(cktOutputDir, "circuit_final.zkey"), // DO NOT change the names
vKeyPath: path.join(cktOutputDir, "verification_key.json"), // DO NOT change the names
r1csPath: path.join(cktOutputDir, `${cktName}.r1cs`),
compilationMode: c.compilationMode? c.compilationMode : "wasm",
compileOptions: {
include: [],
snarkType: c.proofType ? c.proofType : "groth16",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as CircomJS } from "./circomJs"
export { default as CircomJS } from "./circomJs"
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type CircuitConfig = {
zKeyPath: string;
vKeyPath: string;
compileOptions: CompileOptions;
compilationMode: CompilationMode;
r1csPath:string
}

Expand Down
9 changes: 4 additions & 5 deletions src/vendors/circom_tester/c/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function c_tester(circomInput, _options) {
assert(false,"Cannot set recompile to false if the "+jsPath+" folder does not exist");
}
}
return new CTester(options.output, baseName, run);
return new CTester(options.output, baseName);
}

async function compile (baseName, fileName, options) {
Expand All @@ -76,9 +76,9 @@ async function compile (baseName, fileName, options) {
if (options.O === 0) flags += "--O0 ";
if (options.O === 1) flags += "--O1 ";
if (options.verbose) flags += "--verbose ";

let b;
try {
let b = await exec("circom " + flags + fileName);
b = await exec("circom " + flags + fileName);
if (options.verbose) {
console.log(b.stdout);
}
Expand All @@ -95,10 +95,9 @@ async function compile (baseName, fileName, options) {

class CTester {

constructor(dir, baseName, witnessCalculator) {
constructor(dir, baseName) {
this.dir=dir;
this.baseName = baseName;
this.witnessCalculator = witnessCalculator;
}

async release() {
Expand Down
2 changes: 1 addition & 1 deletion tests/circomJS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const jsonConfig = `
"cID": "circ1000constraints",
"fileName": "circ1000constraints.circom",
"proofType": "plonk",
"compilationMode": "wasm"
"compilationMode": "c"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/circuit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const jsonConfig = `
"cID": "circ1000constraints",
"fileName": "circ1000constraints.circom",
"proofType": "plonk",
"compilationMode": "wasm"
"compilationMode": "c"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/configParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("ConfigParser test", () => {
"cID": "circ1000constraints",
"fileName": "circ1000constraints.circom",
"proofType": "groth16",
"compilationMode": "wasm"
"compilationMode": "c"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/data/circuit.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"cID": "circ1000constraints",
"fileName": "circ1000constraints.circom",
"proofType": "plonk",
"compilationMode": "wasm"
"compilationMode": "c"
}
]
},
Expand Down

0 comments on commit f0ed56e

Please sign in to comment.