arnaucube
arnaucube/circomPublic Self-hosted repository
deps and verbos
Jordi Baylina jordi@baylina.cat
Thu, 02 Jul 2020 05:33:31 +0200
commit

744d3b241cd482d668f5c980e9c9160d9db17681

parent

1a5f7d1a2be5f6f9897807da75a4746ed1999370

6 files changed, 25 insertions(+), 16 deletions(-)

jump to
M TUTORIAL.md → TUTORIAL.md

@@ -8,7 +8,7 @@ ### 1.1 Pre-requisites

If you don't have it installed yet, you need to install `Node.js`. -The last stable version of `Node.js` (or 8.12.0) works just fine, but if you install the latest current version `Node.js` (10.12.0) you will see a significant increase in performance. This is because last versions of node includes Big Integer Libraries nativelly. The `snarkjs` library makes use of this feature if available, and this improves the performance x10 (!). +You should install at least version 10 of node. It's important to note here that the latests versions of javascript, includes big integer support and web assembly compilers that make the code run fast. ### 1.2 Install **circom** and **snarkjs**
M cli.js → cli.js

@@ -82,7 +82,6 @@ const options = {};

options.reduceConstraints = !argv.fast; options.verbose = argv.verbose || false; options.sanityCheck = argv.sanitycheck; -options.prime = argv.prime ? Scalar.fromString(argv.prime) : Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617"); if (argv.csource) { options.cSourceWriteStream = fs.createWriteStream(cSourceName);

@@ -102,6 +101,16 @@ }

if (argv.newThreadTemplates) { options.newThreadTemplates = new RegExp(argv.newThreadTemplates); } +if (!argv.prime) { + options.prime = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617"); +} else if (["BLS12-381", "BLS12381"]. indexOf(argv.prime.toUpperCase()) >=0) { + options.prime = Scalar.fromString("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16); +} else if (["BN-128", "BN128", "BN254", "BN-254"]. indexOf(argv.prime.toUpperCase()) >=0) { + options.prime = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617"); +} else { + options.prime = Scalar.fromString(argv.prime); +} + compiler(fullFileName, options).then( () => { let cSourceDone = false;
M package.json → package.json

@@ -31,7 +31,7 @@ },

"dependencies": { "chai": "^4.2.0", "circom_runtime": "0.0.6", - "fastfile": "0.0.1", + "fastfile": "0.0.2", "ffiasm": "0.0.2", "ffjavascript": "0.1.2", "ffwasm": "0.0.7",
M ports/c/builder.js → ports/c/builder.js

@@ -504,7 +504,7 @@ }

function addShortMontgomeryNegative(a) { - const b = self.F.neg(a); + const b = -Scalar.toNumber(self.F.neg(a)); return `${b.toString()}, 0x40000000, { ${getLongString(toMontgomery(a))} }`; }
M ports/wasm/build_runtime.js → ports/wasm/build_runtime.js

@@ -728,12 +728,9 @@ c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(builder.header.NVars))),

c.setLocal( "pSrc", - c.i32_add( - c.i32_const(builder.pSignals), - c.i32_mul( - c.getLocal("i"), - c.i32_const(builder.sizeFr) - ) + c.call( + "getPWitness", + c.getLocal("i"), ) ),

@@ -745,7 +742,7 @@

c.setLocal( "pDst", c.i32_add( - c.i32_const(builder.pSignals), + c.i32_const(builder.pOutput), c.i32_mul( c.getLocal("i"), c.i32_const(builder.sizeFr-8)

@@ -770,7 +767,7 @@ ),

c.br(0) )), - c.i32_const(builder.pSignals) + c.i32_const(builder.pOutput) ); }

@@ -804,6 +801,7 @@

buildWasmFf(module, "Fr", builder.header.P); builder.pSignals=module.alloc(builder.header.NSignals*builder.sizeFr); + builder.pOutput=module.alloc(builder.header.NVars*(builder.sizeFr-8)); builder.pInputSignalsToTrigger=module.alloc(builder.header.NComponents*4); builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4);
M src/compiler.js → src/compiler.js

@@ -32,14 +32,14 @@

module.exports = compile; async function compile(srcFile, options) { - options.p = options.p || Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617"); + options.prime = options.prime || Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617"); if (!options) { options = {}; } if (typeof options.reduceConstraints === "undefined") { options.reduceConstraints = true; } - const ctx = new Ctx(options.p); + const ctx = new Ctx(options.prime); ctx.verbose= options.verbose || false; ctx.mainComponent = options.mainComponent || "main"; ctx.newThreadTemplates = options.newThreadTemplates;

@@ -82,7 +82,8 @@ throw(ctx.error);

} if (options.cSourceWriteStream) { - ctx.builder = new BuilderC(options.p); + if (ctx.verbose) console.log("Generating c..."); + ctx.builder = new BuilderC(options.prime); build(ctx); const rdStream = ctx.builder.build(); rdStream.pipe(options.cSourceWriteStream);

@@ -91,7 +92,8 @@ // await new Promise(fulfill => options.cSourceWriteStream.on("finish", fulfill));

} if ((options.wasmWriteStream)||(options.watWriteStream)) { - ctx.builder = new BuilderWasm(options.p); + if (ctx.verbose) console.log("Generating wasm..."); + ctx.builder = new BuilderWasm(options.prime); build(ctx); if (options.wasmWriteStream) { const rdStream = ctx.builder.build("wasm");