Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eng 639 support for c #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 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 Down Expand Up @@ -30,11 +31,19 @@ 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
})
}


}

async compile() {
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
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