• Stars
    star
    200
  • Rank 195,325 (Top 4 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast zkSnark proof generator written in native Web Assembly.

wasmsnark

A fast zkSnark proof and verifier and proof generator written in native Web Assembly.

wasmsnark is used to generate zkSnark Proofs and verify the from the browser.

This module generates highly optimized Web Assembly modules for the low level cryptographic primitives.

It also makes use of the Web Workers feature to parallelize the generation and verification of the zero knoledge proofs.

The result is a fast library with times close to libsnarks but fully compatible for browsers.

Usage

BN128

You just need to import the wasmsnark_bn128.js found in the build directory.

<script src="wasmsnark_bn128.js" />

This library has a single javascript function:

genZKSnarkProof(witness, provingKey, cb)

cb is the callback. If cb is undefined, then the function will return a promise.

witness is a binary buffer with all the signals in binnary format. The buffer is packt in 32bytes Little Endian Encoded Field Elements.

You can use the tool to build the binary file from the witness.json file generated by snarkjs.

IMPORTANT: Please be sure you run your setup with --protocol groth wasmsnark only generates groth16 proofs!

node ../tools/buildwitness.js -i witness.json -o witness.bin

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 in snarkjs to a proving_key.bin file that can be used directly with this library.

node ../tools/buildpkey.js -i proving_key.json -o proving_key.bin

The result is a JSON object with pi_a, pi_b and pi_c points.

You can use the stringified version of this JSON as a proof.json in snarkjs

Here is a simple example of a web page that loads a key and a witness and generates the proof when the button is pressed.

<html>
<header>
</header>
<script src="wasmsnark_bn128.js"></script>
<script>

var witness;
var proving_key;

function onLoad() {

    fetch("proving_key.bin").then( (response) => {
        return response.arrayBuffer();
    }).then( (b) => {
        provingKey = b;
    });

    fetch("witness.bin").then( (response) => {
        return response.arrayBuffer();
    }).then( (b) => {
        witness = b;
    });
}

function calcProof() {
    const start = new Date().getTime();
    document.getElementById("time").innerHTML = "processing....";
    document.getElementById("proof").innerHTML = "";

    window.genZKSnarkProof(witness, provingKey).then((p)=> {
        const end = new Date().getTime();
        const time = end - start;
        document.getElementById("time").innerHTML = `Time to compute: ${time}ms`;
        document.getElementById("proof").innerHTML = JSON.stringify(p, null, 1);
    });
}

</script>
<body onLoad="onLoad()">
<h1>iden3</h1>
<h2>Zero knowledge proof generator</h2>
<button onClick="calcProof()">Test</button>
<div id="time"></div>
<pre id="proof"></pre>

</body>
</html>

You can test it by running a web server on the example directory

npm -g install http-server
cd example/bn128
http-server .

And then navegate to http://127.0.0.1:8080

The generated proof can be cut and pasted to example/bn128/proof.json and tested with snarkjs

snarkjs verify

MNT6753

The directory example/mnt6753 contains an example of the verifier.

Building wasm.js

npm run build

Testing

npm test

License

wasmsnark is part of the iden3 project copyright 2019 0KIMS association and published with GPL-3 license. Please check the COPYING file for more details.

More Repositories

1

snarkjs

zkSNARK implementation in JavaScript & WASM
JavaScript
1,747
star
2

circom

zkSnark circuit compiler
WebAssembly
1,276
star
3

circomlib

Library of basic circuits for circom
JavaScript
560
star
4

circom_old

Circuit compiler for zkSNARKs
JavaScript
471
star
5

rapidsnark-old

fast zksnark prover
C++
125
star
6

go-iden3-crypto

Go implementation of some cryptographic primitives (that fit inside the SNARK field) and compatible with circomlib
Go
114
star
7

rollup

rollup implementation
JavaScript
91
star
8

contracts

IDEN3 smartcontracts
TypeScript
85
star
9

go-iden3-core

Go core implementation of the iden3 system
Go
85
star
10

circomlibjs

Javascript library to work with circomlib circuits
JavaScript
73
star
11

circuits

Circom circuits used by the iden3 core protocol.
Go
71
star
12

circom_tester

Provides tools for testing circom circuits.
JavaScript
56
star
13

docs

iden3 documentation
Go
54
star
14

ffjavascript

Finite Field Library in Javascript
JavaScript
41
star
15

go-circom-prover-verifier

Go implementation of the Groth16 zkSNARK Prover and Verifier compatible with Circom
Go
37
star
16

rapidsnark

rapidsnark is a fast zkSNARK prover written in C++, that generates proofs for circuits created with circom and snarkjs.
C++
34
star
17

iden3js

Javascript client library of the iden3 system
JavaScript
25
star
18

go-circuits

Circuits
Go
22
star
19

r1csfile

r1cs file format parser
JavaScript
21
star
20

go-iden3-auth

Go
20
star
21

js-iden3-auth

TypeScript
20
star
22

go-rapidsnark

go-rapidsnark
Go
20
star
23

circom_runtime

circom runtime
Assembly
17
star
24

prover-server

REST API for snarkjs prover
Go
16
star
25

wasmcurves

Web Assembly low level implementation of pairing friendly curves.
JavaScript
15
star
26

Wallet

SPA web wallet
JavaScript
14
star
27

wasmbuilder

Javascript package that helps to build wasm code by hand.
JavaScript
14
star
28

js-jwz

TypeScript
14
star
29

vim-circom-syntax

Circom syntax highlighting for vim
Vim Script
14
star
30

iden3-docs

iden3 documentation
Python
13
star
31

go-merkletree-sql

Go
13
star
32

go-merkletree

MerkleTree compatible with circomlib/smt
Go
13
star
33

ffiasm-old

Intel assembly finite field library generator
Assembly
12
star
34

go-zksnark-full-flow-example

zkSNARK full flow example in Go
Go
11
star
35

js-merkletree

browser compatible SMT implemetation
TypeScript
10
star
36

claim-schema-vocab

Vocabulary and schemas for usage with Iden3 Verifiable Credentials
10
star
37

js-iden3-core

TypeScript
9
star
38

fastfile

fast cached read write of big binary files in JS
JavaScript
9
star
39

go-circom-witnesscalc

Witness Calculator in go, calling WASM
Go
8
star
40

circom-highlighting-vscode

Extension for vs-code to highlight circom language
7
star
41

polygonid-flutter-sdk

Flutter Plugin to use the Polygon ID SDK
Dart
7
star
42

js-crypto

Crypto primitives for js-sdk in the light and browser compatible form.
TypeScript
7
star
43

binfileutils

Utilities to work with iden3 binary file.
JavaScript
6
star
44

go-jwz

Golang implementation of json web zeroknowledge
Go
6
star
45

reverse-hash-service

Go
5
star
46

ffwasm

Finite Field Library in Javascript
JavaScript
5
star
47

go-schema-processor

Library to process claim data with different schema formats and compact to index and value slots according claim specification.
Go
5
star
48

react-native-rapidsnark

The react-native wrapper for rapidsnark
Circom
5
star
49

wbigint

Wrapper to BigInt Native or simulate depending if supported.
JavaScript
4
star
50

tx-forwarder

Server that pays gas for client signed transactions for specified smart contracts in ethereum blockchain.
Go
4
star
51

trustlessrelayercircuit

Trustless Relayer circuit in circom
JavaScript
4
star
52

discovery-node

decentralized discovery node draft implementation
Go
4
star
53

distanceProver

Example project for circom snarkjs and wasmsnark
C++
4
star
54

ffiasm

This package is a script that generates a Finite field Library in Intel64 and ARM Assembly
EJS
4
star
55

walletlibjs

Javascript library with utilities for iden3 wallets
JavaScript
3
star
56

iden3comm

Implementation of iden3comm communication protocol on golang
Go
3
star
57

bigarray

Array Object for nodejs that supports millions of elements.
JavaScript
3
star
58

citrus

Continuous integration testing running until sunrise
Go
3
star
59

tutorial-examples

Support files for Iden3 tutorial
JavaScript
3
star
60

ci

continuous integration testing
Shell
2
star
61

js-jsonld-merklization

TypeScript
2
star
62

go-iden3-servers

go-iden3 servers library and cli utils
Go
2
star
63

ts-iden3-light-wallet

iden3 light wallet client library implementation in Typescript for browser wallets
TypeScript
2
star
64

research

Research papers written by the iden3 team
TeX
2
star
65

iden3-playground

JavaScript
2
star
66

merkletree-proof

Complementary library for reverse hash service to fetch iden3 identity state roots and generate Sparse Merkle Tree proofs
Go
2
star
67

notifications-server

Go
2
star
68

iden3-mobile

iden3 light client library implementation in Go for native wallets (with gomobile-friendly wrappers)
Go
2
star
69

r1csoptimize

Optimize r1cs file
JavaScript
2
star
70

snarkjs-generate-solidity

EJS
2
star
71

go-iden3-crypto-wasm

WASM wrappers for browser execution of go-iden3-crypto
JavaScript
2
star
72

go-public-key-encryption

Easy to use functions to encrypt and decrypt using public key encryption (wrappers around libsodium)
Go
1
star
73

eslint-config-react-ts

JavaScript
1
star
74

go-backup

Identity Backup and Recovery Library
Go
1
star
75

go-iden3-servers-demo

iden3 demo servers using the go-iden3-servers library
Go
1
star
76

go-iden3-identity-server

Identity Agent Server
Go
1
star
77

vault-plugin-secrets-iden3

Modification of vault-plugin-secrets-kv/v1 with signing capability
Go
1
star
78

iden3-landing

Source code for the iden3 website.
HTML
1
star
79

go-onchain-credential-adapter

Go
1
star
80

contracts-abi

Shell
1
star
81

notification-service

Service to send push notifications
Go
1
star