mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-07 03:06:42 +01:00
Readme, License Fixes and another test added
This commit is contained in:
@@ -1,43 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
template AND() {
|
|
||||||
signal input a;
|
|
||||||
signal input b;
|
|
||||||
signal output c;
|
|
||||||
|
|
||||||
c <== a*b;
|
|
||||||
}
|
|
||||||
|
|
||||||
template AND3() {
|
|
||||||
signal input in1;
|
|
||||||
signal input in2;
|
|
||||||
signal input in3;
|
|
||||||
signal output out;
|
|
||||||
|
|
||||||
component and1 = AND();
|
|
||||||
component and2 = AND();
|
|
||||||
|
|
||||||
in1 ==> and1.a;
|
|
||||||
in2 ==> and1.b;
|
|
||||||
in3 ==> and2.a;
|
|
||||||
and1.c ==> and2.b;
|
|
||||||
and2.c ==> out;
|
|
||||||
}
|
|
||||||
|
|
||||||
template ToBin() {
|
|
||||||
signal input in;
|
|
||||||
signal output out[32];
|
|
||||||
|
|
||||||
var lc = 0;
|
|
||||||
|
|
||||||
for (var i=0; i<32; i++) {
|
|
||||||
out[i] <-- (in >> i) & 1;
|
|
||||||
lc = lc + out[i] * 2**i;
|
|
||||||
out[i]*(out[i]-1) === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
lc === in;
|
|
||||||
}
|
|
||||||
|
|
||||||
component main = ToBin();
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
template AND() {
|
|
||||||
signal input s1;
|
|
||||||
signal input s2;
|
|
||||||
signal output s3;
|
|
||||||
|
|
||||||
s3 <== s1*s2;
|
|
||||||
s1*(s1-1) === 0;
|
|
||||||
s2*(s2-1) === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
component main = AND();
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
include "constants.jaz"
|
|
||||||
|
|
||||||
template A() {
|
|
||||||
signal input in;
|
|
||||||
component h0;
|
|
||||||
h0 = K(8);
|
|
||||||
|
|
||||||
var lc = 0;
|
|
||||||
var e = 1;
|
|
||||||
for (var i=0; i<32; i++) {
|
|
||||||
lc = lc + e*h0.out[i];
|
|
||||||
e *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
lc === in;
|
|
||||||
}
|
|
||||||
|
|
||||||
component main = A();
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"in": "0xd807aa98"
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
include "../../circuits/sha256/constants.jaz"
|
include "../../circuits/sha256/constants.circom"
|
||||||
|
|
||||||
template A() {
|
template A() {
|
||||||
signal input in;
|
signal input in;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
include "bitify.jaz"
|
include "../../circuits/sha256/bitify.circom"
|
||||||
include "binsum.jaz"
|
include "../../circuits/sha256/binsum.circom"
|
||||||
|
|
||||||
template A() {
|
template A() {
|
||||||
signal private input a;
|
signal private input a;
|
||||||
@@ -9,7 +9,7 @@ const assert = chai.assert;
|
|||||||
describe("SHA256 test", () => {
|
describe("SHA256 test", () => {
|
||||||
it("Should create a constant circuit", async () => {
|
it("Should create a constant circuit", async () => {
|
||||||
|
|
||||||
const cirDef = await compiler(path.join(__dirname, "circuits", "constants_test.jaz"));
|
const cirDef = await compiler(path.join(__dirname, "circuits", "constants_test.circom"));
|
||||||
assert.equal(cirDef.nVars, 2);
|
assert.equal(cirDef.nVars, 2);
|
||||||
|
|
||||||
const circuit = new zkSnark.Circuit(cirDef);
|
const circuit = new zkSnark.Circuit(cirDef);
|
||||||
@@ -19,4 +19,18 @@ describe("SHA256 test", () => {
|
|||||||
assert(witness[0].equals(zkSnark.bigInt(1)));
|
assert(witness[0].equals(zkSnark.bigInt(1)));
|
||||||
assert(witness[1].equals(zkSnark.bigInt("0xd807aa98")));
|
assert(witness[1].equals(zkSnark.bigInt("0xd807aa98")));
|
||||||
});
|
});
|
||||||
|
it("Should create a sum circuit", async () => {
|
||||||
|
|
||||||
|
const cirDef = await compiler(path.join(__dirname, "circuits", "sum_test.circom"));
|
||||||
|
assert.equal(cirDef.nVars, 101);
|
||||||
|
|
||||||
|
const circuit = new zkSnark.Circuit(cirDef);
|
||||||
|
|
||||||
|
const witness = circuit.calculateWitness({ "a": "111", "b": "222" });
|
||||||
|
|
||||||
|
assert(witness[0].equals(zkSnark.bigInt(1)));
|
||||||
|
assert(witness[1].equals(zkSnark.bigInt("333")));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user