Browse Source

deps and verbos

master
Jordi Baylina 4 years ago
parent
commit
744d3b241c
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
6 changed files with 25 additions and 16 deletions
  1. +1
    -1
      TUTORIAL.md
  2. +10
    -1
      cli.js
  3. +1
    -1
      package.json
  4. +1
    -1
      ports/c/builder.js
  5. +6
    -8
      ports/wasm/build_runtime.js
  6. +6
    -4
      src/compiler.js

+ 1
- 1
TUTORIAL.md

@ -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`.
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**

+ 10
- 1
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.sym) {
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;

+ 1
- 1
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",

+ 1
- 1
ports/c/builder.js

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

+ 6
- 8
ports/wasm/build_runtime.js

@ -728,12 +728,9 @@ module.exports = function buildRuntime(module, builder) {
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 @@ module.exports = function buildRuntime(module, builder) {
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 @@ module.exports = function buildRuntime(module, builder) {
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);
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);

+ 6
- 4
src/compiler.js

@ -32,14 +32,14 @@ const buildSyms = require("./buildsyms");
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 @@ async function compile(srcFile, options) {
}
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 @@ async function compile(srcFile, options) {
}
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");

Loading…
Cancel
Save