Compare commits

..

7 Commits

Author SHA1 Message Date
Jordi Baylina
334697dd0c 0.5.32 2020-11-21 23:02:06 +01:00
Jordi Baylina
6c48e9ba01 FIX discard unused signals 2020-11-21 23:01:57 +01:00
Jordi Baylina
42162b10c1 0.5.31 2020-11-21 20:40:27 +01:00
Jordi Baylina
a84873161f FIX discard unused signals 2020-11-21 20:40:11 +01:00
Jordi Baylina
9bf1354bf1 0.5.30 2020-10-14 09:50:22 +02:00
Jordi Baylina
ed4c4b4de0 Merge branch 'master' of github.com:iden3/circom 2020-10-14 09:49:51 +02:00
Marta Bellés
6e4a192c6a Update README.md 2020-10-05 10:12:00 +02:00
5 changed files with 44 additions and 22 deletions

View File

@@ -1,12 +1,15 @@
# Circom
Circom is a language designed to write arithmetic circuits that can be used in zero knowledge proofs.
Circom is a language designed to write arithmetic circuits that can be used in zero-knowledge proofs.
In particular, it is designed to work in [zksnarks JavaScript library](https://github.com/iden3/zksnark).
## Usage
### Circom Docs
You can read the details of circom in [the documentation webpage](https://docs.circom.io/).
### Tutorial
A good starting point [is this tutorial](https://github.com/iden3/circom/blob/master/TUTORIAL.md)

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "circom",
"version": "0.5.29",
"version": "0.5.32",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "circom",
"version": "0.5.29",
"version": "0.5.32",
"description": "Language to generate logic circuits",
"main": "index.js",
"directories": {

View File

@@ -81,10 +81,6 @@ async function compile(srcFile, options) {
throw new Error("A main component must be defined");
}
if (ctx.verbose) console.log("Classify Signals");
measures.classifySignals = -performance.now();
classifySignals(ctx);
measures.classifySignals += performance.now();
if (ctx.verbose) console.log("Reduce Constants");
measures.reduceConstants = -performance.now();
@@ -108,9 +104,13 @@ async function compile(srcFile, options) {
measures.reduceConstraints += performance.now();
}
if (ctx.verbose) console.log("NConstraints After: "+ctx.constraints.length);
if (ctx.verbose) console.log("Classify Signals");
measures.classifySignals = -performance.now();
classifySignals(ctx);
measures.classifySignals += performance.now();
measures.generateWitnessNames = -performance.now();
generateWitnessNames(ctx);
measures.generateWitnessNames += performance.now();
@@ -183,28 +183,36 @@ function classifySignals(ctx) {
function priorize(t1, t2) {
if ((t1 == ERROR) || (t2==ERROR)) return ERROR;
if (t1 == ctx.stINTERNAL) {
return t2;
} else if (t2==ctx.stINTERNAL) {
return t1;
}
if ((t1 == ctx.stONE) || (t2 == ctx.stONE)) return ctx.stONE;
if ((t1 == ctx.stOUTPUT) || (t2 == ctx.stOUTPUT)) return ctx.stOUTPUT;
if ((t1 == ctx.stPUBINPUT) || (t2 == ctx.stPUBINPUT)) return ctx.stPUBINPUT;
if ((t1 == ctx.stPRVINPUT) || (t2 == ctx.stPRVINPUT)) return ctx.stPRVINPUT;
if ((t1 == ctx.stINTERNAL) || (t2 == ctx.stINTERNAL)) return ctx.stINTERNAL;
if ((t1 == ctx.stCONSTANT) || (t2 == ctx.stCONSTANT)) return ctx.stCONSTANT;
if ((t1 == ctx.stDISCARDED) || (t2 == ctx.stDISCARDED)) return ctx.stDISCARDED;
if (t1!=t2) return ERROR;
return t1;
}
for (let i=0; i<ctx.constraints.length; i++) {
if ((ctx.verbose)&&(i%100000 == 0)) console.log(`marking as internal: ${i}/${ctx.constraints.length}`);
const c = ctx.constraints[i];
for (let s in c.a.coefs) ctx.signals[s].c = ctx.stINTERNAL;
for (let s in c.b.coefs) ctx.signals[s].c = ctx.stINTERNAL;
for (let s in c.c.coefs) ctx.signals[s].c = ctx.stINTERNAL;
}
// First classify the signals
for (let s=0; s<ctx.signals.length; s++) {
if ((ctx.verbose)&&(s%100000 == 0)) console.log(`classify signals: ${s}/${ctx.signals.length}`);
const signal = ctx.signals[s];
let tAll = ctx.stINTERNAL;
let tAll = ctx.stDISCARDED;
let lSignal = signal;
let end = false;
while (!end) {
let t = lSignal.c || ctx.stINTERNAL;
let t = lSignal.c || ctx.stDISCARDED;
if (s == 0) {
t = ctx.stONE;
} else if (lSignal.o & ctx.MAIN) {
@@ -454,7 +462,6 @@ async function reduceConstrains(ctx) {
}
sig2constraint[s] = null;
lSignal.c = ctx.stDISCARDED;
}
/*
@@ -488,7 +495,12 @@ async function reduceConstrains(ctx) {
for (let k in l.coefs) {
k = Number(k);
const signal = ctx.signals[k];
if ((signal.c == ctx.stINTERNAL)&&(!ctx.F.isZero(l.coefs[k])) &&(!removedSignals[k])) return k;
if ( ( ((signal.o & ctx.MAIN) == 0)
||( ((signal.o & ctx.IN) == 0)
&&((signal.o & ctx.OUT) == 0)))
&&((signal.o & ctx.ONE) ==0)
&&(!ctx.F.isZero(l.coefs[k]))
&&(!removedSignals[k])) return k;
}
return null;
}

View File

@@ -428,12 +428,19 @@ function execAssignement(ctx, ast) {
}
// Skip if an out is assigned directly to an input.
if ((!isIn)||(!isOut)) {
if (!(isIn&&isOut)) {
if (isIn) {
sDest.e = sIdx;
} else if (isOut) {
sSrc.e = dIdx;
} else {
sDest.e = sIdx;
}
if (!isOut) {
if (utils.isDefined(sSrc.v)) sDest.v = sSrc.v;
}
}
}
}