circomlib/test/binsum.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-12-06 19:32:49 +03:00
const chai = require("chai");
const path = require("path");
2019-12-13 20:35:29 +03:00
const tester = require("circom").tester;
const Fr = require("ffjavascript").bn128.Fr;
2018-12-06 19:32:49 +03:00
const assert = chai.assert;
describe("Binary sum test", function () {
2018-12-06 19:32:49 +03:00
2019-12-16 23:35:52 +03:00
this.timeout(100000000);
2018-12-06 19:32:49 +03:00
2019-12-13 20:35:29 +03:00
it("Should create a constant circuit", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom"));
2019-12-16 23:35:52 +03:00
await circuit.loadConstraints();
2018-12-06 19:32:49 +03:00
2020-03-26 21:24:20 +03:00
assert.equal(circuit.nVars, 2);
assert.equal(circuit.constraints.length, 1);
2018-12-06 19:32:49 +03:00
const witness = await circuit.calculateWitness({ "in": Fr.e("d807aa98", 16)}, true);
2019-12-13 20:35:29 +03:00
assert(Fr.eq(witness[0],Fr.e(1)));
assert(Fr.eq(witness[1],Fr.e("d807aa98", 16)));
2018-12-06 19:32:49 +03:00
});
it("Should create a sum circuit", async () => {
2019-12-13 20:35:29 +03:00
const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom"));
2019-12-16 23:35:52 +03:00
await circuit.loadConstraints();
2018-12-06 19:32:49 +03:00
2020-03-26 21:24:20 +03:00
assert.equal(circuit.constraints.length, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
2018-12-06 19:32:49 +03:00
2020-03-26 21:24:20 +03:00
const witness = await circuit.calculateWitness({ "a": "111", "b": "222" }, true);
2018-12-06 19:32:49 +03:00
assert(Fr.eq(witness[0],Fr.e(1)));
assert(Fr.eq(witness[1],Fr.e("333")));
2018-12-06 19:32:49 +03:00
});
});