mirror of
https://github.com/arnaucube/websnark.git
synced 2026-02-27 21:46:42 +01:00
allow buildpkey & buildwitness to be called from js code in addition to cli usage
This commit is contained in:
@@ -34,17 +34,17 @@ You can use the tool to build the binary file from the witness.json file generat
|
|||||||
### IMPORTANT: Please be sure you run your setup with `--protocol groth` websnark only generates groth16 proofs!
|
### IMPORTANT: Please be sure you run your setup with `--protocol groth` websnark only generates groth16 proofs!
|
||||||
|
|
||||||
```
|
```
|
||||||
node ../tools/buildwitness.js -i witness.json -o witness.bin
|
node ../tools/buildwitness_cli.js -i witness.json -o witness.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
provingKey is the binary buffer with the binary representation of the proving key.
|
provingKey is the binary buffer with the binary representation of the proving key.
|
||||||
|
|
||||||
Check the tool tools/buildpkey.js to convert a proving_key.json file generated
|
Check the tool tools/buildpkey_cli.js to convert a proving_key.json file generated
|
||||||
in [snarkjs](https://github.com/iden3/snarkjs) to a proving_key.bin file that can
|
in [snarkjs](https://github.com/iden3/snarkjs) to a proving_key.bin file that can
|
||||||
be used directly with this library.
|
be used directly with this library.
|
||||||
|
|
||||||
```
|
```
|
||||||
node ../tools/buildpkey.js -i proving_key.json -o proving_key.bin
|
node ../tools/buildpkey_cli.js -i proving_key.json -o proving_key.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
The result is a JSON object with pi_a, pi_b and pi_c points.
|
The result is a JSON object with pi_a, pi_b and pi_c points.
|
||||||
|
|||||||
@@ -1,36 +1,6 @@
|
|||||||
const {unstringifyBigInts} = require("./stringifybigint.js");
|
|
||||||
const fs = require("fs");
|
|
||||||
const bigInt = require("big-integer");
|
const bigInt = require("big-integer");
|
||||||
const assert = require("assert");
|
const assert = require("assert");
|
||||||
|
|
||||||
const version = require("../package").version;
|
|
||||||
|
|
||||||
const argv = require("yargs")
|
|
||||||
.version(version)
|
|
||||||
.usage(`node buildpkey.js -i "proving_key.json" -o "proving_key.bin"
|
|
||||||
Default: circuit.json
|
|
||||||
`)
|
|
||||||
.alias("i", "input")
|
|
||||||
.alias("o", "output")
|
|
||||||
.help("h")
|
|
||||||
.alias("h", "help")
|
|
||||||
.epilogue(`Copyright (C) 2018 0kims association
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY;
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; see the COPYING file in the official
|
|
||||||
repo directory at https://github.com/iden3/circom `)
|
|
||||||
.argv;
|
|
||||||
|
|
||||||
const inputName = (argv.input) ? argv.input : "proving_key.json";
|
|
||||||
const outputName = (argv.output) ? argv.output : "proving_key.bin";
|
|
||||||
|
|
||||||
|
|
||||||
const provingKey = unstringifyBigInts(JSON.parse(fs.readFileSync(inputName, "utf8")));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function writeUint32(h, val) {
|
function writeUint32(h, val) {
|
||||||
h.dataView.setUint32(h.offset, val, true);
|
h.dataView.setUint32(h.offset, val, true);
|
||||||
h.offset += 4;
|
h.offset += 4;
|
||||||
@@ -117,6 +87,7 @@ function calculateBuffLen(provingKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function buildPKey(provingKey) {
|
||||||
const buffLen = calculateBuffLen(provingKey);
|
const buffLen = calculateBuffLen(provingKey);
|
||||||
|
|
||||||
const buff = new ArrayBuffer(buffLen);
|
const buff = new ArrayBuffer(buffLen);
|
||||||
@@ -181,9 +152,10 @@ for (let i=0; i<provingKey.domainSize; i++) {
|
|||||||
|
|
||||||
assert.equal(h.offset, buffLen);
|
assert.equal(h.offset, buffLen);
|
||||||
|
|
||||||
var wstream = fs.createWriteStream(outputName);
|
return Buffer.from(buff);
|
||||||
wstream.write(Buffer.from(buff));
|
}
|
||||||
wstream.end();
|
|
||||||
|
module.exports = buildPKey;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NSignals
|
NSignals
|
||||||
|
|||||||
34
tools/buildpkey_cli.js
Normal file
34
tools/buildpkey_cli.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
const {unstringifyBigInts} = require("./stringifybigint.js");
|
||||||
|
const buildPKey = require("./buildpkey.js");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const version = require("../package").version;
|
||||||
|
|
||||||
|
const argv = require("yargs")
|
||||||
|
.version(version)
|
||||||
|
.usage(`node buildpkey.js -i "proving_key.json" -o "proving_key.bin"
|
||||||
|
Default: circuit.json
|
||||||
|
`)
|
||||||
|
.alias("i", "input")
|
||||||
|
.alias("o", "output")
|
||||||
|
.help("h")
|
||||||
|
.alias("h", "help")
|
||||||
|
.epilogue(`Copyright (C) 2018 0kims association
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY;
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; see the COPYING file in the official
|
||||||
|
repo directory at https://github.com/iden3/circom `)
|
||||||
|
.argv;
|
||||||
|
|
||||||
|
const inputName = (argv.input) ? argv.input : "proving_key.json";
|
||||||
|
const outputName = (argv.output) ? argv.output : "proving_key.bin";
|
||||||
|
|
||||||
|
|
||||||
|
const provingKey = unstringifyBigInts(JSON.parse(fs.readFileSync(inputName, "utf8")));
|
||||||
|
|
||||||
|
const bin = buildPKey(provingKey);
|
||||||
|
|
||||||
|
var wstream = fs.createWriteStream(outputName);
|
||||||
|
wstream.write(bin);
|
||||||
|
wstream.end();
|
||||||
|
|
||||||
@@ -1,32 +1,5 @@
|
|||||||
const {unstringifyBigInts} = require("./stringifybigint.js");
|
|
||||||
const fs = require("fs");
|
|
||||||
const assert = require("assert");
|
const assert = require("assert");
|
||||||
|
|
||||||
const version = require("../package").version;
|
|
||||||
|
|
||||||
const argv = require("yargs")
|
|
||||||
.version(version)
|
|
||||||
.usage(`node buildpkey.js -i "witness.json" -o "witness.bin"
|
|
||||||
Default: circuit.json
|
|
||||||
`)
|
|
||||||
.alias("i", "input")
|
|
||||||
.alias("o", "output")
|
|
||||||
.help("h")
|
|
||||||
.alias("h", "help")
|
|
||||||
.epilogue(`Copyright (C) 2018 0kims association
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY;
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; see the COPYING file in the official
|
|
||||||
repo directory at https://github.com/iden3/circom `)
|
|
||||||
.argv;
|
|
||||||
|
|
||||||
const inputName = (argv.input) ? argv.input : "witness.json";
|
|
||||||
const outputName = (argv.output) ? argv.output : "witness.bin";
|
|
||||||
|
|
||||||
|
|
||||||
const witness = unstringifyBigInts(JSON.parse(fs.readFileSync(inputName, "utf8")));
|
|
||||||
|
|
||||||
|
|
||||||
function writeUint32(h, val) {
|
function writeUint32(h, val) {
|
||||||
h.dataView.setUint32(h.offset, val, true);
|
h.dataView.setUint32(h.offset, val, true);
|
||||||
h.offset += 4;
|
h.offset += 4;
|
||||||
@@ -42,7 +15,6 @@ function writeBigInt(h, bi) {
|
|||||||
|
|
||||||
|
|
||||||
function calculateBuffLen(witness) {
|
function calculateBuffLen(witness) {
|
||||||
|
|
||||||
let size = 0;
|
let size = 0;
|
||||||
|
|
||||||
// beta2, delta2
|
// beta2, delta2
|
||||||
@@ -52,6 +24,7 @@ function calculateBuffLen(witness) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function buildWitness(witness) {
|
||||||
const buffLen = calculateBuffLen(witness);
|
const buffLen = calculateBuffLen(witness);
|
||||||
|
|
||||||
const buff = new ArrayBuffer(buffLen);
|
const buff = new ArrayBuffer(buffLen);
|
||||||
@@ -61,7 +34,6 @@ const h = {
|
|||||||
offset: 0
|
offset: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// writeUint32(h, witness.length);
|
// writeUint32(h, witness.length);
|
||||||
|
|
||||||
for (let i=0; i<witness.length; i++) {
|
for (let i=0; i<witness.length; i++) {
|
||||||
@@ -70,7 +42,7 @@ for (let i=0; i<witness.length; i++) {
|
|||||||
|
|
||||||
assert.equal(h.offset, buffLen);
|
assert.equal(h.offset, buffLen);
|
||||||
|
|
||||||
var wstream = fs.createWriteStream(outputName);
|
return Buffer.from(buff);
|
||||||
wstream.write(Buffer.from(buff));
|
}
|
||||||
wstream.end();
|
|
||||||
|
|
||||||
|
module.exports = buildWitness;
|
||||||
|
|||||||
33
tools/buildwitness_cli.js
Normal file
33
tools/buildwitness_cli.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const {unstringifyBigInts} = require("./stringifybigint.js");
|
||||||
|
const buildWitness = require("./buildwitness.js");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const version = require("../package").version;
|
||||||
|
|
||||||
|
const argv = require("yargs")
|
||||||
|
.version(version)
|
||||||
|
.usage(`node buildpkey.js -i "witness.json" -o "witness.bin"
|
||||||
|
Default: circuit.json
|
||||||
|
`)
|
||||||
|
.alias("i", "input")
|
||||||
|
.alias("o", "output")
|
||||||
|
.help("h")
|
||||||
|
.alias("h", "help")
|
||||||
|
.epilogue(`Copyright (C) 2018 0kims association
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY;
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; see the COPYING file in the official
|
||||||
|
repo directory at https://github.com/iden3/circom `)
|
||||||
|
.argv;
|
||||||
|
|
||||||
|
const inputName = (argv.input) ? argv.input : "witness.json";
|
||||||
|
const outputName = (argv.output) ? argv.output : "witness.bin";
|
||||||
|
|
||||||
|
const witness = unstringifyBigInts(JSON.parse(fs.readFileSync(inputName, "utf8")));
|
||||||
|
|
||||||
|
const bin = buildWitness(witness);
|
||||||
|
|
||||||
|
var wstream = fs.createWriteStream(outputName);
|
||||||
|
wstream.write(bin);
|
||||||
|
wstream.end();
|
||||||
|
|
||||||
Reference in New Issue
Block a user