deps and verbos

This commit is contained in:
Jordi Baylina
2020-07-02 05:33:31 +02:00
parent 1a5f7d1a2b
commit 744d3b241c
6 changed files with 25 additions and 16 deletions

View File

@@ -8,7 +8,7 @@ This tutorial will guide you in creating your first zero-knowledge SNARK circuit
If you don't have it installed yet, you need to install `Node.js`. 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** ### 1.2 Install **circom** and **snarkjs**

11
cli.js
View File

@@ -82,7 +82,6 @@ const options = {};
options.reduceConstraints = !argv.fast; options.reduceConstraints = !argv.fast;
options.verbose = argv.verbose || false; options.verbose = argv.verbose || false;
options.sanityCheck = argv.sanitycheck; options.sanityCheck = argv.sanitycheck;
options.prime = argv.prime ? Scalar.fromString(argv.prime) : Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
if (argv.csource) { if (argv.csource) {
options.cSourceWriteStream = fs.createWriteStream(cSourceName); options.cSourceWriteStream = fs.createWriteStream(cSourceName);
@@ -102,6 +101,16 @@ if (argv.sym) {
if (argv.newThreadTemplates) { if (argv.newThreadTemplates) {
options.newThreadTemplates = new RegExp(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( () => { compiler(fullFileName, options).then( () => {
let cSourceDone = false; let cSourceDone = false;

View File

@@ -31,7 +31,7 @@
"dependencies": { "dependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
"circom_runtime": "0.0.6", "circom_runtime": "0.0.6",
"fastfile": "0.0.1", "fastfile": "0.0.2",
"ffiasm": "0.0.2", "ffiasm": "0.0.2",
"ffjavascript": "0.1.2", "ffjavascript": "0.1.2",
"ffwasm": "0.0.7", "ffwasm": "0.0.7",

View File

@@ -504,7 +504,7 @@ class BuilderC {
function addShortMontgomeryNegative(a) { function addShortMontgomeryNegative(a) {
const b = self.F.neg(a); const b = -Scalar.toNumber(self.F.neg(a));
return `${b.toString()}, 0x40000000, { ${getLongString(toMontgomery(a))} }`; return `${b.toString()}, 0x40000000, { ${getLongString(toMontgomery(a))} }`;
} }

View File

@@ -728,12 +728,9 @@ module.exports = function buildRuntime(module, builder) {
c.setLocal( c.setLocal(
"pSrc", "pSrc",
c.i32_add( c.call(
c.i32_const(builder.pSignals), "getPWitness",
c.i32_mul( c.getLocal("i"),
c.getLocal("i"),
c.i32_const(builder.sizeFr)
)
) )
), ),
@@ -745,7 +742,7 @@ module.exports = function buildRuntime(module, builder) {
c.setLocal( c.setLocal(
"pDst", "pDst",
c.i32_add( c.i32_add(
c.i32_const(builder.pSignals), c.i32_const(builder.pOutput),
c.i32_mul( c.i32_mul(
c.getLocal("i"), c.getLocal("i"),
c.i32_const(builder.sizeFr-8) c.i32_const(builder.sizeFr-8)
@@ -770,7 +767,7 @@ module.exports = function buildRuntime(module, builder) {
c.br(0) c.br(0)
)), )),
c.i32_const(builder.pSignals) c.i32_const(builder.pOutput)
); );
} }
@@ -804,6 +801,7 @@ module.exports = function buildRuntime(module, builder) {
buildWasmFf(module, "Fr", builder.header.P); buildWasmFf(module, "Fr", builder.header.P);
builder.pSignals=module.alloc(builder.header.NSignals*builder.sizeFr); 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.pInputSignalsToTrigger=module.alloc(builder.header.NComponents*4);
builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4); builder.pSignalsAssigned=module.alloc(builder.header.NSignals*4);

View File

@@ -32,14 +32,14 @@ const buildSyms = require("./buildsyms");
module.exports = compile; module.exports = compile;
async function compile(srcFile, options) { async function compile(srcFile, options) {
options.p = options.p || Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617"); options.prime = options.prime || Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
if (!options) { if (!options) {
options = {}; options = {};
} }
if (typeof options.reduceConstraints === "undefined") { if (typeof options.reduceConstraints === "undefined") {
options.reduceConstraints = true; options.reduceConstraints = true;
} }
const ctx = new Ctx(options.p); const ctx = new Ctx(options.prime);
ctx.verbose= options.verbose || false; ctx.verbose= options.verbose || false;
ctx.mainComponent = options.mainComponent || "main"; ctx.mainComponent = options.mainComponent || "main";
ctx.newThreadTemplates = options.newThreadTemplates; ctx.newThreadTemplates = options.newThreadTemplates;
@@ -82,7 +82,8 @@ async function compile(srcFile, options) {
} }
if (options.cSourceWriteStream) { if (options.cSourceWriteStream) {
ctx.builder = new BuilderC(options.p); if (ctx.verbose) console.log("Generating c...");
ctx.builder = new BuilderC(options.prime);
build(ctx); build(ctx);
const rdStream = ctx.builder.build(); const rdStream = ctx.builder.build();
rdStream.pipe(options.cSourceWriteStream); rdStream.pipe(options.cSourceWriteStream);
@@ -91,7 +92,8 @@ async function compile(srcFile, options) {
} }
if ((options.wasmWriteStream)||(options.watWriteStream)) { 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); build(ctx);
if (options.wasmWriteStream) { if (options.wasmWriteStream) {
const rdStream = ctx.builder.build("wasm"); const rdStream = ctx.builder.build("wasm");