arnaucube
arnaucube/go-bellman-verifierPublic Self-hosted repository
Add Travis, update README.md & doc
arnaucube root@arnaucube.com
Mon, 09 Mar 2020 23:46:35 +0100
commit

426d8c21f269df96fc2630d44155dbbc53e769d0

parent

b3f1e735a9d7da7b4c0ede4390b7e0cd73ab2db8

4 files changed, 31 insertions(+), 8 deletions(-)

jump to
A .travis.yml

@@ -0,0 +1,5 @@

+language: go + +go: + - "1.13" +
M README.md → README.md

@@ -1,6 +1,20 @@

-# go-bellman-verifier +# go-bellman-verifier [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucube/go-bellman-verifier)](https://goreportcard.com/report/github.com/arnaucube/go-bellman-verifier) [![Build Status](https://travis-ci.org/arnaucube/go-bellman-verifier.svg?branch=master)](https://travis-ci.org/arnaucube/go-bellman-verifier) + +Groth16 zkSNARK bellman proof verifier + +Verify [Groth16](https://eprint.iacr.org/2016/260.pdf) proofs generated from [bellman](https://github.com/zkcrypto/bellman), using [cloudflare/bn256](https://github.com/ethereum/go-ethereum/tree/master/crypto/bn256/cloudflare) (used by [go-ethereum](https://github.com/ethereum/go-ethereum)) for the Pairing. -Groth16 zkSnark bellman proof verifier -- Verify proofs generated from [bellman](https://github.com/zkcrypto/bellman) -- Using [cloudflare/bn256](https://github.com/cloudflare/bn256) for the Pairing. +## Usage +```go +public, err := ParsePublicRaw(publicJson) +require.Nil(t, err) +proof, err := ParseProofRaw(proofJson) +require.Nil(t, err) +vk, err := ParseVkRaw(vkJson) +require.Nil(t, err) + +v := Verify(vk, proof, public) +assert.True(t, v) +``` +
M verifier.go → verifier.go

@@ -11,6 +11,7 @@

bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" ) +// Vk is the Verification Key data structure type Vk struct { Alpha *bn256.G1 Beta *bn256.G2

@@ -19,6 +20,7 @@ Delta *bn256.G2

GammaABC []*bn256.G1 } +// VkRaw is the Verification Key data structure in string format (from json) type VkRaw struct { Alpha []string `json:"alpha_g1"` Beta [][]string `json:"beta_g2"`

@@ -27,12 +29,14 @@ Delta [][]string `json:"delta_g2"`

GammaABC [][]string `json:"ic"` } +// Proof is the Groth16 Proof data structure type Proof struct { A *bn256.G1 B *bn256.G2 C *bn256.G1 } +// ProofRaw is the Groth16 Proof data structure in string format (from json) type ProofRaw struct { A []string `json:"a"` B [][]string `json:"b"`
M verifier_test.go → verifier_test.go

@@ -15,11 +15,11 @@ assert.Nil(t, err)

assert.Equal(t, "bn256.G1(2cdfab288afda1ba399d60951423e76445754b7d2e7827634732988373c8e0ff, 1bb2e3543dfdd373610db3ea82703bc70e4d6f01b5c0e10709e27545670824f4)", a.String()) bHex := [][]string{ - []string{ + { "0x0f9cd75cae408d3b6d2731035dbb6aa6f66cf900c1d64b46510cbbcd7cf94f64", "0x165997362d7c2bf5672d16206fbee620ad8eb54f609b98c49c7c6287c9979077", }, - []string{ + { "0x0392982b7cd7bdbbee79d5f808c67ead8ef3e2347810b546b419da5f738aab92", "0x0f94d6781b9de113b86abd1930accd2260d0c979d520bc1a0e79dec3c8ce76a3", },

@@ -29,11 +29,11 @@ assert.Nil(t, err)

assert.Equal(t, "bn256.G2((165997362d7c2bf5672d16206fbee620ad8eb54f609b98c49c7c6287c9979077, 0f9cd75cae408d3b6d2731035dbb6aa6f66cf900c1d64b46510cbbcd7cf94f64), (0f94d6781b9de113b86abd1930accd2260d0c979d520bc1a0e79dec3c8ce76a3, 0392982b7cd7bdbbee79d5f808c67ead8ef3e2347810b546b419da5f738aab92))", b.String()) gHex := [][]string{ - []string{ + { "0x2d0c4fa1239184802aeda1f206e49104940aa3eccc1b3e0141c25b2dba8e7caf", "0x15c9b1123841897787badbe858eb00943fc8a99454666f21acf4e79e13547471", }, - []string{ + { "0x256ad09ecb0abc15fd48f20c37d28ffcf0f8eb3b23cb10cdeee7365b598963ac", "0x2bc9bc381cf68badd992338c637b36b54936b69cb8560eaf5a8cbe2c20ff8522", },