|
@ -26,6 +26,7 @@ const Ctx = require("./ctx"); |
|
|
const ZqField = require("fflib").ZqField; |
|
|
const ZqField = require("fflib").ZqField; |
|
|
const utils = require("./utils"); |
|
|
const utils = require("./utils"); |
|
|
const buildR1cs = require("./r1csfile").buildR1cs; |
|
|
const buildR1cs = require("./r1csfile").buildR1cs; |
|
|
|
|
|
const BigArray = require("./bigarray"); |
|
|
|
|
|
|
|
|
module.exports = compile; |
|
|
module.exports = compile; |
|
|
|
|
|
|
|
@ -124,7 +125,7 @@ function classifySignals(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// First classify the signals
|
|
|
// First classify the signals
|
|
|
for (let s in ctx.signals) { |
|
|
|
|
|
|
|
|
for (let s=0; s<ctx.signals.length; s++) { |
|
|
const signal = ctx.signals[s]; |
|
|
const signal = ctx.signals[s]; |
|
|
let tAll = ctx.stINTERNAL; |
|
|
let tAll = ctx.stINTERNAL; |
|
|
let lSignal = signal; |
|
|
let lSignal = signal; |
|
@ -216,7 +217,7 @@ function generateWitnessNames(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function reduceConstants(ctx) { |
|
|
function reduceConstants(ctx) { |
|
|
const newConstraints = []; |
|
|
|
|
|
|
|
|
const newConstraints = new BigArray(); |
|
|
for (let i=0; i<ctx.constraints.length; i++) { |
|
|
for (let i=0; i<ctx.constraints.length; i++) { |
|
|
if ((ctx.verbose)&&(i%10000 == 0)) console.log("reducing constants: ", i); |
|
|
if ((ctx.verbose)&&(i%10000 == 0)) console.log("reducing constants: ", i); |
|
|
const c = ctx.lc.canonize(ctx, ctx.constraints[i]); |
|
|
const c = ctx.lc.canonize(ctx, ctx.constraints[i]); |
|
@ -230,11 +231,11 @@ function reduceConstants(ctx) { |
|
|
|
|
|
|
|
|
function reduceConstrains(ctx) { |
|
|
function reduceConstrains(ctx) { |
|
|
indexVariables(); |
|
|
indexVariables(); |
|
|
let possibleConstraints = Object.keys(ctx.constraints); |
|
|
|
|
|
|
|
|
let possibleConstraints = ctx.constraints; |
|
|
let ii=0; |
|
|
let ii=0; |
|
|
while (possibleConstraints.length>0) { |
|
|
while (possibleConstraints.length>0) { |
|
|
let nextPossibleConstraints = {}; |
|
|
|
|
|
for (let i in possibleConstraints) { |
|
|
|
|
|
|
|
|
let nextPossibleConstraints = new BigArray(); |
|
|
|
|
|
for (let i=0; i<possibleConstraints.length; i++) { |
|
|
ii++; |
|
|
ii++; |
|
|
if ((ctx.verbose)&&(ii%10000 == 0)) console.log("reducing constraints: ", i); |
|
|
if ((ctx.verbose)&&(ii%10000 == 0)) console.log("reducing constraints: ", i); |
|
|
if (!ctx.constraints[i]) continue; |
|
|
if (!ctx.constraints[i]) continue; |
|
@ -290,7 +291,7 @@ function reduceConstrains(ctx) { |
|
|
ctx.constraints[j] = ctx.lc.substitute(ctx.constraints[j], isolatedSignal, isolatedSignalEquivalence); |
|
|
ctx.constraints[j] = ctx.lc.substitute(ctx.constraints[j], isolatedSignal, isolatedSignalEquivalence); |
|
|
linkSignalsConstraint(j); |
|
|
linkSignalsConstraint(j); |
|
|
if (j<i) { |
|
|
if (j<i) { |
|
|
nextPossibleConstraints[j] = true; |
|
|
|
|
|
|
|
|
nextPossibleConstraints.push(j); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -303,7 +304,7 @@ function reduceConstrains(ctx) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
possibleConstraints = Object.keys(nextPossibleConstraints); |
|
|
|
|
|
|
|
|
possibleConstraints = nextPossibleConstraints; |
|
|
} |
|
|
} |
|
|
unindexVariables(); |
|
|
unindexVariables(); |
|
|
|
|
|
|
|
@ -331,7 +332,7 @@ function reduceConstrains(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function unindexVariables() { |
|
|
function unindexVariables() { |
|
|
for (let s in ctx.signals) { |
|
|
|
|
|
|
|
|
for (let s=0; s<ctx.signals.length; s++) { |
|
|
let lSignal = ctx.signals[s]; |
|
|
let lSignal = ctx.signals[s]; |
|
|
while (lSignal.e>=0) { |
|
|
while (lSignal.e>=0) { |
|
|
lSignal = ctx.signals[lSignal.e]; |
|
|
lSignal = ctx.signals[lSignal.e]; |
|
@ -462,7 +463,7 @@ is converted to |
|
|
A B C |
|
|
A B C |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
function buildConstraints(ctx) { |
|
|
function buildConstraints(ctx) { |
|
|
const res = []; |
|
|
const res = []; |
|
|
|
|
|
|
|
@ -489,7 +490,7 @@ function buildConstraints(ctx) { |
|
|
|
|
|
|
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
function buildSyms(ctx, strm) { |
|
|
function buildSyms(ctx, strm) { |
|
|
|
|
|
|
|
|
let nSyms; |
|
|
let nSyms; |
|
|