circom_tester
Version:
Tools for testing circom circuits.
162 lines (144 loc) • 5.55 kB
JavaScript
const path = require("path");
const wasm_tester = require("./../../index").wasm;
const c_tester = require("./../../index").c;
const testInput = {
a: [["1", "2"], ["3", "4"]],
commitment: "3330844108758711782672220159612173083623710937399719017074673646455206473965"
};
describe("Arrays (autogenerated main component)", function () {
this.timeout(100000);
it("wasm: gen main with template name, params", async function () {
const circuit = await wasm_tester(
path.join(__dirname, "Arrays.circom"),
{
templateName: "Arrays",
templateParams: [2, 2n],
}
);
const w = await circuit.calculateWitness(testInput);
const outputs = await circuit.getOutput(w, {"a": [2, 2], "commitment": 1});
await circuit.checkConstraints(w);
console.log(outputs);
});
it("wasm: gen main with template name, params & public signals", async function () {
const circuit = await wasm_tester(
path.join(__dirname, "Arrays.circom"),
{
templateName: "Arrays",
templateParams: [2, 2n],
templatePublicSignals: ["a", "commitment"],
}
);
const w = await circuit.calculateWitness(testInput);
const outputs = await circuit.getOutput(w, {"a": [2, 2], "commitment": 1});
await circuit.checkConstraints(w);
console.log(outputs);
});
it("wasm: gen main with template name, params & public signals in a given folder", async function () {
const circuit = await wasm_tester(
path.join(__dirname, "Arrays.circom"),
{
output: path.join(__dirname, "tmp"),
templateName: "Arrays",
templateParams: [2, 2n],
templatePublicSignals: ["a", "commitment"],
}
);
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
});
it("wasm: gen main with params, autodetect template name, in a given folder", async function () {
const circuit = await wasm_tester(
path.join(__dirname, "Arrays.circom"),
{
output: path.join(__dirname, "tmp"),
templateParams: [2, 2n],
}
);
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
});
it("wasm: gen main with params and public signals, autodetect template name, in a given folder", async function () {
const circuit = await wasm_tester(
path.join(__dirname, "Arrays.circom"),
{
output: path.join(__dirname, "tmp"),
templateParams: [2, 2n],
}
);
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
});
it("wasm: gen main with params & public signals, autodetect template name, in a given folder without recompiling", async function () {
const circuit = await wasm_tester(
path.join(__dirname, "Arrays.circom"),
{
output: path.join(__dirname, "tmp"),
recompile: false,
templateParams: [2, 2],
}
);
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
});
it("c: gen main with params, autodetect template name", async function () {
const circuit = await c_tester(
path.join(__dirname, "Arrays.circom"),
{
templateParams: [2, 2],
}
);
try {
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
} catch (e) {
if (e.message.includes("Illegal instruction")) {
// GitHub Actions may run on older hardware that doesn't support ADX
// instructions used in cpp witness calculator
// If such a case, skip this test
this.skip();
} else {
throw e;
}
}
});
it("c: gen main with params, autodetect template name, in a given folder", async function () {
const circuit = await c_tester(
path.join(__dirname, "Arrays.circom"),
{
output: path.join(__dirname, "tmp"),
templateParams: [2, 2],
}
);
try {
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
} catch (e) {
if (e.message.includes("Illegal instruction")) {
this.skip();
} else {
throw e;
}
}
});
it("c: gen main with params, autodetect template name, in a given folder without recompiling", async function () {
const circuit = await c_tester(
path.join(__dirname, "Arrays.circom"),
{
output: path.join(__dirname, "tmp"),
recompile: false,
templateParams: [2, 2],
}
);
try {
const w = await circuit.calculateWitness(testInput);
await circuit.checkConstraints(w);
} catch (e) {
if (e.message.includes("Illegal instruction")) {
this.skip();
} else {
throw e;
}
}
});
});