mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Begining of wasm
This commit is contained in:
@@ -2,9 +2,11 @@ const path = require("path");
|
||||
|
||||
const bigInt = require("big-integer");
|
||||
const c_tester = require("../index.js").c_tester;
|
||||
const wasm_tester = require("../index.js").wasm_tester;
|
||||
|
||||
const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
||||
|
||||
const basicCases = require("./basiccases.json");
|
||||
|
||||
function normalize(o) {
|
||||
if ((typeof(o) == "bigint") || o.isZero !== undefined) {
|
||||
@@ -31,11 +33,14 @@ function normalize(o) {
|
||||
}
|
||||
|
||||
|
||||
async function doTest(circuit, testVectors) {
|
||||
const cir = await c_tester(path.join(__dirname, "circuits", circuit));
|
||||
async function doTest(tester, circuit, testVectors) {
|
||||
const cir = await tester(path.join(__dirname, "circuits", circuit));
|
||||
|
||||
for (let i=0; i<testVectors.length; i++) {
|
||||
const w = await cir.calculateWitness(normalize(testVectors[i][0]));
|
||||
// console.log(testVectors[i][0]);
|
||||
// console.log(w);
|
||||
// console.log(testVectors[i][1]);
|
||||
await cir.assertOut(w, normalize(testVectors[i][1]) );
|
||||
}
|
||||
|
||||
@@ -44,300 +49,18 @@ async function doTest(circuit, testVectors) {
|
||||
|
||||
describe("basic cases", function () {
|
||||
this.timeout(100000);
|
||||
/*
|
||||
for (let i=0; i<basicCases.length; i++) {
|
||||
it("c/c++ " + basicCases[i].name, async () => {
|
||||
await doTest(c_tester, basicCases[i].circuit, basicCases[i].tv);
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
it("inout", async () => {
|
||||
await doTest(
|
||||
"inout.circom",
|
||||
[
|
||||
[{in1: 1, in2: [2,3], in3:[[4,5], [6,7], [8,9]]}, {out1: 1, out2: [2,3], out3: [[4,5], [6,7],[8,9]]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("add", async () => {
|
||||
await doTest(
|
||||
"add.circom",
|
||||
[
|
||||
[{in: [0,0]}, {out: 0}],
|
||||
[{in: [0,1]}, {out: 1}],
|
||||
[{in: [1,2]}, {out: 3}],
|
||||
[{in: [__P__.minus(1),1]}, {out: 0}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("add constant", async () => {
|
||||
await doTest(
|
||||
"addconst1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 15}],
|
||||
[{in: 10}, {out: 25}],
|
||||
[{in: __P__.minus(2)}, {out: 13}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("for unrolled", async () => {
|
||||
await doTest(
|
||||
"forunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [0,1,2]}],
|
||||
[{in: 10}, {out: [10, 11, 12]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("for rolled", async () => {
|
||||
await doTest(
|
||||
"forrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: 0}],
|
||||
[{in: 10}, {out: 10}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("while unrolled", async () => {
|
||||
await doTest(
|
||||
"whileunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [0,1,2]}],
|
||||
[{in: 10}, {out: [10, 11, 12]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("while rolled", async () => {
|
||||
await doTest(
|
||||
"whilerolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: 0}],
|
||||
[{in: 10}, {out: 10}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("function1", async () => {
|
||||
await doTest(
|
||||
"function1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 3}],
|
||||
[{in: 10}, {out: 13}],
|
||||
[{in: __P__.minus(2)}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("function2", async () => {
|
||||
await doTest(
|
||||
"function2.circom",
|
||||
[
|
||||
[{in: 0}, {out: 3}],
|
||||
[{in: 10}, {out: 13}],
|
||||
[{in: __P__.minus(2)}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("constants1", async () => {
|
||||
await doTest(
|
||||
"constants1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 42}],
|
||||
[{in: 10}, {out: 52}],
|
||||
[{in: __P__.minus(2)}, {out: 40}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("arrays", async () => {
|
||||
await doTest(
|
||||
"arrays.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, 8, 51]}],
|
||||
[{in: 10}, {out: [11, 28, 111]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(1), 4, 39]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("if unrolled", async () => {
|
||||
await doTest(
|
||||
"ifunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, 3, 6]}],
|
||||
[{in: 10}, {out: [11, 13, 16]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(1), 1, 4]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("if rolled", async () => {
|
||||
await doTest(
|
||||
"ifrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, 0, 0]}],
|
||||
[{in: 1}, {out: [0, 1, 0]}],
|
||||
[{in: 2}, {out: [0, 0, 1]}],
|
||||
[{in: 3}, {out: [0, 0, 0]}],
|
||||
[{in: __P__.minus(2)}, {out: [0,0,0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("inc", async () => {
|
||||
await doTest(
|
||||
"inc.circom",
|
||||
[
|
||||
[{in: 0}, {out: [5, 2]}],
|
||||
[{in: 1}, {out: [6, 4]}],
|
||||
[{in: 2}, {out: [7, 6]}],
|
||||
[{in: 3}, {out: [8, 8]}],
|
||||
[{in: __P__.minus(2)}, {out: [3,__P__.minus(2)]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("dec", async () => {
|
||||
await doTest(
|
||||
"dec.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, __P__.minus(2)]}],
|
||||
[{in: 1}, {out: [2, 0]}],
|
||||
[{in: 2}, {out: [3, 2]}],
|
||||
[{in: 3}, {out: [4, 4]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(1),__P__.minus(6)]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("ops", async () => {
|
||||
await doTest(
|
||||
"ops.circom",
|
||||
[
|
||||
[{in: [-2, 2]}, {add: 0, sub: -4, mul: -4}],
|
||||
[{in: [-1, 1]}, {add: 0, sub: -2, mul: -1}],
|
||||
[{in: [ 0, 0]}, {add: 0, sub: 0, mul: 0}],
|
||||
[{in: [ 1,-1]}, {add: 0, sub: 2, mul: -1}],
|
||||
[{in: [ 2,-2]}, {add: 0, sub: 4, mul: -4}],
|
||||
[{in: [-2,-3]}, {add: -5, sub: 1, mul: 6}],
|
||||
[{in: [ 2, 3]}, {add: 5, sub: -1, mul: 6}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("ops2", async () => {
|
||||
await doTest(
|
||||
"ops2.circom",
|
||||
[
|
||||
[{in: [-2, 2]}, {div: -1, idiv: bigInt("10944121435919637611123202872628637544274182200208017171849102093287904247807"), mod: 1}],
|
||||
[{in: [-1, 1]}, {div: -1, idiv: -1, mod: 0}],
|
||||
[{in: [ 1,-1]}, {div: -1, idiv: 0, mod: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("ops3", async () => {
|
||||
await doTest(
|
||||
"ops3.circom",
|
||||
[
|
||||
[{in: [-2, 2]}, {neg1: 2,neg2: -2, pow: 4}],
|
||||
[{in: [0, 1]}, {neg1: 0, neg2: -1, pow: 0}],
|
||||
[{in: [ 1,-1]}, {neg1: -1, neg2: 1, pow: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Comparation ops", async () => {
|
||||
await doTest(
|
||||
"opscmp.circom",
|
||||
[
|
||||
[{in: [ 8, 9]}, {lt: 1, leq: 1, eq:0, neq:1, geq: 0, gt:0}],
|
||||
[{in: [-2,-2]}, {lt: 0, leq: 1, eq:1, neq:0, geq: 1, gt:0}],
|
||||
[{in: [-1,-2]}, {lt: 0, leq: 0, eq:0, neq:1, geq: 1, gt:1}],
|
||||
[{in: [ 1,-1]}, {lt: 0, leq: 0, eq:0, neq:1, geq: 1, gt:1}], // In mod, negative values are higher than positive.
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Bit ops", async () => {
|
||||
const mask = bigInt("14474011154664524427946373126085988481658748083205070504932198000989141204991");
|
||||
const m1m = bigInt("7414231717174750794300032619171286606889616317210963838766006185586667290624");
|
||||
await doTest(
|
||||
"opsbit.circom",
|
||||
[
|
||||
[{in: [ 5, 3]}, {and: 1, or: 7, xor:6, not1:mask.minus(5), shl: 40, shr:0}],
|
||||
[{in: [ 0, 0]}, {and: 0, or: 0, xor:0, not1:mask, shl: 0, shr:0}],
|
||||
[{in: [-1, 1]}, {and: 0, or: m1m.add(bigInt.one), xor:m1m.add(bigInt.one), not1:mask.minus(m1m), shl: m1m.shiftLeft(1).and(mask), shr:__P__.shiftRight(1).and(mask)}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Logical ops", async () => {
|
||||
await doTest(
|
||||
"opslog.circom",
|
||||
[
|
||||
[{in: [ 5, 0]}, {and: 0, or: 1, not1:0}],
|
||||
[{in: [ 0, 1]}, {and: 0, or: 1, not1:1}],
|
||||
[{in: [-1, 9]}, {and: 1, or: 1, not1:0}],
|
||||
[{in: [ 0, 0]}, {and: 0, or: 0, not1:1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("Conditional Ternary operator", async () => {
|
||||
await doTest(
|
||||
"condternary.circom",
|
||||
[
|
||||
[{in: 0}, {out: 21}],
|
||||
[{in: 1}, {out: 1}],
|
||||
[{in: 2}, {out: 23}],
|
||||
[{in:-1}, {out: 20}],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("Compute block", async () => {
|
||||
await doTest(
|
||||
"compute.circom",
|
||||
[
|
||||
[{x: 1}, {y: 7}],
|
||||
[{x: 2}, {y: 7}],
|
||||
[{x: 3}, {y: 11}],
|
||||
[{x:-1}, {y: -5}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Component array ", async () => {
|
||||
await doTest(
|
||||
"componentarray.circom",
|
||||
[
|
||||
[{in: 1}, {out: 1}],
|
||||
[{in: 2}, {out: 256}],
|
||||
[{in: 3}, {out: 6561}],
|
||||
[{in:-1}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Component array 2d", async () => {
|
||||
await doTest(
|
||||
"componentarray2.circom",
|
||||
[
|
||||
[{in: [1,2]}, {out: [1, 256]}],
|
||||
[{in: [0,3]}, {out: [0, 6561]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Constant circuit", async () => {
|
||||
await doTest(
|
||||
"constantcircuit.circom",
|
||||
[
|
||||
// 0xbb67ae85
|
||||
[{}, {out: [1,0,1,0, 0,0,0,1, 0,1,1,1, 0,1,0,1, 1,1,1,0, 0,1,1,0, 1,1,0,1, 1,1,0,1]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Constant internal circuit", async () => {
|
||||
await doTest(
|
||||
"constantinternalcircuit.circom",
|
||||
[
|
||||
[{in: 1}, {out: 5}],
|
||||
[{in: 0}, {out: 4}],
|
||||
[{in: -2}, {out: 2}],
|
||||
[{in: 10}, {out: 14}]
|
||||
]
|
||||
);
|
||||
});
|
||||
it("include", async () => {
|
||||
await doTest(
|
||||
"include.circom",
|
||||
[
|
||||
[{in: 3}, {out: 6}],
|
||||
[{in: 6}, {out: 15}],
|
||||
]
|
||||
);
|
||||
});
|
||||
for (let i=16; i<17; i++) {
|
||||
it("wasm " + basicCases[i].name, async () => {
|
||||
await doTest(wasm_tester, basicCases[i].circuit, basicCases[i].tv);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
343
test/basiccases.js.old
Normal file
343
test/basiccases.js.old
Normal file
@@ -0,0 +1,343 @@
|
||||
const path = require("path");
|
||||
|
||||
const bigInt = require("big-integer");
|
||||
const c_tester = require("../index.js").c_tester;
|
||||
|
||||
const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
||||
|
||||
|
||||
function normalize(o) {
|
||||
if ((typeof(o) == "bigint") || o.isZero !== undefined) {
|
||||
const res = bigInt(o);
|
||||
return norm(res);
|
||||
} else if (Array.isArray(o)) {
|
||||
return o.map(normalize);
|
||||
} else if (typeof o == "object") {
|
||||
const res = {};
|
||||
for (let k in o) {
|
||||
res[k] = normalize(o[k]);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
const res = bigInt(o);
|
||||
return norm(res);
|
||||
}
|
||||
|
||||
function norm(n) {
|
||||
let res = n.mod(__P__);
|
||||
if (res.isNegative()) res = __P__.add(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function doTest(circuit, testVectors) {
|
||||
const cir = await c_tester(path.join(__dirname, "circuits", circuit));
|
||||
|
||||
for (let i=0; i<testVectors.length; i++) {
|
||||
const w = await cir.calculateWitness(normalize(testVectors[i][0]));
|
||||
await cir.assertOut(w, normalize(testVectors[i][1]) );
|
||||
}
|
||||
|
||||
await cir.release();
|
||||
}
|
||||
|
||||
describe("basic cases", function () {
|
||||
this.timeout(100000);
|
||||
|
||||
it("inout", async () => {
|
||||
await doTest(
|
||||
"inout.circom",
|
||||
[
|
||||
[{in1: 1, in2: [2,3], in3:[[4,5], [6,7], [8,9]]}, {out1: 1, out2: [2,3], out3: [[4,5], [6,7],[8,9]]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("add", async () => {
|
||||
await doTest(
|
||||
"add.circom",
|
||||
[
|
||||
[{in: [0,0]}, {out: 0}],
|
||||
[{in: [0,1]}, {out: 1}],
|
||||
[{in: [1,2]}, {out: 3}],
|
||||
[{in: [__P__.minus(1),1]}, {out: 0}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("add constant", async () => {
|
||||
await doTest(
|
||||
"addconst1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 15}],
|
||||
[{in: 10}, {out: 25}],
|
||||
[{in: __P__.minus(2)}, {out: 13}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("for unrolled", async () => {
|
||||
await doTest(
|
||||
"forunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [0,1,2]}],
|
||||
[{in: 10}, {out: [10, 11, 12]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("for rolled", async () => {
|
||||
await doTest(
|
||||
"forrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: 0}],
|
||||
[{in: 10}, {out: 10}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("while unrolled", async () => {
|
||||
await doTest(
|
||||
"whileunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [0,1,2]}],
|
||||
[{in: 10}, {out: [10, 11, 12]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("while rolled", async () => {
|
||||
await doTest(
|
||||
"whilerolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: 0}],
|
||||
[{in: 10}, {out: 10}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("function1", async () => {
|
||||
await doTest(
|
||||
"function1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 3}],
|
||||
[{in: 10}, {out: 13}],
|
||||
[{in: __P__.minus(2)}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("function2", async () => {
|
||||
await doTest(
|
||||
"function2.circom",
|
||||
[
|
||||
[{in: 0}, {out: 3}],
|
||||
[{in: 10}, {out: 13}],
|
||||
[{in: __P__.minus(2)}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("constants1", async () => {
|
||||
await doTest(
|
||||
"constants1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 42}],
|
||||
[{in: 10}, {out: 52}],
|
||||
[{in: __P__.minus(2)}, {out: 40}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("arrays", async () => {
|
||||
await doTest(
|
||||
"arrays.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, 8, 51]}],
|
||||
[{in: 10}, {out: [11, 28, 111]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(1), 4, 39]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("if unrolled", async () => {
|
||||
await doTest(
|
||||
"ifunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, 3, 6]}],
|
||||
[{in: 10}, {out: [11, 13, 16]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(1), 1, 4]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("if rolled", async () => {
|
||||
await doTest(
|
||||
"ifrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, 0, 0]}],
|
||||
[{in: 1}, {out: [0, 1, 0]}],
|
||||
[{in: 2}, {out: [0, 0, 1]}],
|
||||
[{in: 3}, {out: [0, 0, 0]}],
|
||||
[{in: __P__.minus(2)}, {out: [0,0,0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("inc", async () => {
|
||||
await doTest(
|
||||
"inc.circom",
|
||||
[
|
||||
[{in: 0}, {out: [5, 2]}],
|
||||
[{in: 1}, {out: [6, 4]}],
|
||||
[{in: 2}, {out: [7, 6]}],
|
||||
[{in: 3}, {out: [8, 8]}],
|
||||
[{in: __P__.minus(2)}, {out: [3,__P__.minus(2)]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("dec", async () => {
|
||||
await doTest(
|
||||
"dec.circom",
|
||||
[
|
||||
[{in: 0}, {out: [1, __P__.minus(2)]}],
|
||||
[{in: 1}, {out: [2, 0]}],
|
||||
[{in: 2}, {out: [3, 2]}],
|
||||
[{in: 3}, {out: [4, 4]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(1),__P__.minus(6)]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("ops", async () => {
|
||||
await doTest(
|
||||
"ops.circom",
|
||||
[
|
||||
[{in: [-2, 2]}, {add: 0, sub: -4, mul: -4}],
|
||||
[{in: [-1, 1]}, {add: 0, sub: -2, mul: -1}],
|
||||
[{in: [ 0, 0]}, {add: 0, sub: 0, mul: 0}],
|
||||
[{in: [ 1,-1]}, {add: 0, sub: 2, mul: -1}],
|
||||
[{in: [ 2,-2]}, {add: 0, sub: 4, mul: -4}],
|
||||
[{in: [-2,-3]}, {add: -5, sub: 1, mul: 6}],
|
||||
[{in: [ 2, 3]}, {add: 5, sub: -1, mul: 6}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("ops2", async () => {
|
||||
await doTest(
|
||||
"ops2.circom",
|
||||
[
|
||||
[{in: [-2, 2]}, {div: -1, idiv: bigInt("10944121435919637611123202872628637544274182200208017171849102093287904247807"), mod: 1}],
|
||||
[{in: [-1, 1]}, {div: -1, idiv: -1, mod: 0}],
|
||||
[{in: [ 1,-1]}, {div: -1, idiv: 0, mod: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("ops3", async () => {
|
||||
await doTest(
|
||||
"ops3.circom",
|
||||
[
|
||||
[{in: [-2, 2]}, {neg1: 2,neg2: -2, pow: 4}],
|
||||
[{in: [0, 1]}, {neg1: 0, neg2: -1, pow: 0}],
|
||||
[{in: [ 1,-1]}, {neg1: -1, neg2: 1, pow: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Comparation ops", async () => {
|
||||
await doTest(
|
||||
"opscmp.circom",
|
||||
[
|
||||
[{in: [ 8, 9]}, {lt: 1, leq: 1, eq:0, neq:1, geq: 0, gt:0}],
|
||||
[{in: [-2,-2]}, {lt: 0, leq: 1, eq:1, neq:0, geq: 1, gt:0}],
|
||||
[{in: [-1,-2]}, {lt: 0, leq: 0, eq:0, neq:1, geq: 1, gt:1}],
|
||||
[{in: [ 1,-1]}, {lt: 0, leq: 0, eq:0, neq:1, geq: 1, gt:1}], // In mod, negative values are higher than positive.
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Bit ops", async () => {
|
||||
const mask = bigInt("14474011154664524427946373126085988481658748083205070504932198000989141204991");
|
||||
const m1m = bigInt("7414231717174750794300032619171286606889616317210963838766006185586667290624");
|
||||
await doTest(
|
||||
"opsbit.circom",
|
||||
[
|
||||
[{in: [ 5, 3]}, {and: 1, or: 7, xor:6, not1:mask.minus(5), shl: 40, shr:0}],
|
||||
[{in: [ 0, 0]}, {and: 0, or: 0, xor:0, not1:mask, shl: 0, shr:0}],
|
||||
[{in: [-1, 1]}, {and: 0, or: m1m.add(bigInt.one), xor:m1m.add(bigInt.one), not1:mask.minus(m1m), shl: m1m.shiftLeft(1).and(mask), shr:__P__.shiftRight(1).and(mask)}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Logical ops", async () => {
|
||||
await doTest(
|
||||
"opslog.circom",
|
||||
[
|
||||
[{in: [ 5, 0]}, {and: 0, or: 1, not1:0}],
|
||||
[{in: [ 0, 1]}, {and: 0, or: 1, not1:1}],
|
||||
[{in: [-1, 9]}, {and: 1, or: 1, not1:0}],
|
||||
[{in: [ 0, 0]}, {and: 0, or: 0, not1:1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("Conditional Ternary operator", async () => {
|
||||
await doTest(
|
||||
"condternary.circom",
|
||||
[
|
||||
[{in: 0}, {out: 21}],
|
||||
[{in: 1}, {out: 1}],
|
||||
[{in: 2}, {out: 23}],
|
||||
[{in:-1}, {out: 20}],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("Compute block", async () => {
|
||||
await doTest(
|
||||
"compute.circom",
|
||||
[
|
||||
[{x: 1}, {y: 7}],
|
||||
[{x: 2}, {y: 7}],
|
||||
[{x: 3}, {y: 11}],
|
||||
[{x:-1}, {y: -5}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Component array ", async () => {
|
||||
await doTest(
|
||||
"componentarray.circom",
|
||||
[
|
||||
[{in: 1}, {out: 1}],
|
||||
[{in: 2}, {out: 256}],
|
||||
[{in: 3}, {out: 6561}],
|
||||
[{in:-1}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Component array 2d", async () => {
|
||||
await doTest(
|
||||
"componentarray2.circom",
|
||||
[
|
||||
[{in: [1,2]}, {out: [1, 256]}],
|
||||
[{in: [0,3]}, {out: [0, 6561]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Constant circuit", async () => {
|
||||
await doTest(
|
||||
"constantcircuit.circom",
|
||||
[
|
||||
// 0xbb67ae85
|
||||
[{}, {out: [1,0,1,0, 0,0,0,1, 0,1,1,1, 0,1,0,1, 1,1,1,0, 0,1,1,0, 1,1,0,1, 1,1,0,1]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Constant internal circuit", async () => {
|
||||
await doTest(
|
||||
"constantinternalcircuit.circom",
|
||||
[
|
||||
[{in: 1}, {out: 5}],
|
||||
[{in: 0}, {out: 4}],
|
||||
[{in: -2}, {out: 2}],
|
||||
[{in: 10}, {out: 14}]
|
||||
]
|
||||
);
|
||||
});
|
||||
it("include", async () => {
|
||||
await doTest(
|
||||
"include.circom",
|
||||
[
|
||||
[{in: 3}, {out: 6}],
|
||||
[{in: 6}, {out: 15}],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
307
test/basiccases.json
Normal file
307
test/basiccases.json
Normal file
@@ -0,0 +1,307 @@
|
||||
[
|
||||
{
|
||||
"name": "inout",
|
||||
"circuit": "inout.circom",
|
||||
"tv": [
|
||||
[{
|
||||
"in1": 1,
|
||||
"in2": [2,3],
|
||||
"in3" : [[4,5], [6,7], [8,9]]
|
||||
}, {
|
||||
"out1": 1,
|
||||
"out2": [2,3],
|
||||
"out3": [[4,5], [6,7],[8,9]]
|
||||
}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "add",
|
||||
"circuit": "add.circom",
|
||||
"tv": [
|
||||
[{"in": [0,0]}, {"out": 0}],
|
||||
[{"in": [0 ,1]}, {"out": 1}],
|
||||
[{"in": [1 ,2]}, {"out": 3}],
|
||||
[{"in": [-1,1]}, {"out": 0}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "add constant",
|
||||
"circuit": "addconst1.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": 15}],
|
||||
[{"in": 10}, {"out": 25}],
|
||||
[{"in": -2}, {"out": 13}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "for unrolled",
|
||||
"circuit": "forunrolled.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [ 0, 1, 2]}],
|
||||
[{"in": 10}, {"out": [10, 11, 12]}],
|
||||
[{"in": -2}, {"out": [-2, -1, 0]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "for rolled",
|
||||
"circuit": "forrolled.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": 0}],
|
||||
[{"in": 10}, {"out": 10}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "while unrolled",
|
||||
"circuit": "whileunrolled.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [ 0, 1, 2]}],
|
||||
[{"in": 10}, {"out": [10, 11, 12]}],
|
||||
[{"in": -2}, {"out": [-2, -1, 0]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "while rolled",
|
||||
"circuit": "whilerolled.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": 0}],
|
||||
[{"in": 10}, {"out": 10}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "function1",
|
||||
"circuit": "function1.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": 3}],
|
||||
[{"in": 10}, {"out": 13}],
|
||||
[{"in": -2}, {"out": 1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "function2",
|
||||
"circuit": "function2.circom",
|
||||
"tv": [
|
||||
[{"in": 0 }, {"out": 3}],
|
||||
[{"in": 10}, {"out": 13}],
|
||||
[{"in": -2}, {"out": 1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "constants1",
|
||||
"circuit": "constants1.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": 42}],
|
||||
[{"in": 10}, {"out": 52}],
|
||||
[{"in": -2}, {"out": 40}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "arrays",
|
||||
"circuit": "arrays.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [ 1, 8, 51]}],
|
||||
[{"in": 10}, {"out": [11, 28, 111]}],
|
||||
[{"in": -2}, {"out": [-1, 4, 39]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "if unrolled",
|
||||
"circuit": "ifunrolled.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [ 1, 3, 6]}],
|
||||
[{"in": 10}, {"out": [11, 13, 16]}],
|
||||
[{"in": -2}, {"out": [-1, 1, 4]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "if rolled",
|
||||
"circuit": "ifrolled.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [1, 0, 0]}],
|
||||
[{"in": 1}, {"out": [0, 1, 0]}],
|
||||
[{"in": 2}, {"out": [0, 0, 1]}],
|
||||
[{"in": 3}, {"out": [0, 0, 0]}],
|
||||
[{"in": -2}, {"out": [0, 0, 0]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "inc",
|
||||
"circuit": "inc.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [5, 2]}],
|
||||
[{"in": 1}, {"out": [6, 4]}],
|
||||
[{"in": 2}, {"out": [7, 6]}],
|
||||
[{"in": 3}, {"out": [8, 8]}],
|
||||
[{"in": -2}, {"out": [3,-2]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "dec",
|
||||
"circuit": "dec.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": [ 1, -2]}],
|
||||
[{"in": 1}, {"out": [ 2, 0]}],
|
||||
[{"in": 2}, {"out": [ 3, 2]}],
|
||||
[{"in": 3}, {"out": [ 4, 4]}],
|
||||
[{"in": -2}, {"out": [-1, -6]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ops",
|
||||
"circuit": "ops.circom",
|
||||
"tv": [
|
||||
[{"in": [-2, 2]}, {"add": 0, "sub": -4, "mul": -4}],
|
||||
[{"in": [-1, 1]}, {"add": 0, "sub": -2, "mul": -1}],
|
||||
[{"in": [ 0, 0]}, {"add": 0, "sub": 0, "mul": 0}],
|
||||
[{"in": [ 1,-1]}, {"add": 0, "sub": 2, "mul": -1}],
|
||||
[{"in": [ 2,-2]}, {"add": 0, "sub": 4, "mul": -4}],
|
||||
[{"in": [-2,-3]}, {"add": -5, "sub": 1, "mul": 6}],
|
||||
[{"in": [ 2, 3]}, {"add": 5, "sub": -1, "mul": 6}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ops2",
|
||||
"circuit": "ops2.circom",
|
||||
"tv": [
|
||||
[{"in": [-2, 2]}, {"div": -1, "idiv": "10944121435919637611123202872628637544274182200208017171849102093287904247807", "mod": 1}],
|
||||
[{"in": [-1, 1]}, {"div": -1, "idiv": -1, "mod": 0}],
|
||||
[{"in": [ 1,-1]}, {"div": -1, "idiv": 0, "mod": 1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ops3",
|
||||
"circuit": "ops3.circom",
|
||||
"tv": [
|
||||
[{"in": [-2, 2]}, {"neg1": 2, "neg2": -2, "pow": 4}],
|
||||
[{"in": [ 0, 1]}, {"neg1": 0, "neg2": -1, "pow": 0}],
|
||||
[{"in": [ 1,-1]}, {"neg1": -1, "neg2": 1, "pow": 1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Comparation ops",
|
||||
"circuit": "opscmp.circom",
|
||||
"tv": [
|
||||
[{"in": [ 8, 9]}, {"lt": 1, "leq": 1, "eq":0, "neq":1, "geq": 0, "gt":0}],
|
||||
[{"in": [-2,-2]}, {"lt": 0, "leq": 1, "eq":1, "neq":0, "geq": 1, "gt":0}],
|
||||
[{"in": [-1,-2]}, {"lt": 0, "leq": 0, "eq":0, "neq":1, "geq": 1, "gt":1}],
|
||||
[{"in": [ 1,-1]}, {"lt": 0, "leq": 0, "eq":0, "neq":1, "geq": 1, "gt":1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Bit ops",
|
||||
"circuit": "opsbit.circom",
|
||||
"tv": [
|
||||
[
|
||||
{
|
||||
"in": [ 5, 3]
|
||||
},
|
||||
{
|
||||
"and": 1,
|
||||
"or": 7,
|
||||
"xor":6,
|
||||
"not1": "14474011154664524427946373126085988481658748083205070504932198000989141204986",
|
||||
"shl": 40,
|
||||
"shr":0
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"in": [ 0, 0]
|
||||
},
|
||||
{
|
||||
"and": 0,
|
||||
"or": 0,
|
||||
"xor":0,
|
||||
"not1":"14474011154664524427946373126085988481658748083205070504932198000989141204991",
|
||||
"shl": 0,
|
||||
"shr":0
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"in": [-1, 1]
|
||||
},
|
||||
{
|
||||
"and": 0,
|
||||
"or": "7414231717174750794300032619171286606889616317210963838766006185586667290625",
|
||||
"xor":"7414231717174750794300032619171286606889616317210963838766006185586667290625",
|
||||
"not1": "7059779437489773633646340506914701874769131765994106666166191815402473914367",
|
||||
"shl": "354452279684977160653692112256584732120484551216857172599814370184193376256",
|
||||
"shr": "10944121435919637611123202872628637544274182200208017171849102093287904247808"
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Logical ops",
|
||||
"circuit": "opslog.circom",
|
||||
"tv": [
|
||||
[{"in": [ 5, 0]}, {"and": 0, "or": 1, "not1":0}],
|
||||
[{"in": [ 0, 1]}, {"and": 0, "or": 1, "not1":1}],
|
||||
[{"in": [-1, 9]}, {"and": 1, "or": 1, "not1":0}],
|
||||
[{"in": [ 0, 0]}, {"and": 0, "or": 0, "not1":1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Conditional Ternary operator",
|
||||
"circuit": "condternary.circom",
|
||||
"tv": [
|
||||
[{"in": 0}, {"out": 21}],
|
||||
[{"in": 1}, {"out": 1}],
|
||||
[{"in": 2}, {"out": 23}],
|
||||
[{"in":-1}, {"out": 20}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Compute block",
|
||||
"circuit": "compute.circom",
|
||||
"tv": [
|
||||
[{"x": 1}, {"y": 7}],
|
||||
[{"x": 2}, {"y": 7}],
|
||||
[{"x": 3}, {"y": 11}],
|
||||
[{"x":-1}, {"y": -5}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Component array",
|
||||
"circuit": "componentarray.circom",
|
||||
"tv": [
|
||||
[{"in": 1}, {"out": 1}],
|
||||
[{"in": 2}, {"out": 256}],
|
||||
[{"in": 3}, {"out": 6561}],
|
||||
[{"in":-1}, {"out": 1}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Component array 2d",
|
||||
"circuit": "componentarray2.circom",
|
||||
"tv": [
|
||||
[{"in": [1,2]}, {"out": [1, 256]}],
|
||||
[{"in": [0,3]}, {"out": [0, 6561]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Constant circuit",
|
||||
"circuit": "constantcircuit.circom",
|
||||
"tv": [
|
||||
[{}, {"out": [1,0,1,0, 0,0,0,1, 0,1,1,1, 0,1,0,1, 1,1,1,0, 0,1,1,0, 1,1,0,1, 1,1,0,1]}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Constant internal circuit",
|
||||
"circuit": "constantinternalcircuit.circom",
|
||||
"tv": [
|
||||
[{"in": 1}, {"out": 5}],
|
||||
[{"in": 0}, {"out": 4}],
|
||||
[{"in": -2}, {"out": 2}],
|
||||
[{"in": 10}, {"out": 14}]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "include",
|
||||
"circuit": "include.circom",
|
||||
"tv": [
|
||||
[{"in": 3}, {"out": 6}],
|
||||
[{"in": 6}, {"out": 15}]
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -31,9 +31,11 @@ template Main() {
|
||||
out[0] === in+c[0];
|
||||
|
||||
out[1] <-- d[1]+c[1];
|
||||
// out[1] === (in+in)+3+c[1];
|
||||
out[1] === 2*in+3+c[1];
|
||||
|
||||
out[2] <-- d[2]+c[2];
|
||||
// out[2] === (in+in+in+in+in+in)+12+c[2];
|
||||
out[2] === 6*in+12+c[2];
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"x": "3"}
|
||||
@@ -1,4 +1,4 @@
|
||||
const tester = require("../c/buildasm/buildzqfieldtester.js");
|
||||
const tester = require("../ports/c/buildasm/buildzqfieldtester.js");
|
||||
|
||||
const ZqField = require("fflib").ZqField;
|
||||
|
||||
@@ -17,7 +17,6 @@ describe("field asm test", function () {
|
||||
const tv = buildTestVector2(bn128r, "add");
|
||||
await tester(bn128r, tv);
|
||||
});
|
||||
|
||||
it("secp256k1q add", async () => {
|
||||
const tv = buildTestVector2(secp256k1q, "add");
|
||||
await tester(secp256k1q, tv);
|
||||
@@ -267,7 +266,6 @@ describe("field asm test", function () {
|
||||
const tv = buildTestVector1(mnt6753q, "square");
|
||||
await tester(mnt6753q, tv);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function buildTestVector2(p, op) {
|
||||
|
||||
Reference in New Issue
Block a user