const fs = require("fs"); const assert = require("assert"); const lc = require("./lcalgebra"); const bigInt = require("big-integer"); module.exports.buildR1cs = buildR1cs; module.exports.loadR1cs = loadR1cs; async function loadR1cs(fileName, loadConstraints, loadMap) { const res = {}; const fd = await fs.promises.open(fileName, "r"); const b = Buffer.allocUnsafe(4); await fd.read(b, 0, 4, 0); if (b.toString() != "r1cs") assert(false, "Invalid File format"); let p=4; let v = await readU32(); if (v>1) assert(false, "Version not supported"); const nSections = await readU32(); let pHeader; let pConstraints; let headerSize; let constraintsSize; let pMap; let mapSize; for (let i=0; i=0) continue; // If has an alias, continue.. assert(typeof outIdx != "undefined", `Signal ${i} does not have index`); if (outIdx>=NWires) continue; // Is a constant or a discarded variable if (typeof arr[ctx.signals[i].id] == "undefined") { arr[outIdx] = i; } } for (let i=0; i=0 ) lSignal = ctx.signals[lSignal.e]; await writeU32(lSignal.id); await writeBigInt(lc.values[s]); } } async function writeBigInt(n) { const bytes = bigInt(n).toArray(256).value.reverse(); await fd.write(Buffer.from([bytes.length, ...bytes ])); p += bytes.length+1; } }