mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Various small fixes
This commit is contained in:
@@ -1,14 +1,36 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
const snarkjs = require("snarkjs");
|
||||
const crypto = require("crypto");
|
||||
|
||||
const bigInt = snarkjs.bigInt;
|
||||
|
||||
const compiler = require("../index.js");
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
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"));
|
||||
});
|
||||
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)));
|
||||
});
|
||||
});
|
||||
|
||||
12
test/circuits/declareandistantiate.circom
Normal file
12
test/circuits/declareandistantiate.circom
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
template A() {
|
||||
signal a;
|
||||
}
|
||||
|
||||
template B() {
|
||||
component a[2] = A();
|
||||
}
|
||||
|
||||
component main = B();
|
||||
19
test/circuits/forvariables.circom
Normal file
19
test/circuits/forvariables.circom
Normal file
@@ -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();
|
||||
14
test/circuits/mixvarsignal.circom
Normal file
14
test/circuits/mixvarsignal.circom
Normal file
@@ -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();
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user