arnaucube
arnaucube/circomPublic Self-hosted repository
BigArray in code
Jordi Baylina jordi@baylina.cat
Thu, 30 Jul 2020 05:04:15 +0200
commit

1e2fb12631be896be9aa3b58ca6e941b6e30d1f5

parent

0e1a1bcc2305b69f83263364450a93b0a514820c

4 files changed, 15 insertions(+), 9 deletions(-)

jump to
M ports/c/builder.js → ports/c/builder.js

@@ -484,6 +484,7 @@

code.push("// Constants"); code.push(`FrElement _constants[${self.constants.length}] = {`); for (let i=0; i<self.constants.length; i++) { + if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildConstants ${i}/${this.constants.length}`); code.push((i>0 ? "," : " ") + "{" + number2Code(self.constants[i]) + "}"); } code.push("};");

@@ -561,6 +562,7 @@ _buildComponents(code) {

code.push("// Components"); code.push(`Circom_Component _components[${this.components.length}] = {`); for (let i=0; i<this.components.length; i++) { + if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildComponents ${i}/${this.components.length}`); const c = this.components[i]; const sep = i>0 ? " ," : " "; code.push(`${sep}{${c.hashMapName}, ${c.entryTableName}, ${c.functionName}, ${c.nInSignals}, ${c.newThread}}`);

@@ -573,6 +575,7 @@ code.push("// mapIsInput");

code.push(`u32 _mapIsInput[${this.mapIsInput.length}] = {`); let line = ""; for (let i=0; i<this.mapIsInput.length; i++) { + if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildMapIsInput ${i}/${this.mapIsInput.length}`); line += i>0 ? ", " : " "; line += toHex(this.mapIsInput[i]); if (((i+1) % 64)==0) {

@@ -596,6 +599,7 @@ code.push("// Witness to Signal Table");

code.push(`int _wit2sig[${this.wit2sig.length}] = {`); let line = ""; for (let i=0; i<this.wit2sig.length; i++) { + if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildWit2Sig ${i}/${this.wit2sig.length}`); line += i>0 ? "," : " "; line += this.wit2sig[i]; if (((i+1) % 64) == 0) {

@@ -628,7 +632,7 @@ }

build() { - const code=[]; + const code=new BigArray(); this._buildHeader(code); this._buildSizes(code); this._buildConstants(code);
M src/bigarray.js → src/bigarray.js

@@ -26,8 +26,10 @@ this.arr[i/SUBARRAY_SIZE] = new Array(Math.min(SUBARRAY_SIZE, initSize - i));

} return this; } - push (element) { - this.setElement (this.length, element); + push () { + for (let i=0; i<arguments.length; i++) { + this.setElement (this.length, arguments[i]); + } } getElement(idx) { idx = parseInt(idx);
M src/build.js → src/build.js

@@ -116,7 +116,7 @@ const fDefined = {};

const fnComponents = []; for (let i=0; i<ctx.components.length; i++) { - if (ctx.verbose && (i%1000 ==0)) console.log(`buildCode component: ${i}/${ctx.components.length}`); + if (ctx.verbose && (i%100000 ==0)) console.log(`buildCode component: ${i}/${ctx.components.length}`); const {h, instanceDef} = hashComponentCall(ctx, i); const fName = ctx.components[i].template+"_"+h; if (!fDefined[fName]) {

@@ -166,7 +166,7 @@ }

function buildComponentsArray(ctx) { for (let i=0; i< ctx.components.length; i++) { - if (ctx.verbose && (i%10000 ==0)) console.log(`buildComponentsArray component: ${i}/${ctx.components.length}`); + if (ctx.verbose && (i%1000000 ==0)) console.log(`buildComponentsArray component: ${i}/${ctx.components.length}`); let newThread; if (ctx.newThreadTemplates) { if (ctx.newThreadTemplates.test(ctx.components[i].template)) {

@@ -204,7 +204,7 @@ let i;

let map = []; let acc = 0; for (i=0; i<ctx.signals.length; i++) { - if (ctx.verbose && (i%100000 ==0)) console.log(`buildMapIsInput signal: ${i}/${ctx.signals.length}`); + if (ctx.verbose && (i%1000000 ==0)) console.log(`buildMapIsInput signal: ${i}/${ctx.signals.length}`); if (ctx.signals[i].o & ctx.IN) { acc = acc | (1 << (i%32) ); }

@@ -231,7 +231,7 @@ ctx.totals[ctx.stPRVINPUT] +

ctx.totals[ctx.stINTERNAL]; const arr = Array(NVars); for (let i=0; i<ctx.signals.length; i++) { - if (ctx.verbose && (i%100000 ==0)) console.log(`buildWit2Sig signal: ${i}/${ctx.signals.length}`); + if (ctx.verbose && (i%1000000 ==0)) console.log(`buildWit2Sig signal: ${i}/${ctx.signals.length}`); const outIdx = ctx.signals[i].id; if (ctx.signals[i].e>=0) continue; // If has an alias, continue.. assert(typeof outIdx != "undefined", `Signal ${i} does not have index`);
M src/streamfromarray_txt.js → src/streamfromarray_txt.js

@@ -1,4 +1,4 @@

- +const BigArray = require("./bigArray"); const Readable = require("stream").Readable; module.exports = function streamFromArrayTxt(ma) {

@@ -22,7 +22,7 @@ return rs;

function getFirstIdx(ma) { - if (!Array.isArray(ma)) return []; + if (typeof ma.push !== "function" ) return []; return [0, ...getFirstIdx(ma[0])]; }