@ -1,14 +1,36 @@ |
|||||
const chai = require("chai"); |
const chai = require("chai"); |
||||
const path = require("path"); |
const path = require("path"); |
||||
const snarkjs = require("snarkjs"); |
const snarkjs = require("snarkjs"); |
||||
const crypto = require("crypto"); |
|
||||
|
|
||||
|
const bigInt = snarkjs.bigInt; |
||||
|
|
||||
const compiler = require("../index.js"); |
const compiler = require("../index.js"); |
||||
|
|
||||
const assert = chai.assert; |
const assert = chai.assert; |
||||
|
|
||||
describe("Sum test", () => { |
describe("Sum test", () => { |
||||
it("Should compile a code with an undefined if", async() => { |
|
||||
|
it("Should compile a code with an undefined if", async () => { |
||||
await compiler(path.join(__dirname, "circuits", "undefinedif.circom")); |
await compiler(path.join(__dirname, "circuits", "undefinedif.circom")); |
||||
}); |
}); |
||||
|
it("Should compile a code with vars inside a for", async () => { |
||||
|
const cirDef = await compiler(path.join(__dirname, "circuits", "forvariables.circom")); |
||||
|
|
||||
|
const circuit = new snarkjs.Circuit(cirDef); |
||||
|
|
||||
|
const witness = circuit.calculateWitness({ "in": 111}); |
||||
|
assert(witness[0].equals(bigInt(1))); |
||||
|
assert(witness[1].equals(bigInt(114))); |
||||
|
assert(witness[2].equals(bigInt(111))); |
||||
|
|
||||
|
}); |
||||
|
it("Should compile a code with an undefined if", async () => { |
||||
|
const cirDef = await compiler(path.join(__dirname, "circuits", "mixvarsignal.circom")); |
||||
|
|
||||
|
const circuit = new snarkjs.Circuit(cirDef); |
||||
|
|
||||
|
const witness = circuit.calculateWitness({ "i": 111}); |
||||
|
assert(witness[0].equals(bigInt(1))); |
||||
|
assert(witness[1].equals(bigInt(111))); |
||||
|
assert(witness[2].equals(bigInt(111))); |
||||
|
}); |
||||
}); |
}); |
@ -0,0 +1,12 @@ |
|||||
|
|
||||
|
|
||||
|
|
||||
|
template A() { |
||||
|
signal a; |
||||
|
} |
||||
|
|
||||
|
template B() { |
||||
|
component a[2] = A(); |
||||
|
} |
||||
|
|
||||
|
component main = B(); |
@ -0,0 +1,19 @@ |
|||||
|
template A() { |
||||
|
signal input in; |
||||
|
signal output out; |
||||
|
|
||||
|
var acc = 0; |
||||
|
for (var i=0; i<3; i++) { |
||||
|
if (i==1) { |
||||
|
var accIn = 0; |
||||
|
for (var j=0; j<3; j++) { |
||||
|
accIn= accIn+1; |
||||
|
} |
||||
|
acc = acc + accIn; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
out <== in + acc; |
||||
|
} |
||||
|
|
||||
|
component main = A(); |
@ -0,0 +1,14 @@ |
|||||
|
template X() { |
||||
|
signal input i; |
||||
|
signal output out; |
||||
|
|
||||
|
var r = 0; |
||||
|
for (var n=0; n<i; n++) { |
||||
|
r++; |
||||
|
} |
||||
|
|
||||
|
i === r; |
||||
|
out <== r; |
||||
|
} |
||||
|
|
||||
|
component main = X(); |