mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
faster write r1cs
This commit is contained in:
13
package-lock.json
generated
13
package-lock.json
generated
@@ -576,9 +576,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"fastfile": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.7.tgz",
|
||||
"integrity": "sha512-Zk7sdqsV6DsN/rhjULDfCCowPiMDsziTMFicdkrKN80yybr/6YFf9H91ELXN85dVEf6EYkVR5EHkZNc0dMqZKA=="
|
||||
"version": "0.0.8",
|
||||
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.8.tgz",
|
||||
"integrity": "sha512-i78nuMJUoNZP5J1bPjecK07+ifHMJTBnJND/4QMUYp++DDltoAjQcIeFIWoUalt7n324fvvzWR55+WEPQUA7tQ=="
|
||||
},
|
||||
"ffiasm": {
|
||||
"version": "0.0.2",
|
||||
@@ -1167,6 +1167,13 @@
|
||||
"requires": {
|
||||
"fastfile": "0.0.7",
|
||||
"ffjavascript": "0.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"fastfile": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.7.tgz",
|
||||
"integrity": "sha512-Zk7sdqsV6DsN/rhjULDfCCowPiMDsziTMFicdkrKN80yybr/6YFf9H91ELXN85dVEf6EYkVR5EHkZNc0dMqZKA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"regexpp": {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
"dependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"circom_runtime": "0.0.6",
|
||||
"fastfile": "0.0.7",
|
||||
"fastfile": "0.0.8",
|
||||
"ffiasm": "0.0.2",
|
||||
"ffjavascript": "0.2.4",
|
||||
"ffwasm": "0.0.7",
|
||||
|
||||
@@ -44,9 +44,12 @@ async function compile(srcFile, options) {
|
||||
ctx.mainComponent = options.mainComponent || "main";
|
||||
ctx.newThreadTemplates = options.newThreadTemplates;
|
||||
|
||||
if (ctx.verbose) console.time("Construction Phase");
|
||||
constructionPhase(ctx, srcFile);
|
||||
if (ctx.verbose) console.timeEnd("Construction Phase");
|
||||
|
||||
if (ctx.verbose) console.log("NConstraints Before: "+ctx.constraints.length);
|
||||
if (ctx.verbose) console.log("NSignals Before: "+ctx.signals.length);
|
||||
|
||||
if (ctx.error) {
|
||||
throw(ctx.error);
|
||||
@@ -57,10 +60,15 @@ async function compile(srcFile, options) {
|
||||
}
|
||||
|
||||
if (ctx.verbose) console.log("Classify Signals");
|
||||
if (ctx.verbose) console.time("Classify Signals");
|
||||
classifySignals(ctx);
|
||||
if (ctx.verbose) console.timeEnd("Classify Signals");
|
||||
|
||||
if (ctx.verbose) console.log("Reduce Constants");
|
||||
if (ctx.verbose) console.time("Reduce Constants");
|
||||
reduceConstants(ctx);
|
||||
if (ctx.verbose) console.timeEnd("Reduce Constants");
|
||||
|
||||
if (options.reduceConstraints) {
|
||||
|
||||
if (ctx.verbose) console.log("Reduce Constraints");
|
||||
@@ -73,13 +81,17 @@ async function compile(srcFile, options) {
|
||||
reduceConstrains(ctx);
|
||||
}
|
||||
*/
|
||||
|
||||
if (ctx.verbose) console.time("Reduce Constraints");
|
||||
await reduceConstrains(ctx);
|
||||
if (ctx.verbose) console.timeEnd("Reduce Constraints");
|
||||
|
||||
}
|
||||
|
||||
if (ctx.verbose) console.log("NConstraints After: "+ctx.constraints.length);
|
||||
|
||||
if (ctx.verbose) console.time("Generate Witness Names");
|
||||
generateWitnessNames(ctx);
|
||||
if (ctx.verbose) console.timeEnd("Generate Witness Names");
|
||||
|
||||
if (ctx.error) {
|
||||
throw(ctx.error);
|
||||
@@ -87,16 +99,19 @@ async function compile(srcFile, options) {
|
||||
|
||||
if (options.cSourceWriteStream) {
|
||||
if (ctx.verbose) console.log("Generating c...");
|
||||
if (ctx.verbose) console.time("Generate C");
|
||||
ctx.builder = new BuilderC(options.prime);
|
||||
build(ctx);
|
||||
const rdStream = ctx.builder.build();
|
||||
rdStream.pipe(options.cSourceWriteStream);
|
||||
if (ctx.verbose) console.timeEnd("Generate C");
|
||||
|
||||
// await new Promise(fulfill => options.cSourceWriteStream.on("finish", fulfill));
|
||||
}
|
||||
|
||||
if ((options.wasmWriteStream)||(options.watWriteStream)) {
|
||||
if (ctx.verbose) console.log("Generating wasm...");
|
||||
if (ctx.verbose) console.time("Generating wasm");
|
||||
ctx.builder = new BuilderWasm(options.prime);
|
||||
build(ctx);
|
||||
if (options.wasmWriteStream) {
|
||||
@@ -107,6 +122,7 @@ async function compile(srcFile, options) {
|
||||
const rdStream = ctx.builder.build("wat");
|
||||
rdStream.pipe(options.watWriteStream);
|
||||
}
|
||||
if (ctx.verbose) console.timeEnd("Generate wasm");
|
||||
|
||||
// await new Promise(fulfill => options.wasmWriteStream.on("finish", fulfill));
|
||||
}
|
||||
@@ -116,13 +132,17 @@ async function compile(srcFile, options) {
|
||||
|
||||
if (options.r1csFileName) {
|
||||
if (ctx.verbose) console.log("Generating r1cs...");
|
||||
if (ctx.verbose) console.time("Generating r1cs");
|
||||
await buildR1cs(ctx, options.r1csFileName);
|
||||
if (ctx.verbose) console.timeEnd("Generating r1cs");
|
||||
}
|
||||
|
||||
if (options.symWriteStream) {
|
||||
if (ctx.verbose) console.log("Generating syms...");
|
||||
if (ctx.verbose) console.time("Generating syms");
|
||||
const rdStream = buildSyms(ctx);
|
||||
rdStream.pipe(options.symWriteStream);
|
||||
if (ctx.verbose) console.timeEnd("Generating syms");
|
||||
|
||||
// await new Promise(fulfill => options.symWriteStream.on("finish", fulfill));
|
||||
}
|
||||
@@ -154,6 +174,7 @@ function classifySignals(ctx) {
|
||||
|
||||
// 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 lSignal = signal;
|
||||
|
||||
@@ -123,6 +123,7 @@ class LCAlgebra {
|
||||
}
|
||||
|
||||
_signal2lc(a) {
|
||||
const self = this;
|
||||
if (a.t == "S") {
|
||||
const lc = {
|
||||
t: "LC",
|
||||
|
||||
@@ -4,11 +4,14 @@ const assert = require("assert");
|
||||
|
||||
module.exports.buildR1cs = buildR1cs;
|
||||
|
||||
|
||||
async function buildR1cs(ctx, fileName) {
|
||||
|
||||
const fd = await fastFile.createOverride(fileName);
|
||||
|
||||
|
||||
const buffBigInt = new Uint8Array(ctx.F.n8);
|
||||
|
||||
const type = "r1cs";
|
||||
const buff = new Uint8Array(4);
|
||||
for (let i=0; i<4; i++) buff[i] = type.charCodeAt(i);
|
||||
@@ -112,12 +115,9 @@ async function buildR1cs(ctx, fileName) {
|
||||
|
||||
async function writeBigInt(n, pos) {
|
||||
|
||||
const s = n.toString(16);
|
||||
const b = Buffer.from(s.padStart(n8*2, "0"), "hex");
|
||||
const buff = new Uint8Array(b.length);
|
||||
for (let i=0; i<b.length; i++) buff[i] = b[b.length-1-i];
|
||||
ctx.F.toRprLE(buffBigInt, 0, n);
|
||||
|
||||
await fd.write(buff, pos);
|
||||
await fd.write(buffBigInt, pos);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user