tutorial and many fixes
This commit is contained in:
parent
e739634579
commit
4fcc0a3398
401
README.md
401
README.md
@ -1,133 +1,360 @@
|
||||
# snarkjs: JavaScript implementation of zkSNARKs.
|
||||
|
||||
This is a JavaScript implementation of zkSNARK schemes. It allows the original 8points protocol
|
||||
and the Groth Protocol (3 point only and 3 pairings)
|
||||
This is a JavaScript and Pure Web Assembly implementation of zkSNARK schemes. It uses the Groth16 Protocol (3 point only and 3 pairings)
|
||||
|
||||
This library allows to do the trusted setup, generate proofs and verify the proofs.
|
||||
This library includes all the tools for the Trusted setup multiparty ceremony.
|
||||
This includes the universal ceremony "powers of tau".
|
||||
And the per circuit phase 2 ceremony.
|
||||
|
||||
This library uses the compiled circuits generated by the jaz compiler.
|
||||
The formats used in this library for the multipary computation are compatible with the ones used in other (implementations in rust)[].
|
||||
|
||||
### Tutorial.
|
||||
This library uses the compiled circuits generated by the circom compiler.
|
||||
|
||||
A good starting point [is this tutorial](https://github.com/iden3/circom/blob/master/TUTORIAL.md)
|
||||
The library works in nodejs and browser.
|
||||
|
||||
Also this [video](https://www.youtube.com/watch?v=-9TJa1hVsKA) is a good starting point.
|
||||
It's a ESM module, so it can be directly imported from bigger projects using rollup or webpack.
|
||||
|
||||
## Install.
|
||||
The low level criptography is done directly in wasm. And it uses working threads to parallelize the computations. The result is a high performance library with benchmarks comparable with implementations running in the host.
|
||||
|
||||
## Usage / Tutorial.
|
||||
|
||||
### Install snarkjs and circom
|
||||
```sh
|
||||
npm install snarkjs
|
||||
npm install -g circom
|
||||
npm install -g snarkjs
|
||||
```
|
||||
|
||||
## Usage from command line.
|
||||
|
||||
### Help
|
||||
|
||||
```sh
|
||||
snarkjs --help
|
||||
```
|
||||
|
||||
Will show all the info in how to use the cli.
|
||||
In commands that takes long time, you can add the -v or --verbose option to see the progress.
|
||||
|
||||
## Usage from javascript
|
||||
The help for specific command:
|
||||
|
||||
|
||||
### Import.
|
||||
|
||||
```js
|
||||
const zkSnark = require("snarkjs");
|
||||
Example
|
||||
```sh
|
||||
snarkjs groth16 prove --help
|
||||
```
|
||||
|
||||
### Load a circuit.
|
||||
Most of the commands have a shor alias.
|
||||
|
||||
```js
|
||||
// "myCircuit.cir" is the output of the jaz compiler
|
||||
For example, the previos command can also be invoked as:
|
||||
|
||||
const circuitDef = JSON.parse(fs.readFileSync("myCircuit.cir", "utf8"));
|
||||
const circuit = new zkSnark.Circuit(circuitDef);
|
||||
```sh
|
||||
snarkjs g16p --help
|
||||
```
|
||||
|
||||
### Inspect the circuit.
|
||||
|
||||
```js
|
||||
// `signalId` can always be a number or an alias string
|
||||
### Start a new ceremony.
|
||||
|
||||
circuit.nConstraints; // number of constraints
|
||||
circuit.nSignals; // number of signals
|
||||
circuit.nPublic; // number of public signals (nOutputs + nPublicInputs)
|
||||
|
||||
// The array of signals is always sorted in this order:
|
||||
// [ 1, outputs, publicInputs, privateInputs, internalSignals, constants]
|
||||
|
||||
// returns a,b and c coeficients of the `signalId` on a given `constraint`
|
||||
circuit.a(constraint, signalId)
|
||||
circuit.b(constraint, signalId)
|
||||
circuit.c(constraint, signalId)
|
||||
|
||||
circuit.nOutputs // number of public outputs
|
||||
circuit.pubInputs // number of public inputs
|
||||
circuit.nPrvInputs // number of private inputs
|
||||
circuit.nInputs // number of inputs ( nPublicInputs + nPrivateInputs)
|
||||
circuit.nVars // number of variables ( not including constants (one is a variable) )
|
||||
circuit.nSignals // number of signals ( including constants )
|
||||
|
||||
circuit.outputIdx(i) // returns the index of the i'th output
|
||||
circuit.inputIdx(i) // returns the index of the i'th input
|
||||
circuit.pubInputIdx(i) // returns the index of the i'th public input
|
||||
circuit.prvInputIdx(i) // returns the index of the i'th private input
|
||||
circuit.varIdx(i) // returns the index of the i'th variable
|
||||
circuit.constantIdx(i) // returns the index of the i'th constant
|
||||
circuit.signalIdx(i) // returns the index of the i'th signal
|
||||
|
||||
// returns signal Idx given a signalId
|
||||
// if the idx >= n , it is a constant
|
||||
// if the idx == -1, the signal does not exist
|
||||
circuit.getSignalIdx(name);
|
||||
|
||||
// returns an array aliases names of the i'th signal
|
||||
circuit.signalNames(i)
|
||||
|
||||
// input is a key value object where keys are the signal names
|
||||
// of all the inputs (public and private)
|
||||
// returns an array of values representing the witness
|
||||
circuit.calculateWitness(input)
|
||||
```sh
|
||||
snarkjs powersoftau new bn128 12 pot12_0000.ptau
|
||||
```
|
||||
|
||||
### Trusted setup.
|
||||
You can also use bls12-381 as the curve.
|
||||
|
||||
```js
|
||||
const setup = zkSnark.setup(circuit);
|
||||
fs.writeFileSync("myCircuit.vk_proof", JSON.stringify(setup.vk_proof), "utf8");
|
||||
fs.writeFileSync("myCircuit.vk_verifier", JSON.stringify(setup.vk_verifier), "utf8");
|
||||
setup.toxic // Must be discarded.
|
||||
The secons parameter is the power of two of the maximum number of contraints that can accept this ceremony.
|
||||
|
||||
In this case 12 means that the maximum constraints will be 2**12 = 4096
|
||||
|
||||
### Contribute in the ceremony
|
||||
```sh
|
||||
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="Example Name" -v
|
||||
```
|
||||
|
||||
### Generate proof.
|
||||
The name is a random name and it's include for reference. It's printed in the verification.
|
||||
|
||||
```js
|
||||
const circuitDef = JSON.parse(fs.readFileSync("myCircuit.cir", "utf8"));
|
||||
const circuit = new zkSnark.Circuit(circuitDef);
|
||||
const input = {
|
||||
"main.pubIn1": "123",
|
||||
"main.out1": "456"
|
||||
### Do a second contribution
|
||||
```sh
|
||||
snarkjs powersoftau contribute pot12_0001.ptau pot12_0002.ptau --name="Second contribution Name" -v -e="some random text"
|
||||
```
|
||||
|
||||
the -e parameter allows the comman to be non interactive and use this text as an extra source of entropy for the random generation.
|
||||
|
||||
|
||||
### Verify the file
|
||||
```sh
|
||||
snarkjs powersoftau verify pot12_0002.ptau
|
||||
```
|
||||
|
||||
This command checks all the contributions of the Multiparty Computation (MPC) and list the hashes of the
|
||||
intermediary results.
|
||||
|
||||
### Contribute using ther party software.
|
||||
|
||||
```sh
|
||||
snarkjs powersoftau export challange pot12_0002.ptau challange_0003
|
||||
snarkjs powersoftau challange contribute bn128 challange_0003 response_0003
|
||||
snarkjs powersoftau import response pot12_0002.ptau response_0003 pot12_0003.ptau -n="Third contribution name"
|
||||
```
|
||||
|
||||
|
||||
### Add a beacon
|
||||
```sh
|
||||
snarkjs powersoftau beacon pot12_0003.ptau pot12_beacon.ptau 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon"
|
||||
```
|
||||
|
||||
### Prepare phase2
|
||||
```sh
|
||||
powersoftau prepare phase2 pot12_beacon.ptau pot12_final.ptau -v
|
||||
```
|
||||
|
||||
### Verify the last file
|
||||
```sh
|
||||
snarkjs powersoftau verify pot12_final.ptau
|
||||
```
|
||||
|
||||
### Create a circuit
|
||||
```sh
|
||||
mkdir mycircuit
|
||||
cd my mycircuit
|
||||
cat <<EOT > circuit.circom
|
||||
template Multiplier(n) {
|
||||
signal private input a;
|
||||
signal private input b;
|
||||
signal output c;
|
||||
|
||||
signal int[n];
|
||||
|
||||
int[0] <== a*a + b;
|
||||
for (var i=1; i<n; i++) {
|
||||
int[i] <== int[i-1]*int[i-1] + b;
|
||||
}
|
||||
|
||||
c <== int[n-1];
|
||||
}
|
||||
const witness = circuit.calculateWitness(input);
|
||||
const vk_proof = JSON.parse(fs.readFileSync("myCircuit.vk_proof", "utf8"));
|
||||
|
||||
const {proof, publicSignals} = zkSnark.genProof(vk_proof, witness);
|
||||
component main = Multiplier(1000);
|
||||
EOT
|
||||
```
|
||||
|
||||
### Verifier.
|
||||
This is an example circom fille that allows to test the system with different number of contraints.
|
||||
|
||||
In this case 1000, but it can be changed to any nomber of constraints.
|
||||
|
||||
### compile the circuit
|
||||
```sh
|
||||
circom circuit.circom -r -w -s -v
|
||||
```
|
||||
|
||||
-r to generate the .r1cs file
|
||||
-w to generate the .wasm file that computes the witness from an input.
|
||||
-s to generate the .sym file that contains the human readable names of all signals. (Important to debug the circuit)
|
||||
-v Verbose. To see the progress of the compilation.
|
||||
|
||||
### info of a circuit
|
||||
```sh
|
||||
snarkjs r1cs info circuit.r1cs
|
||||
```
|
||||
|
||||
### Print the constraints
|
||||
```sh
|
||||
snarkjs r1cs print circuit.r1cs
|
||||
```
|
||||
|
||||
### export r1cs to json
|
||||
```sh
|
||||
snarkjs r1cs export json circuit.r1cs circuit.r1cs.json
|
||||
```
|
||||
|
||||
|
||||
### Generate the reference zKey without contributions from the circuit.
|
||||
```sh
|
||||
snarkjs zkey new circuit.r1cs pot12_final.ptau circuit_0000.zkey
|
||||
```
|
||||
|
||||
circuit_0000.zkey does not include any contribution yet, so it cannot be used in a final circuit.
|
||||
|
||||
### Contribute in the phase2 ceremony
|
||||
```sh
|
||||
snarkjs zkey contribute circuit_0000.zkey circuit_0001.zkey --name="1st Contributor Name" -v
|
||||
```
|
||||
|
||||
### Do a second phase2 contribution
|
||||
```sh
|
||||
snarkjs zkey contribute circuit_0001.zkey circuit_0002.zkey --name="Second contribution Name" -v -e="Another random entropy"
|
||||
```
|
||||
|
||||
|
||||
### Verify the zkey file
|
||||
```sh
|
||||
snarkjs zkey verify circuit.r1cs pot12_final.ptau circuit_0002.zkey
|
||||
```
|
||||
|
||||
|
||||
### Contribute using third party software.
|
||||
|
||||
```sh
|
||||
snarkjs zkey export bellman circuit_0002.zkey challange_phase2_0003
|
||||
snarkjs zkey bellman contribute bn128 challange_phase2_0003 response_phase2_0003
|
||||
snarkjs zkey import bellman circuit_0002.zkey response_phase2_0003 circuit_0003.zkey -n="Third contribution name"
|
||||
```
|
||||
|
||||
|
||||
### Add a beacon
|
||||
```sh
|
||||
snarkjs zkey beacon circuit_0003.zkey circuit_final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
|
||||
```
|
||||
|
||||
### Verify the final file
|
||||
```sh
|
||||
snarkjs zkey verify circuit.r1cs pot12_final.ptau circuit_final.zkey
|
||||
```
|
||||
|
||||
### Export the verification key
|
||||
```sh
|
||||
snarkjs zkey export verificationkey circuit_final.zkey verification_key.json
|
||||
```
|
||||
|
||||
### Calculat witess
|
||||
```sh
|
||||
cat <<EOT > input.json
|
||||
{"a": 3, "b": 11}
|
||||
EOT
|
||||
snarkjs wtns calculate circuit.wasm input.json witness.wtns
|
||||
```
|
||||
|
||||
|
||||
### Debug witness calculation
|
||||
|
||||
In general, when you are developing a new circuit you will want to check for some errors in the witness calculation process.
|
||||
|
||||
You can do it by doing
|
||||
```sh
|
||||
snarkjs wtns debug circuit.wasm input.json witness.wtns circuit.sym --trigger --get --set
|
||||
```
|
||||
|
||||
This will log every time a new component is started/ended ( --trigger ) when a signal is set (--set) and when it's get (--get)
|
||||
|
||||
|
||||
### Proof calculation
|
||||
```sh
|
||||
snarkjs groth16 prove circuit_final.zkey witness.wtns proof.json public.json
|
||||
```
|
||||
|
||||
It is possible also to do the calculate witness and the prove calculation in the same command:
|
||||
```sh
|
||||
snarkjs groth16 fullprove input.json circuit.wasm circuit_final.zkey proof.json public.json
|
||||
```
|
||||
|
||||
|
||||
### Verify
|
||||
```sh
|
||||
snarkjs groth16 verify verification_key.json public.json proof.json
|
||||
```
|
||||
|
||||
### Export Solidity Verifier
|
||||
```sh
|
||||
snarkjs zkey export solidityverifier circuit_final.zkey verifier.sol
|
||||
```
|
||||
|
||||
You can deploy th "Verifier" smartcontract using remix for example.
|
||||
|
||||
In order to simulate a verification call, you can do:
|
||||
|
||||
```sh
|
||||
zkey export soliditycalldata public.json proof.json
|
||||
```
|
||||
|
||||
And cut and paste the resolt directlly in the "verifyProof" field in the deployed smart contract.
|
||||
|
||||
This call will return true if the proof and the public data is valid.
|
||||
|
||||
|
||||
## Use in node
|
||||
|
||||
```sh
|
||||
npm install snarkjs
|
||||
```
|
||||
|
||||
```js
|
||||
const vk_verifier = JSON.parse(fs.readFileSync("myCircuit.vk_verifier", "utf8"));
|
||||
const snarkjs = require("snarkjs");
|
||||
const fs = require("fs");
|
||||
|
||||
async function run() {
|
||||
const { proof, publicSignals } = await snarkjs.groth16.fullProve({a: 10, b: 21}, "circuit.wasm", "circuit_final.zkey");
|
||||
|
||||
console.log("Proof: ");
|
||||
console.log(JSON.stringify(proof, null, 1));
|
||||
|
||||
const vKey = JSON.parse(fs.readFileSync("verification_key.json"));
|
||||
|
||||
const res = await snarkjs.groth16.verify(vKey, publicSignals, proof);
|
||||
|
||||
if (res === true) {
|
||||
console.log("Verification OK");
|
||||
} else {
|
||||
console.log("Invalid proof");
|
||||
}
|
||||
|
||||
if (zkSnark.isValid(vk_verifier, proof, publicSignals)) {
|
||||
console.log("The proof is valid");
|
||||
} else {
|
||||
console.log("The proof is not valid");
|
||||
}
|
||||
|
||||
run().then(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
```
|
||||
|
||||
## Use in the web
|
||||
|
||||
load snarkjs.min.js and start using it normally.
|
||||
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Snarkjs client example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Snarkjs client example</h1>
|
||||
<button id="bGenProof"> Create proof </button>
|
||||
|
||||
<!-- JS-generated output will be added here. -->
|
||||
<pre class="proof"> Proof: <code id="proof"></code></pre>
|
||||
|
||||
<pre class="proof"> Result: <code id="result"></code></pre>
|
||||
|
||||
|
||||
<script src="snarkjs.min.js"> </script>
|
||||
|
||||
|
||||
<!-- This is the bundle generated by rollup.js -->
|
||||
<script>
|
||||
|
||||
const proofCompnent = document.getElementById('proof');
|
||||
const resultComponent = document.getElementById('result');
|
||||
const bGenProof = document.getElementById("bGenProof");
|
||||
|
||||
bGenProof.addEventListener("click", calculateProof);
|
||||
|
||||
async function calculateProof() {
|
||||
|
||||
const { proof, publicSignals } =
|
||||
await snarkjs.groth16.fullProve( { a: 3, b: 11}, "circuit.wasm", "circuit_final.zkey");
|
||||
|
||||
proofCompnent.innerHTML = JSON.stringify(proof, null, 1);
|
||||
|
||||
|
||||
const vkey = await fetch("verification_key.json").then( function(res) {
|
||||
return res.json();
|
||||
});
|
||||
|
||||
const res = await snarkjs.groth16.verify(vkey, publicSignals, proof);
|
||||
|
||||
resultComponent.innerHTML = res;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
snarkjs is part of the iden3 project copyright 2018 0KIMS association and published with GPL-3 license. Please check the COPYING file for more details.
|
||||
|
212
TUTORIAL.md
212
TUTORIAL.md
@ -1,212 +0,0 @@
|
||||
### Install snarkjs and circom
|
||||
```sh
|
||||
npm install -g circom
|
||||
npm install -g snarkjs
|
||||
```
|
||||
|
||||
### Help
|
||||
|
||||
```sh
|
||||
snarkjs
|
||||
```
|
||||
|
||||
In commands that takes long time, you can add the -v or --verbose option to see the progress.
|
||||
|
||||
|
||||
|
||||
### Start a new ceremony.
|
||||
|
||||
```sh
|
||||
snarkjs powersoftau new bn128 12 pot12_0000.ptau
|
||||
```
|
||||
|
||||
### Contribute in the ceremony
|
||||
```sh
|
||||
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="Example Name" -v
|
||||
```
|
||||
|
||||
### Do a second contribution
|
||||
```sh
|
||||
snarkjs powersoftau contribute pot12_0001.ptau pot12_0002.ptau --name="Second contribution Name" -v
|
||||
```
|
||||
|
||||
|
||||
### Verify the file
|
||||
```sh
|
||||
snarkjs powersoftau verify pot12_0002.ptau
|
||||
```
|
||||
|
||||
|
||||
### Contribute using ther party software.
|
||||
|
||||
```sh
|
||||
snarkjs powersoftau export challange pot12_0002.ptau challange_0003
|
||||
snarkjs powersoftau challange contribute bn128 challange_0003 response_0003
|
||||
snarkjs powersoftau import response pot12_0002.ptau response_0003 pot12_0003.ptau -n="Third contribution name"
|
||||
```
|
||||
|
||||
|
||||
### Add a beacon
|
||||
```sh
|
||||
snarkjs powersoftau beacon pot12_0003.ptau pot12_beacon.ptau 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon"
|
||||
```
|
||||
|
||||
### Prepare phase2
|
||||
```sh
|
||||
powersoftau prepare phase2 pot12_beacon.ptau pot12_final.ptau -v
|
||||
```
|
||||
|
||||
### Verify the last file
|
||||
```sh
|
||||
snarkjs powersoftau verify pot12_final.ptau
|
||||
```
|
||||
|
||||
### Create a circuit
|
||||
```sh
|
||||
mkdir mycircuit
|
||||
cd my mycircuit
|
||||
cat <<EOT > circuit.circom
|
||||
template Multiplier(n) {
|
||||
signal private input a;
|
||||
signal private input b;
|
||||
signal output c;
|
||||
|
||||
signal int[n];
|
||||
|
||||
int[0] <== a*a + b;
|
||||
for (var i=1; i<n; i++) {
|
||||
int[i] <== int[i-1]*int[i-1] + b;
|
||||
}
|
||||
|
||||
c <== int[n-1];
|
||||
}
|
||||
|
||||
component main = Multiplier(1000);
|
||||
EOT
|
||||
```
|
||||
|
||||
### compile the circuit
|
||||
```sh
|
||||
circom circuit.circom -r -w -s -v
|
||||
```
|
||||
|
||||
### info of a circuit
|
||||
```sh
|
||||
snarkjs r1cs info circuit.r1cs
|
||||
```
|
||||
|
||||
### Print the constraints
|
||||
```sh
|
||||
snarkjs r1cs print circuit.r1cs
|
||||
```
|
||||
|
||||
### export r1cs to json
|
||||
```sh
|
||||
snarkjs r1cs export json circuit.r1cs circuit.r1cs.json
|
||||
```
|
||||
|
||||
|
||||
### Generate the reference zKey without contributions from the circuit.
|
||||
```sh
|
||||
snarkjs zkey new circuit.r1cs pot12_final.ptau circuit_0000.zkey
|
||||
```
|
||||
|
||||
|
||||
### Contribute in the phase2 ceremony
|
||||
```sh
|
||||
snarkjs zkey contribute circuit_0000.zkey circuit_0001.zkey --name="1st Contributor Name" -v
|
||||
```
|
||||
|
||||
### Do a second phase2 contribution
|
||||
```sh
|
||||
snarkjs zkey contribute circuit_0001.zkey circuit_0002.zkey --name="Second contribution Name" -v
|
||||
```
|
||||
|
||||
|
||||
### Verify the zkey file
|
||||
```sh
|
||||
snarkjs zkey verify circuit.r1cs pot12_final.ptau circuit_0002.zkey
|
||||
```
|
||||
|
||||
|
||||
### Contribute using ther party software.
|
||||
|
||||
```sh
|
||||
snarkjs zkey export bellman circuit_0002.zkey challange_phase2_0003
|
||||
snarkjs zkey bellman contribute bn128 challange_phase2_0003 response_phase2_0003
|
||||
snarkjs zkey import bellman circuit_0002.zkey response_phase2_0003 circuit_0003.zkey -n="Third contribution name"
|
||||
```
|
||||
|
||||
|
||||
### Add a beacon
|
||||
```sh
|
||||
snarkjs zkey beacon circuit_0003.zkey circuit_final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
|
||||
```
|
||||
|
||||
### Verify the final file
|
||||
```sh
|
||||
snarkjs zkey verify circuit.r1cs pot12_final.ptau circuit_final.zkey
|
||||
```
|
||||
|
||||
### Export the verification key
|
||||
```sh
|
||||
snarkjs zkey export verificationkey circuit_final.zkey verification_key.json
|
||||
```
|
||||
|
||||
### Calculat witess
|
||||
```sh
|
||||
cat <<EOT > input.json
|
||||
{"a": 3, "b": 11}
|
||||
EOT
|
||||
snarkjs wtns calculate circuit.wasm input.json witness.wtns
|
||||
```
|
||||
|
||||
|
||||
### Debug witness calculation
|
||||
|
||||
En general when you are developing a new circuit you will want to check for some errors in the witness calculation process.
|
||||
|
||||
You can do it by doing
|
||||
```sh
|
||||
snarkjs wtns debug circuit.wasm input.json witness.wtns circuit.sym --trigger --get --set
|
||||
```
|
||||
|
||||
This will log every time a new component is started/ended ( --trigger ) when a signal is set (--set) and when it's get (--get)
|
||||
|
||||
|
||||
### Proof calculation
|
||||
```sh
|
||||
snarkjs groth16 prove circuit_final.zkey witness.wtns proof.json public.json
|
||||
```
|
||||
|
||||
It is possible also to do the calculate witness and the prove calculation in the same command:
|
||||
```sh
|
||||
snarkjs groth16 fullprove input.json circuit.wasm circuit_final.zkey proof.json public.json
|
||||
```
|
||||
|
||||
|
||||
### Verify
|
||||
```sh
|
||||
snarkjs groth16 verify verification_key.json public.json proof.json
|
||||
```
|
||||
|
||||
### Export Solidity Verifier
|
||||
```sh
|
||||
snarkjs zkey export solidityverifier circuit_final.zkey verifier.sol
|
||||
```
|
||||
|
||||
You can deploy th "Verifier" smartcontract using remix for example.
|
||||
|
||||
In order to simulate a verification call, you can do:
|
||||
|
||||
```sh
|
||||
zkey export soliditycalldata public.json proof.json
|
||||
```
|
||||
|
||||
And cut and paste the resolt directlly in the "verifyProof" field in the deployed smart contract.
|
||||
|
||||
This call will return true if the proof and the public data is valid.
|
||||
|
||||
|
||||
|
||||
|
270
build/cli.cjs
270
build/cli.cjs
@ -455,6 +455,9 @@ class MemFile {
|
||||
|
||||
}
|
||||
|
||||
/* global fetch */
|
||||
|
||||
|
||||
async function createOverride(o, b) {
|
||||
if (typeof o === "string") {
|
||||
o = {
|
||||
@ -472,24 +475,38 @@ async function createOverride(o, b) {
|
||||
}
|
||||
}
|
||||
|
||||
function readExisting$1(o, b) {
|
||||
async function readExisting$1(o, b) {
|
||||
if (o instanceof Uint8Array) {
|
||||
o = {
|
||||
type: "mem",
|
||||
data: o
|
||||
};
|
||||
}
|
||||
if (typeof o === "string") {
|
||||
o = {
|
||||
type: "file",
|
||||
fileName: o,
|
||||
cacheSize: b
|
||||
};
|
||||
if (process.browser) {
|
||||
if (typeof o === "string") {
|
||||
const buff = await fetch(o).then( function(res) {
|
||||
return res.arrayBuffer();
|
||||
}).then(function (ab) {
|
||||
return new Uint8Array(ab);
|
||||
});
|
||||
o = {
|
||||
type: "mem",
|
||||
data: buff
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (typeof o === "string") {
|
||||
o = {
|
||||
type: "file",
|
||||
fileName: o,
|
||||
cacheSize: b
|
||||
};
|
||||
}
|
||||
}
|
||||
if (o.type == "file") {
|
||||
return open(o.fileName, "r", o.cacheSize);
|
||||
return await open(o.fileName, "r", o.cacheSize);
|
||||
} else if (o.type == "mem") {
|
||||
return readExisting(o);
|
||||
return await readExisting(o);
|
||||
} else {
|
||||
throw new Error("Invalid FastFile type: "+o.type);
|
||||
}
|
||||
@ -734,10 +751,11 @@ var scripts = {
|
||||
test: "mocha",
|
||||
build: "rollup -c config/rollup.cjs.config.js",
|
||||
buildcli: "rollup -c config/rollup.cli.config.js",
|
||||
buildiife: "BROWSER=true rollup -c config/rollup.iife.config.js"
|
||||
buildiife: "BROWSER=true rollup -c config/rollup.iife.config.js",
|
||||
buildiifemin: "BROWSER=true rollup -c config/rollup.iife_min.config.js"
|
||||
};
|
||||
var bin = {
|
||||
snarkjs: "build/cli.js"
|
||||
snarkjs: "build/cli.cjs"
|
||||
};
|
||||
var directories = {
|
||||
templates: "templates"
|
||||
@ -760,11 +778,11 @@ var repository = {
|
||||
var dependencies = {
|
||||
"blake2b-wasm": "https://github.com/jbaylina/blake2b-wasm.git",
|
||||
circom_runtime: "0.0.8",
|
||||
fastfile: "0.0.5",
|
||||
fastfile: "0.0.6",
|
||||
ffjavascript: "0.2.2",
|
||||
keccak: "^3.0.0",
|
||||
logplease: "^1.2.15",
|
||||
r1csfile: "0.0.9",
|
||||
r1csfile: "0.0.10",
|
||||
yargs: "^12.0.5"
|
||||
};
|
||||
var devDependencies = {
|
||||
@ -777,7 +795,8 @@ var devDependencies = {
|
||||
"rollup-plugin-ignore": "^1.0.6",
|
||||
"rollup-plugin-json": "^4.0.0",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-replace": "^2.2.0"
|
||||
"rollup-plugin-replace": "^2.2.0",
|
||||
"rollup-plugin-terser": "^6.1.0"
|
||||
};
|
||||
var pkg = {
|
||||
name: name,
|
||||
@ -5203,7 +5222,7 @@ async function read(fileName) {
|
||||
|
||||
const {stringifyBigInts: stringifyBigInts$1} = ffjavascript.utils;
|
||||
|
||||
async function groth16ProofFromInput(zkeyFileName, witnessFileName, logger) {
|
||||
async function groth16Prove(zkeyFileName, witnessFileName, logger) {
|
||||
const {fd: fdWtns, sections: sectionsWtns} = await readBinFile$1(witnessFileName, "wtns", 2);
|
||||
|
||||
const wtns = await readHeader$1(fdWtns, sectionsWtns);
|
||||
@ -5298,7 +5317,6 @@ async function groth16ProofFromInput(zkeyFileName, witnessFileName, logger) {
|
||||
proof = stringifyBigInts$1(proof);
|
||||
publicSignals = stringifyBigInts$1(publicSignals);
|
||||
|
||||
|
||||
return {proof, publicSignals};
|
||||
}
|
||||
|
||||
@ -5457,12 +5475,12 @@ async function wtnsCalculate(input, wasmFileName, wtnsFileName, options) {
|
||||
|
||||
}
|
||||
|
||||
async function groth16ProofFromInput$1(input, wasmFile, zkeyFileName, logger) {
|
||||
async function groth16FullProve(input, wasmFile, zkeyFileName, logger) {
|
||||
const wtns= {
|
||||
type: "mem"
|
||||
};
|
||||
await wtnsCalculate(input, wasmFile, wtns);
|
||||
return await groth16ProofFromInput(zkeyFileName, wtns);
|
||||
return await groth16Prove(zkeyFileName, wtns);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -5485,7 +5503,7 @@ async function groth16ProofFromInput$1(input, wasmFile, zkeyFileName, logger) {
|
||||
*/
|
||||
const {unstringifyBigInts} = ffjavascript.utils;
|
||||
|
||||
async function isValid(vk_verifier, publicSignals, proof, logger) {
|
||||
async function groth16Verify(vk_verifier, publicSignals, proof, logger) {
|
||||
/*
|
||||
let cpub = vk_verifier.IC[0];
|
||||
for (let s= 0; s< vk_verifier.nPublic; s++) {
|
||||
@ -5649,13 +5667,6 @@ const commands = [
|
||||
options: "-verbose|v -nopoints -nocheck -name|n",
|
||||
action: powersOfTawImport
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau verify <powersoftau.ptau>",
|
||||
description: "verifies a powers of tau file",
|
||||
alias: ["ptv"],
|
||||
options: "-verbose|v",
|
||||
action: powersOfTawVerify
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau beacon <old_powersoftau.ptau> <new_powersoftau.ptau> <beaconHash(Hex)> <numIterationsExp>",
|
||||
description: "adds a beacon",
|
||||
@ -5671,6 +5682,13 @@ const commands = [
|
||||
options: "-verbose|v",
|
||||
action: powersOfTawPreparePhase2
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau verify <powersoftau.ptau>",
|
||||
description: "verifies a powers of tau file",
|
||||
alias: ["ptv"],
|
||||
options: "-verbose|v",
|
||||
action: powersOfTawVerify
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau export json <powersoftau_0000.ptau> <powersoftau_0000.json>",
|
||||
description: "Exports a power of tau file to a JSON",
|
||||
@ -5718,34 +5736,67 @@ const commands = [
|
||||
alias: ["wej"],
|
||||
action: wtnsExportJson$1
|
||||
},
|
||||
/*
|
||||
{
|
||||
cmd: "zksnark setup [circuit.r1cs] [circuit.zkey] [verification_key.json]",
|
||||
description: "Run a simple setup for a circuit generating the proving key.",
|
||||
alias: ["zs", "setup -r1cs|r -provingkey|pk -verificationkey|vk"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkSetup
|
||||
},
|
||||
*/
|
||||
{
|
||||
cmd: "groth16 prove [circuit.zkey] [witness.wtns] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from witness",
|
||||
alias: ["g16p", "zpw", "zksnark proof", "proof -pk|provingkey -wt|witness -p|proof -pub|public"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkProve
|
||||
cmd: "zkey new [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Creates an initial pkey file with zero contributions ",
|
||||
alias: ["zkn"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyNew
|
||||
},
|
||||
{
|
||||
cmd: "groth16 fullprove [input.json] [circuit.wasm] [circuit.zkey] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from input",
|
||||
alias: ["g16f", "g16i"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkFullProve
|
||||
cmd: "zkey contribute <circuit_old.zkey> <circuit_new.zkey>",
|
||||
description: "creates a zkey file with a new contribution",
|
||||
alias: ["zkc"],
|
||||
options: "-verbose|v -entropy|e -name|n",
|
||||
action: zkeyContribute
|
||||
},
|
||||
{
|
||||
cmd: "groth16 verify [verification_key.json] [public.json] [proof.json]",
|
||||
description: "Verify a zk Proof",
|
||||
alias: ["g16v", "verify -vk|verificationkey -pub|public -p|proof"],
|
||||
action: zksnarkVerify
|
||||
cmd: "zkey export bellman [circuit.zkey] [circuit.mpcparams]",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman)",
|
||||
alias: ["zkeb"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportBellman
|
||||
},
|
||||
{
|
||||
cmd: "zkey bellman contribute <curve> <circuit.mpcparams> <circuit_response.mpcparams>",
|
||||
description: "contributes to a llallange file in bellman format",
|
||||
alias: ["zkbc"],
|
||||
options: "-verbose|v -entropy|e",
|
||||
action: zkeyBellmanContribute
|
||||
},
|
||||
{
|
||||
cmd: "zkey import bellman <circuit_old.zkey> <circuit.mpcparams> <circuit_new.zkey>",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman) ",
|
||||
alias: ["zkib"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyImportBellman
|
||||
},
|
||||
{
|
||||
cmd: "zkey beacon <circuit_old.zkey> <circuit_new.zkey> <beaconHash(Hex)> <numIterationsExp>",
|
||||
description: "adds a beacon",
|
||||
alias: ["zkb"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyBeacon
|
||||
},
|
||||
{
|
||||
cmd: "zkey verify [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Verify zkey file contributions and verify that matches with the original circuit.r1cs and ptau",
|
||||
alias: ["zkv"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyVerify
|
||||
},
|
||||
{
|
||||
cmd: "zkey export verificationkey [circuit.zkey] [verification_key.json]",
|
||||
description: "Exports a verification key",
|
||||
alias: ["zkev"],
|
||||
action: zkeyExportVKey
|
||||
},
|
||||
{
|
||||
cmd: "zkey export json [circuit.zkey] [circuit.zkey.json]",
|
||||
description: "Exports a circuit key to a JSON file",
|
||||
alias: ["zkej"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportJson$1
|
||||
},
|
||||
{
|
||||
cmd: "zkey export solidityverifier [circuit.zkey] [verifier.sol]",
|
||||
@ -5760,66 +5811,24 @@ const commands = [
|
||||
action: zkeyExportSolidityCalldata
|
||||
},
|
||||
{
|
||||
cmd: "zkey new [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Creates an initial pkey file with zero contributions ",
|
||||
alias: ["zkn"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyNew
|
||||
cmd: "groth16 prove [circuit.zkey] [witness.wtns] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from witness",
|
||||
alias: ["g16p", "zpw", "zksnark proof", "proof -pk|provingkey -wt|witness -p|proof -pub|public"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: groth16Prove$1
|
||||
},
|
||||
{
|
||||
cmd: "zkey export bellman [circuit.zkey] [circuit.mpcparams]",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman)",
|
||||
alias: ["zkeb"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportBellman
|
||||
cmd: "groth16 fullprove [input.json] [circuit.wasm] [circuit.zkey] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from input",
|
||||
alias: ["g16f", "g16i"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: groth16FullProve$1
|
||||
},
|
||||
{
|
||||
cmd: "zkey import bellman <circuit_old.zkey> <circuit.mpcparams> <circuit_new.zkey>",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman) ",
|
||||
alias: ["zkib"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyImportBellman
|
||||
},
|
||||
{
|
||||
cmd: "zkey verify [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Verify zkey file contributions and verify that matches with the original circuit.r1cs and ptau",
|
||||
alias: ["zkv"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyVerify
|
||||
},
|
||||
{
|
||||
cmd: "zkey contribute <circuit_old.zkey> <circuit_new.zkey>",
|
||||
description: "creates a zkey file with a new contribution",
|
||||
alias: ["zkc"],
|
||||
options: "-verbose|v -entropy|e -name|n",
|
||||
action: zkeyContribute
|
||||
},
|
||||
{
|
||||
cmd: "zkey beacon <circuit_old.zkey> <circuit_new.zkey> <beaconHash(Hex)> <numIterationsExp>",
|
||||
description: "adds a beacon",
|
||||
alias: ["zkb"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyBeacon
|
||||
},
|
||||
{
|
||||
cmd: "zkey bellman contribute <curve> <circuit.mpcparams> <circuit_response.mpcparams>",
|
||||
description: "contributes to a llallange file in bellman format",
|
||||
alias: ["zkbc"],
|
||||
options: "-verbose|v -entropy|e",
|
||||
action: zkeyBellmanContribute
|
||||
},
|
||||
{
|
||||
cmd: "zkey export verificationkey [circuit.zkey] [verification_key.json]",
|
||||
description: "Exports a verification key",
|
||||
alias: ["zkev"],
|
||||
action: zkeyExportVKey
|
||||
},
|
||||
{
|
||||
cmd: "zkey export json [circuit.zkey] [circuit.zkey.json]",
|
||||
description: "Exports a circuit key to a JSON file",
|
||||
alias: ["zkej"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportJson$1
|
||||
cmd: "groth16 verify [verification_key.json] [public.json] [proof.json]",
|
||||
description: "Verify a zk Proof",
|
||||
alias: ["g16v", "verify -vk|verificationkey -pub|public -p|proof"],
|
||||
action: groth16Verify$1
|
||||
},
|
||||
|
||||
];
|
||||
@ -5839,42 +5848,21 @@ TODO COMMANDS
|
||||
=============
|
||||
|
||||
{
|
||||
cmd: "r1cs export circomJSON [circuit.r1cs] [circuit.json]",
|
||||
description: "Exports a R1CS to JSON file.",
|
||||
alias: ["rj"],
|
||||
action: r1csExportCircomJSON
|
||||
cmd: "zksnark setup [circuit.r1cs] [circuit.zkey] [verification_key.json]",
|
||||
description: "Run a simple setup for a circuit generating the proving key.",
|
||||
alias: ["zs", "setup -r1cs|r -provingkey|pk -verificationkey|vk"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkSetup
|
||||
},
|
||||
{
|
||||
cmd: "witness export json <witness.wtns> <witness.json>",
|
||||
description: "Export witness file to json",
|
||||
alias: ["wj"],
|
||||
action: witnessExportJson
|
||||
},
|
||||
|
||||
{
|
||||
cmd: "zkey export vkey <circuit.zkey> <verification_key.json>",
|
||||
description: "Exports a verification key to JSON",
|
||||
alias: ["kv"],
|
||||
action: zKeySolidity
|
||||
},
|
||||
|
||||
{
|
||||
cmd: "witness verify <circuit.r1cs> <witness.wtns>",
|
||||
description: "Verify a witness agains a r1cs",
|
||||
alias: ["wv"],
|
||||
action: witnessVerify
|
||||
},
|
||||
|
||||
phase2 constribute Contribute in the seconf phase ceremony
|
||||
phase2 beacon Contribute in the seconf phase ceremony with a Powers of Tau
|
||||
phase2 verify Verify the Powers of tau
|
||||
zksnark setup s Run a simple setup for a circuit generating the proving key.
|
||||
zksnark prove p Generates a zk Proof
|
||||
zksnark verify v Verify a zk Proof
|
||||
zkey export pkJSON pkjson Exports a proving key to JSON
|
||||
zkey export vkJSON vkjson Exports a verification key to JSON
|
||||
zkey export vkSolidity vksol Creates a verifier in solidity
|
||||
proof callParameters cp Generates call parameters ready to be called.
|
||||
{
|
||||
cmd: "powersOfTau export response"
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@ -6014,7 +6002,7 @@ async function zksnarkSetup(params, options) {
|
||||
*/
|
||||
|
||||
// groth16 prove [circuit.zkey] [witness.wtns] [proof.json] [public.json]
|
||||
async function zksnarkProve(params, options) {
|
||||
async function groth16Prove$1(params, options) {
|
||||
|
||||
const zkeyName = params[0] || "circuit.zkey";
|
||||
const witnessName = params[1] || "witness.wtns";
|
||||
@ -6023,7 +6011,7 @@ async function zksnarkProve(params, options) {
|
||||
|
||||
if (options.verbose) Logger.setLogLevel("DEBUG");
|
||||
|
||||
const {proof, publicSignals} = await groth16ProofFromInput(zkeyName, witnessName);
|
||||
const {proof, publicSignals} = await groth16Prove(zkeyName, witnessName);
|
||||
|
||||
await fs.promises.writeFile(proofName, JSON.stringify(stringifyBigInts$2(proof), null, 1), "utf-8");
|
||||
await fs.promises.writeFile(publicName, JSON.stringify(stringifyBigInts$2(publicSignals), null, 1), "utf-8");
|
||||
@ -6032,7 +6020,7 @@ async function zksnarkProve(params, options) {
|
||||
}
|
||||
|
||||
// groth16 fullprove [input.json] [circuit.wasm] [circuit.zkey] [proof.json] [public.json]
|
||||
async function zksnarkFullProve(params, options) {
|
||||
async function groth16FullProve$1(params, options) {
|
||||
|
||||
const inputName = params[0] || "input.json";
|
||||
const wasmName = params[1] || "circuit.wasm";
|
||||
@ -6044,7 +6032,7 @@ async function zksnarkFullProve(params, options) {
|
||||
|
||||
const input = unstringifyBigInts$1(JSON.parse(await fs.promises.readFile(inputName, "utf8")));
|
||||
|
||||
const {proof, publicSignals} = await groth16ProofFromInput$1(input, wasmName, zkeyName);
|
||||
const {proof, publicSignals} = await groth16FullProve(input, wasmName, zkeyName);
|
||||
|
||||
await fs.promises.writeFile(proofName, JSON.stringify(stringifyBigInts$2(proof), null, 1), "utf-8");
|
||||
await fs.promises.writeFile(publicName, JSON.stringify(stringifyBigInts$2(publicSignals), null, 1), "utf-8");
|
||||
@ -6053,7 +6041,7 @@ async function zksnarkFullProve(params, options) {
|
||||
}
|
||||
|
||||
// groth16 verify [verification_key.json] [public.json] [proof.json]
|
||||
async function zksnarkVerify(params, options) {
|
||||
async function groth16Verify$1(params, options) {
|
||||
|
||||
const verificationKeyName = params[0] || "verification_key.json";
|
||||
const publicName = params[1] || "public.json";
|
||||
@ -6065,9 +6053,9 @@ async function zksnarkVerify(params, options) {
|
||||
|
||||
if (options.verbose) Logger.setLogLevel("DEBUG");
|
||||
|
||||
const isValid$1 = await isValid(verificationKey, pub, proof, logger);
|
||||
const isValid = await groth16Verify(verificationKey, pub, proof, logger);
|
||||
|
||||
if (isValid$1) {
|
||||
if (isValid) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
|
5349
build/main.cjs
Normal file
5349
build/main.cjs
Normal file
File diff suppressed because it is too large
Load Diff
14983
build/main.js
14983
build/main.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
build/snarkjs.min.js
vendored
Normal file
1
build/snarkjs.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
208
cli.js
208
cli.js
@ -79,13 +79,6 @@ const commands = [
|
||||
options: "-verbose|v -nopoints -nocheck -name|n",
|
||||
action: powersOfTawImport
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau verify <powersoftau.ptau>",
|
||||
description: "verifies a powers of tau file",
|
||||
alias: ["ptv"],
|
||||
options: "-verbose|v",
|
||||
action: powersOfTawVerify
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau beacon <old_powersoftau.ptau> <new_powersoftau.ptau> <beaconHash(Hex)> <numIterationsExp>",
|
||||
description: "adds a beacon",
|
||||
@ -101,6 +94,13 @@ const commands = [
|
||||
options: "-verbose|v",
|
||||
action: powersOfTawPreparePhase2
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau verify <powersoftau.ptau>",
|
||||
description: "verifies a powers of tau file",
|
||||
alias: ["ptv"],
|
||||
options: "-verbose|v",
|
||||
action: powersOfTawVerify
|
||||
},
|
||||
{
|
||||
cmd: "powersoftau export json <powersoftau_0000.ptau> <powersoftau_0000.json>",
|
||||
description: "Exports a power of tau file to a JSON",
|
||||
@ -148,34 +148,67 @@ const commands = [
|
||||
alias: ["wej"],
|
||||
action: wtnsExportJson
|
||||
},
|
||||
/*
|
||||
{
|
||||
cmd: "zksnark setup [circuit.r1cs] [circuit.zkey] [verification_key.json]",
|
||||
description: "Run a simple setup for a circuit generating the proving key.",
|
||||
alias: ["zs", "setup -r1cs|r -provingkey|pk -verificationkey|vk"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkSetup
|
||||
},
|
||||
*/
|
||||
{
|
||||
cmd: "groth16 prove [circuit.zkey] [witness.wtns] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from witness",
|
||||
alias: ["g16p", "zpw", "zksnark proof", "proof -pk|provingkey -wt|witness -p|proof -pub|public"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkProve
|
||||
cmd: "zkey new [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Creates an initial pkey file with zero contributions ",
|
||||
alias: ["zkn"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyNew
|
||||
},
|
||||
{
|
||||
cmd: "groth16 fullprove [input.json] [circuit.wasm] [circuit.zkey] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from input",
|
||||
alias: ["g16f", "g16i"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkFullProve
|
||||
cmd: "zkey contribute <circuit_old.zkey> <circuit_new.zkey>",
|
||||
description: "creates a zkey file with a new contribution",
|
||||
alias: ["zkc"],
|
||||
options: "-verbose|v -entropy|e -name|n",
|
||||
action: zkeyContribute
|
||||
},
|
||||
{
|
||||
cmd: "groth16 verify [verification_key.json] [public.json] [proof.json]",
|
||||
description: "Verify a zk Proof",
|
||||
alias: ["g16v", "verify -vk|verificationkey -pub|public -p|proof"],
|
||||
action: zksnarkVerify
|
||||
cmd: "zkey export bellman [circuit.zkey] [circuit.mpcparams]",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman)",
|
||||
alias: ["zkeb"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportBellman
|
||||
},
|
||||
{
|
||||
cmd: "zkey bellman contribute <curve> <circuit.mpcparams> <circuit_response.mpcparams>",
|
||||
description: "contributes to a llallange file in bellman format",
|
||||
alias: ["zkbc"],
|
||||
options: "-verbose|v -entropy|e",
|
||||
action: zkeyBellmanContribute
|
||||
},
|
||||
{
|
||||
cmd: "zkey import bellman <circuit_old.zkey> <circuit.mpcparams> <circuit_new.zkey>",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman) ",
|
||||
alias: ["zkib"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyImportBellman
|
||||
},
|
||||
{
|
||||
cmd: "zkey beacon <circuit_old.zkey> <circuit_new.zkey> <beaconHash(Hex)> <numIterationsExp>",
|
||||
description: "adds a beacon",
|
||||
alias: ["zkb"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyBeacon
|
||||
},
|
||||
{
|
||||
cmd: "zkey verify [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Verify zkey file contributions and verify that matches with the original circuit.r1cs and ptau",
|
||||
alias: ["zkv"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyVerify
|
||||
},
|
||||
{
|
||||
cmd: "zkey export verificationkey [circuit.zkey] [verification_key.json]",
|
||||
description: "Exports a verification key",
|
||||
alias: ["zkev"],
|
||||
action: zkeyExportVKey
|
||||
},
|
||||
{
|
||||
cmd: "zkey export json [circuit.zkey] [circuit.zkey.json]",
|
||||
description: "Exports a circuit key to a JSON file",
|
||||
alias: ["zkej"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportJson
|
||||
},
|
||||
{
|
||||
cmd: "zkey export solidityverifier [circuit.zkey] [verifier.sol]",
|
||||
@ -190,66 +223,24 @@ const commands = [
|
||||
action: zkeyExportSolidityCalldata
|
||||
},
|
||||
{
|
||||
cmd: "zkey new [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Creates an initial pkey file with zero contributions ",
|
||||
alias: ["zkn"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyNew
|
||||
cmd: "groth16 prove [circuit.zkey] [witness.wtns] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from witness",
|
||||
alias: ["g16p", "zpw", "zksnark proof", "proof -pk|provingkey -wt|witness -p|proof -pub|public"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: groth16Prove
|
||||
},
|
||||
{
|
||||
cmd: "zkey export bellman [circuit.zkey] [circuit.mpcparams]",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman)",
|
||||
alias: ["zkeb"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportBellman
|
||||
cmd: "groth16 fullprove [input.json] [circuit.wasm] [circuit.zkey] [proof.json] [public.json]",
|
||||
description: "Generates a zk Proof from input",
|
||||
alias: ["g16f", "g16i"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: groth16FullProve
|
||||
},
|
||||
{
|
||||
cmd: "zkey import bellman <circuit_old.zkey> <circuit.mpcparams> <circuit_new.zkey>",
|
||||
description: "Export a zKey to a MPCParameters file compatible with kobi/phase2 (Bellman) ",
|
||||
alias: ["zkib"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyImportBellman
|
||||
},
|
||||
{
|
||||
cmd: "zkey verify [circuit.r1cs] [powersoftau.ptau] [circuit.zkey]",
|
||||
description: "Verify zkey file contributions and verify that matches with the original circuit.r1cs and ptau",
|
||||
alias: ["zkv"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyVerify
|
||||
},
|
||||
{
|
||||
cmd: "zkey contribute <circuit_old.zkey> <circuit_new.zkey>",
|
||||
description: "creates a zkey file with a new contribution",
|
||||
alias: ["zkc"],
|
||||
options: "-verbose|v -entropy|e -name|n",
|
||||
action: zkeyContribute
|
||||
},
|
||||
{
|
||||
cmd: "zkey beacon <circuit_old.zkey> <circuit_new.zkey> <beaconHash(Hex)> <numIterationsExp>",
|
||||
description: "adds a beacon",
|
||||
alias: ["zkb"],
|
||||
options: "-verbose|v -name|n",
|
||||
action: zkeyBeacon
|
||||
},
|
||||
{
|
||||
cmd: "zkey bellman contribute <curve> <circuit.mpcparams> <circuit_response.mpcparams>",
|
||||
description: "contributes to a llallange file in bellman format",
|
||||
alias: ["zkbc"],
|
||||
options: "-verbose|v -entropy|e",
|
||||
action: zkeyBellmanContribute
|
||||
},
|
||||
{
|
||||
cmd: "zkey export verificationkey [circuit.zkey] [verification_key.json]",
|
||||
description: "Exports a verification key",
|
||||
alias: ["zkev"],
|
||||
action: zkeyExportVKey
|
||||
},
|
||||
{
|
||||
cmd: "zkey export json [circuit.zkey] [circuit.zkey.json]",
|
||||
description: "Exports a circuit key to a JSON file",
|
||||
alias: ["zkej"],
|
||||
options: "-verbose|v",
|
||||
action: zkeyExportJson
|
||||
cmd: "groth16 verify [verification_key.json] [public.json] [proof.json]",
|
||||
description: "Verify a zk Proof",
|
||||
alias: ["g16v", "verify -vk|verificationkey -pub|public -p|proof"],
|
||||
action: groth16Verify
|
||||
},
|
||||
|
||||
];
|
||||
@ -269,42 +260,21 @@ TODO COMMANDS
|
||||
=============
|
||||
|
||||
{
|
||||
cmd: "r1cs export circomJSON [circuit.r1cs] [circuit.json]",
|
||||
description: "Exports a R1CS to JSON file.",
|
||||
alias: ["rj"],
|
||||
action: r1csExportCircomJSON
|
||||
cmd: "zksnark setup [circuit.r1cs] [circuit.zkey] [verification_key.json]",
|
||||
description: "Run a simple setup for a circuit generating the proving key.",
|
||||
alias: ["zs", "setup -r1cs|r -provingkey|pk -verificationkey|vk"],
|
||||
options: "-verbose|v -protocol",
|
||||
action: zksnarkSetup
|
||||
},
|
||||
{
|
||||
cmd: "witness export json <witness.wtns> <witness.json>",
|
||||
description: "Export witness file to json",
|
||||
alias: ["wj"],
|
||||
action: witnessExportJson
|
||||
},
|
||||
|
||||
{
|
||||
cmd: "zkey export vkey <circuit.zkey> <verification_key.json>",
|
||||
description: "Exports a verification key to JSON",
|
||||
alias: ["kv"],
|
||||
action: zKeySolidity
|
||||
},
|
||||
|
||||
{
|
||||
cmd: "witness verify <circuit.r1cs> <witness.wtns>",
|
||||
description: "Verify a witness agains a r1cs",
|
||||
alias: ["wv"],
|
||||
action: witnessVerify
|
||||
},
|
||||
|
||||
phase2 constribute Contribute in the seconf phase ceremony
|
||||
phase2 beacon Contribute in the seconf phase ceremony with a Powers of Tau
|
||||
phase2 verify Verify the Powers of tau
|
||||
zksnark setup s Run a simple setup for a circuit generating the proving key.
|
||||
zksnark prove p Generates a zk Proof
|
||||
zksnark verify v Verify a zk Proof
|
||||
zkey export pkJSON pkjson Exports a proving key to JSON
|
||||
zkey export vkJSON vkjson Exports a verification key to JSON
|
||||
zkey export vkSolidity vksol Creates a verifier in solidity
|
||||
proof callParameters cp Generates call parameters ready to be called.
|
||||
{
|
||||
cmd: "powersOfTau export response"
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@ -444,7 +414,7 @@ async function zksnarkSetup(params, options) {
|
||||
*/
|
||||
|
||||
// groth16 prove [circuit.zkey] [witness.wtns] [proof.json] [public.json]
|
||||
async function zksnarkProve(params, options) {
|
||||
async function groth16Prove(params, options) {
|
||||
|
||||
const zkeyName = params[0] || "circuit.zkey";
|
||||
const witnessName = params[1] || "witness.wtns";
|
||||
@ -462,7 +432,7 @@ async function zksnarkProve(params, options) {
|
||||
}
|
||||
|
||||
// groth16 fullprove [input.json] [circuit.wasm] [circuit.zkey] [proof.json] [public.json]
|
||||
async function zksnarkFullProve(params, options) {
|
||||
async function groth16FullProve(params, options) {
|
||||
|
||||
const inputName = params[0] || "input.json";
|
||||
const wasmName = params[1] || "circuit.wasm";
|
||||
@ -483,7 +453,7 @@ async function zksnarkFullProve(params, options) {
|
||||
}
|
||||
|
||||
// groth16 verify [verification_key.json] [public.json] [proof.json]
|
||||
async function zksnarkVerify(params, options) {
|
||||
async function groth16Verify(params, options) {
|
||||
|
||||
const verificationKeyName = params[0] || "verification_key.json";
|
||||
const publicName = params[1] || "public.json";
|
||||
@ -495,7 +465,7 @@ async function zksnarkVerify(params, options) {
|
||||
|
||||
if (options.verbose) Logger.setLogLevel("DEBUG");
|
||||
|
||||
const isValid = await groth16.validate(verificationKey, pub, proof, logger);
|
||||
const isValid = await groth16.verify(verificationKey, pub, proof, logger);
|
||||
|
||||
if (isValid) {
|
||||
return 0;
|
||||
|
@ -4,10 +4,26 @@ import commonJS from "rollup-plugin-commonjs";
|
||||
export default {
|
||||
input: "main.js",
|
||||
output: {
|
||||
file: "build/main.js",
|
||||
file: "build/main.cjs",
|
||||
format: "cjs",
|
||||
},
|
||||
external: ["fs", "os", "worker_threads", "readline", "crypto", "path"],
|
||||
external: [
|
||||
"fs",
|
||||
"os",
|
||||
"worker_threads",
|
||||
"readline",
|
||||
"crypto",
|
||||
"path",
|
||||
"big-integer",
|
||||
"wasmsnark",
|
||||
"circom_runtime",
|
||||
"blake2b-wasm",
|
||||
|
||||
"ffjavascript",
|
||||
"keccak",
|
||||
"yargs",
|
||||
"logplease"
|
||||
],
|
||||
plugins: [
|
||||
resolve({ preferBuiltins: true }),
|
||||
commonJS({
|
||||
|
24
config/rollup.iife_min.config.js
Normal file
24
config/rollup.iife_min.config.js
Normal file
@ -0,0 +1,24 @@
|
||||
import resolve from "rollup-plugin-node-resolve";
|
||||
import commonJS from "rollup-plugin-commonjs";
|
||||
import ignore from "rollup-plugin-ignore";
|
||||
import replace from "rollup-plugin-replace";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
|
||||
export default {
|
||||
input: "main.js",
|
||||
output: {
|
||||
file: "build/snarkjs.min.js",
|
||||
format: "iife",
|
||||
globals: {
|
||||
os: "null"
|
||||
},
|
||||
name: "snarkjs"
|
||||
},
|
||||
plugins: [
|
||||
ignore(["fs", "os", "crypto", "readline", "worker_threads"]),
|
||||
resolve(),
|
||||
commonJS(),
|
||||
replace({ "process.browser": !!process.env.BROWSER }),
|
||||
terser()
|
||||
]
|
||||
};
|
122
package-lock.json
generated
122
package-lock.json
generated
@ -203,6 +203,12 @@
|
||||
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
|
||||
"dev": true
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||
"dev": true
|
||||
},
|
||||
"builtin-modules": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz",
|
||||
@ -327,6 +333,12 @@
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
||||
"dev": true
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.20.3",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||
"dev": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@ -646,9 +658,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"fastfile": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.5.tgz",
|
||||
"integrity": "sha512-h6YDy9iI1gITf900quL91qnBl25JtqU5KD82NzhW0B35YFjGhXwWSkUA8g+nyz1th95RWEhtonz7O2AiSL+lQg=="
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.6.tgz",
|
||||
"integrity": "sha512-6cOUdePcue0DAssqGKPhmcSgdLTaB2IzxNgg2WAADOuta00Os88+ShpDItSkQ/eLCiAeYjsPasdBLYozVz+4Ug=="
|
||||
},
|
||||
"ffjavascript": {
|
||||
"version": "0.2.2",
|
||||
@ -1205,6 +1217,12 @@
|
||||
"p-is-promise": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"merge-stream": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||
"integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
|
||||
"dev": true
|
||||
},
|
||||
"mimic-fn": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
|
||||
@ -1670,14 +1688,23 @@
|
||||
"dev": true
|
||||
},
|
||||
"r1csfile": {
|
||||
"version": "0.0.9",
|
||||
"resolved": "https://registry.npmjs.org/r1csfile/-/r1csfile-0.0.9.tgz",
|
||||
"integrity": "sha512-VEp8K+Y3z+rRepjVgnnHI0fMgkTts6jYGr6R2WYWTJzW/g08rChWKErjwJRp4VRmqBGHNDV73GImLCxmf3+/7w==",
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/r1csfile/-/r1csfile-0.0.10.tgz",
|
||||
"integrity": "sha512-9w2aCGE9E85v4zGGyLuKyiFyFOv71f7tNbmeujCmNFdQkW06rhuEKMcv/My8MBqOI0SyA6fefYJxGyKOSDCNNA==",
|
||||
"requires": {
|
||||
"fastfile": "0.0.5",
|
||||
"fastfile": "0.0.6",
|
||||
"ffjavascript": "0.2.2"
|
||||
}
|
||||
},
|
||||
"randombytes": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
|
||||
"integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.0"
|
||||
}
|
||||
},
|
||||
"readdirp": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.2.0.tgz",
|
||||
@ -1797,6 +1824,54 @@
|
||||
"rollup-pluginutils": "^2.6.0"
|
||||
}
|
||||
},
|
||||
"rollup-plugin-terser": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-6.1.0.tgz",
|
||||
"integrity": "sha512-4fB3M9nuoWxrwm39habpd4hvrbrde2W2GG4zEGPQg1YITNkM3Tqur5jSuXlWNzbv/2aMLJ+dZJaySc3GCD8oDw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.8.3",
|
||||
"jest-worker": "^26.0.0",
|
||||
"serialize-javascript": "^3.0.0",
|
||||
"terser": "^4.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"has-flag": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||
"dev": true
|
||||
},
|
||||
"jest-worker": {
|
||||
"version": "26.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.1.0.tgz",
|
||||
"integrity": "sha512-Z9P5pZ6UC+kakMbNJn+tA2RdVdNX5WH1x+5UCBZ9MxIK24pjYtFt96fK+UwBTrjLYm232g1xz0L3eTh51OW+yQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"merge-stream": "^2.0.0",
|
||||
"supports-color": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"serialize-javascript": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-3.1.0.tgz",
|
||||
"integrity": "sha512-JIJT1DGiWmIKhzRsG91aS6Ze4sFUrYbltlkg2onR5OrnNM02Kl/hnY/T4FN2omvyeBbQmMJv+K4cPOpGzOTFBg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"randombytes": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
|
||||
"integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has-flag": "^4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"rollup-pluginutils": {
|
||||
"version": "2.8.2",
|
||||
"resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz",
|
||||
@ -1824,6 +1899,12 @@
|
||||
"tslib": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||
"dev": true
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
@ -1869,6 +1950,22 @@
|
||||
"is-fullwidth-code-point": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"dev": true
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.19",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz",
|
||||
"integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"buffer-from": "^1.0.0",
|
||||
"source-map": "^0.6.0"
|
||||
}
|
||||
},
|
||||
"sourcemap-codec": {
|
||||
"version": "1.4.8",
|
||||
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
|
||||
@ -1984,6 +2081,17 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"terser": {
|
||||
"version": "4.8.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz",
|
||||
"integrity": "sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"commander": "^2.20.0",
|
||||
"source-map": "~0.6.1",
|
||||
"source-map-support": "~0.5.12"
|
||||
}
|
||||
},
|
||||
"text-table": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
|
||||
|
12
package.json
12
package.json
@ -13,10 +13,11 @@
|
||||
"test": "mocha",
|
||||
"build": "rollup -c config/rollup.cjs.config.js",
|
||||
"buildcli": "rollup -c config/rollup.cli.config.js",
|
||||
"buildiife": "BROWSER=true rollup -c config/rollup.iife.config.js"
|
||||
"buildiife": "BROWSER=true rollup -c config/rollup.iife.config.js",
|
||||
"buildiifemin": "BROWSER=true rollup -c config/rollup.iife_min.config.js"
|
||||
},
|
||||
"bin": {
|
||||
"snarkjs": "build/cli.js"
|
||||
"snarkjs": "build/cli.cjs"
|
||||
},
|
||||
"directories": {
|
||||
"templates": "templates"
|
||||
@ -39,11 +40,11 @@
|
||||
"dependencies": {
|
||||
"blake2b-wasm": "https://github.com/jbaylina/blake2b-wasm.git",
|
||||
"circom_runtime": "0.0.8",
|
||||
"fastfile": "0.0.5",
|
||||
"fastfile": "0.0.6",
|
||||
"ffjavascript": "0.2.2",
|
||||
"keccak": "^3.0.0",
|
||||
"logplease": "^1.2.15",
|
||||
"r1csfile": "0.0.9",
|
||||
"r1csfile": "0.0.10",
|
||||
"yargs": "^12.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -56,6 +57,7 @@
|
||||
"rollup-plugin-ignore": "^1.0.6",
|
||||
"rollup-plugin-json": "^4.0.0",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-replace": "^2.2.0"
|
||||
"rollup-plugin-replace": "^2.2.0",
|
||||
"rollup-plugin-terser": "^6.1.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
export {default as fullProve} from "./groth16_fullprove.js";
|
||||
export {default as prove} from "./groth16_prove.js";
|
||||
export {default as validate} from "./groth16_verify.js";
|
||||
export {default as verify} from "./groth16_verify.js";
|
||||
|
@ -1,7 +1,7 @@
|
||||
import groth16_prove from "./groth16_prove.js";
|
||||
import wtns_calculate from "./wtns_calculate.js";
|
||||
|
||||
export default async function groth16ProofFromInput(input, wasmFile, zkeyFileName, logger) {
|
||||
export default async function groth16FullProve(input, wasmFile, zkeyFileName, logger) {
|
||||
const wtns= {
|
||||
type: "mem"
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ import { log2 } from "./misc.js";
|
||||
import { Scalar, utils } from "ffjavascript";
|
||||
const {stringifyBigInts} = utils;
|
||||
|
||||
export default async function groth16ProofFromInput(zkeyFileName, witnessFileName, logger) {
|
||||
export default async function groth16Prove(zkeyFileName, witnessFileName, logger) {
|
||||
const {fd: fdWtns, sections: sectionsWtns} = await binFileUtils.readBinFile(witnessFileName, "wtns", 2);
|
||||
|
||||
const wtns = await wtnsUtils.readHeader(fdWtns, sectionsWtns);
|
||||
@ -101,7 +101,6 @@ export default async function groth16ProofFromInput(zkeyFileName, witnessFileNam
|
||||
proof = stringifyBigInts(proof);
|
||||
publicSignals = stringifyBigInts(publicSignals);
|
||||
|
||||
|
||||
return {proof, publicSignals};
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import * as curves from "./curves.js";
|
||||
import { utils } from "ffjavascript";
|
||||
const {unstringifyBigInts} = utils;
|
||||
|
||||
export default async function isValid(vk_verifier, publicSignals, proof, logger) {
|
||||
export default async function groth16Verify(vk_verifier, publicSignals, proof, logger) {
|
||||
/*
|
||||
let cpub = vk_verifier.IC[0];
|
||||
for (let s= 0; s< vk_verifier.nPublic; s++) {
|
||||
|
@ -109,7 +109,7 @@ describe("Full process", function () {
|
||||
});
|
||||
|
||||
it ("groth16 verify", async () => {
|
||||
const res = await snarkjs.groth16.validate(vKey, publicSignals, proof);
|
||||
const res = await snarkjs.groth16.verify(vKey, publicSignals, proof);
|
||||
assert(res == true);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user