mirror of
https://github.com/arnaucube/go-snark-study.git
synced 2026-02-02 17:26:41 +01:00
Archive repository
This commit is contained in:
32
README.md
32
README.md
@@ -1,18 +1,16 @@
|
|||||||
# go-snark [](https://goreportcard.com/report/github.com/arnaucube/go-snark) [](https://travis-ci.org/arnaucube/go-snark) [](https://gitter.im/go-snark/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
### Warning
|
||||||
|
Implementation of the zkSNARK [Pinocchio protocol](https://eprint.iacr.org/2013/279.pdf) and [Groth16 protocol](https://eprint.iacr.org/2016/260.pdf) from scratch in Go done in my free time to understand the concepts. Do not use in production.
|
||||||
|
|
||||||
|
If you want to generate proofs & verify them from Go, you can try https://github.com/vocdoni/go-snark, which is implemented using the [bn256](https://github.com/ethereum/go-ethereum/tree/master/crypto/bn256/cloudflare) for the Pairing curve operations for the Groth16 zkSNARK, and it is compatible with [circom](https://github.com/iden3/circom).
|
||||||
|
|
||||||
|
# go-snark-study [](https://goreportcard.com/report/github.com/arnaucube/go-snark-study) [](https://godoc.org/github.com/arnaucube/go-snark-study)
|
||||||
|
|
||||||
zkSNARK library implementation in Go
|
zkSNARK library implementation in Go
|
||||||
|
|
||||||
|
|
||||||
- `Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture`, Eli Ben-Sasson, Alessandro Chiesa, Eran Tromer, Madars Virza https://eprint.iacr.org/2013/879.pdf
|
- `Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture`, Eli Ben-Sasson, Alessandro Chiesa, Eran Tromer, Madars Virza https://eprint.iacr.org/2013/879.pdf
|
||||||
- `Pinocchio: Nearly practical verifiable computation`, Bryan Parno, Craig Gentry, Jon Howell, Mariana Raykova https://eprint.iacr.org/2013/279.pdf
|
- `Pinocchio: Nearly practical verifiable computation`, Bryan Parno, Craig Gentry, Jon Howell, Mariana Raykova https://eprint.iacr.org/2013/279.pdf
|
||||||
- `On the Size of Pairing-based Non-interactive Arguments`, Jens Groth https://eprint.iacr.org/2016/260.pdf
|
- `On the Size of Pairing-based Non-interactive Arguments`, Jens Groth https://eprint.iacr.org/2016/260.pdf
|
||||||
|
|
||||||
## Caution & Warning
|
|
||||||
Implementation of the zkSNARK [Pinocchio protocol](https://eprint.iacr.org/2013/279.pdf) and [Groth16 protocol](https://eprint.iacr.org/2016/260.pdf) from scratch in Go done in my free time to understand the concepts. Do not use in production.
|
|
||||||
|
|
||||||
## zkSNARKs in Go
|
|
||||||
If you need to use zkSNARKs in Go, I would recommend to take a look at [go-circom-prover-verifier](https://github.com/iden3/go-circom-prover-verifier), which I've wrote using the [bn256](https://github.com/ethereum/go-ethereum/tree/master/crypto/bn256/cloudflare) for the Pairing curve operations for the Groth16 zkSNARK, and it is compatible with [circom](https://github.com/iden3/circom).
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
Currently allows to do the complete path with [Pinocchio protocol](https://eprint.iacr.org/2013/279.pdf) and [Groth16 protocol](https://eprint.iacr.org/2016/260.pdf) :
|
Currently allows to do the complete path with [Pinocchio protocol](https://eprint.iacr.org/2013/279.pdf) and [Groth16 protocol](https://eprint.iacr.org/2016/260.pdf) :
|
||||||
|
|
||||||
@@ -36,15 +34,15 @@ Minimal complete flow implementation:
|
|||||||
- [x] verify proofs with BN128 pairing
|
- [x] verify proofs with BN128 pairing
|
||||||
|
|
||||||
## WASM usage
|
## WASM usage
|
||||||
Experimentation with go-snark compiled to wasm: https://github.com/arnaucube/go-snark/tree/master/wasm
|
Experimentation with go-snark-study compiled to wasm: https://github.com/arnaucube/go-snark-study/tree/master/wasm
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
- [](https://godoc.org/github.com/arnaucube/go-snark) zkSnark
|
- [](https://godoc.org/github.com/arnaucube/go-snark-study) zkSnark
|
||||||
- [](https://godoc.org/github.com/arnaucube/go-snark/groth16) zkSnark Groth16
|
- [](https://godoc.org/github.com/arnaucube/go-snark-study/groth16) zkSnark Groth16
|
||||||
- [](https://godoc.org/github.com/arnaucube/go-snark/bn128) bn128 (more details: https://github.com/arnaucube/go-snark/tree/master/bn128)
|
- [](https://godoc.org/github.com/arnaucube/go-snark-study/bn128) bn128 (more details: https://github.com/arnaucube/go-snark-study/tree/master/bn128)
|
||||||
- [](https://godoc.org/github.com/arnaucube/go-snark/fields) Finite Fields operations
|
- [](https://godoc.org/github.com/arnaucube/go-snark-study/fields) Finite Fields operations
|
||||||
- [](https://godoc.org/github.com/arnaucube/go-snark/r1csqap) R1CS to QAP (more details: https://github.com/arnaucube/go-snark/tree/master/r1csqap)
|
- [](https://godoc.org/github.com/arnaucube/go-snark-study/r1csqap) R1CS to QAP (more details: https://github.com/arnaucube/go-snark-study/tree/master/r1csqap)
|
||||||
- [](https://godoc.org/github.com/arnaucube/go-snark/circuitcompiler) Circuit Compiler
|
- [](https://godoc.org/github.com/arnaucube/go-snark-study/circuitcompiler) Circuit Compiler
|
||||||
|
|
||||||
### CLI usage
|
### CLI usage
|
||||||
*The cli still needs some improvements, such as seting input files, etc.*
|
*The cli still needs some improvements, such as seting input files, etc.*
|
||||||
@@ -197,7 +195,7 @@ assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true))
|
|||||||
```
|
```
|
||||||
|
|
||||||
##### Verify Proof generated from [snarkjs](https://github.com/iden3/snarkjs)
|
##### Verify Proof generated from [snarkjs](https://github.com/iden3/snarkjs)
|
||||||
Is possible with `go-snark` to verify proofs generated by `snarkjs`
|
Is possible with `go-snark-study` to verify proofs generated by `snarkjs`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```go
|
```go
|
||||||
@@ -219,7 +217,7 @@ go test ./... -v
|
|||||||
```
|
```
|
||||||
|
|
||||||
## vim/nvim circuit syntax highlighter
|
## vim/nvim circuit syntax highlighter
|
||||||
For more details and installation instructions see https://github.com/arnaucube/go-snark/tree/master/vim-syntax
|
For more details and installation instructions see https://github.com/arnaucube/go-snark-study/tree/master/vim-syntax
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
## Bn128
|
## Bn128
|
||||||
[](https://godoc.org/github.com/arnaucube/go-snark/bn128) bn128
|
[](https://godoc.org/github.com/arnaucube/go-snark-study/bn128) bn128
|
||||||
Implementation of the bn128 pairing in Go.
|
Implementation of the bn128 pairing in Go.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bn128 is the data structure of the BN128
|
// Bn128 is the data structure of the BN128
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package bn128
|
|||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
)
|
)
|
||||||
|
|
||||||
type G1 struct {
|
type G1 struct {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package bn128
|
|||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
)
|
)
|
||||||
|
|
||||||
type G2 struct {
|
type G2 struct {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/r1csqap"
|
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Circuit is the data structure of the compiled circuit
|
// Circuit is the data structure of the compiled circuit
|
||||||
|
|||||||
10
cli/main.go
10
cli/main.go
@@ -11,11 +11,11 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
snark "github.com/arnaucube/go-snark"
|
snark "github.com/arnaucube/go-snark-study"
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/groth16"
|
"github.com/arnaucube/go-snark-study/groth16"
|
||||||
"github.com/arnaucube/go-snark/r1csqap"
|
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||||
"github.com/arnaucube/go-snark/utils"
|
"github.com/arnaucube/go-snark-study/utils"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# go-snark /externalVerif
|
# go-snark-study /externalVerif
|
||||||
Utilities to verify zkSNARK proofs generated by other tools.
|
Utilities to verify zkSNARK proofs generated by other tools.
|
||||||
|
|
||||||
## Verify Proof generated from [snarkjs](https://github.com/iden3/snarkjs)
|
## Verify Proof generated from [snarkjs](https://github.com/iden3/snarkjs)
|
||||||
Is possible with `go-snark` to verify proofs generated by `snarkjs`
|
Is possible with `go-snark-study` to verify proofs generated by `snarkjs`
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```go
|
```go
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/groth16"
|
"github.com/arnaucube/go-snark-study/groth16"
|
||||||
"github.com/arnaucube/go-snark/utils"
|
"github.com/arnaucube/go-snark-study/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CircomProof struct {
|
type CircomProof struct {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/arnaucube/go-snark
|
module github.com/arnaucube/go-snark-study
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/bn128"
|
"github.com/arnaucube/go-snark-study/bn128"
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
"github.com/arnaucube/go-snark/r1csqap"
|
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pk struct { // Proving Key
|
type Pk struct { // Proving Key
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/r1csqap"
|
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
## R1CS to Quadratic Arithmetic Program
|
## R1CS to Quadratic Arithmetic Program
|
||||||
[](https://godoc.org/github.com/arnaucube/go-snark/r1csqap) R1CS to QAP
|
[](https://godoc.org/github.com/arnaucube/go-snark-study/r1csqap) R1CS to QAP
|
||||||
- `Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture`, Eli Ben-Sasson, Alessandro Chiesa, Eran Tromer, Madars Virza https://eprint.iacr.org/2013/879.pdf
|
- `Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture`, Eli Ben-Sasson, Alessandro Chiesa, Eran Tromer, Madars Virza https://eprint.iacr.org/2013/879.pdf
|
||||||
- Vitalik Buterin blog post about QAP https://medium.com/@VitalikButerin/quadratic-arithmetic-programs-from-zero-to-hero-f6d558cea649
|
- Vitalik Buterin blog post about QAP https://medium.com/@VitalikButerin/quadratic-arithmetic-programs-from-zero-to-hero-f6d558cea649
|
||||||
- Ariel Gabizon in Zcash blog https://z.cash/blog/snark-explain5
|
- Ariel Gabizon in Zcash blog https://z.cash/blog/snark-explain5
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Transpose transposes the *big.Int matrix
|
// Transpose transposes the *big.Int matrix
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
8
snark.go
8
snark.go
@@ -7,10 +7,10 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/bn128"
|
"github.com/arnaucube/go-snark-study/bn128"
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/fields"
|
"github.com/arnaucube/go-snark-study/fields"
|
||||||
"github.com/arnaucube/go-snark/r1csqap"
|
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pk struct { // Proving Key pk:=(pkA, pkB, pkC, pkH)
|
type Pk struct { // Proving Key pk:=(pkA, pkB, pkC, pkH)
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/groth16"
|
"github.com/arnaucube/go-snark-study/groth16"
|
||||||
"github.com/arnaucube/go-snark/r1csqap"
|
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
snark "github.com/arnaucube/go-snark"
|
snark "github.com/arnaucube/go-snark-study"
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/groth16"
|
"github.com/arnaucube/go-snark-study/groth16"
|
||||||
)
|
)
|
||||||
|
|
||||||
// []*big.Int
|
// []*big.Int
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
snark "github.com/arnaucube/go-snark"
|
snark "github.com/arnaucube/go-snark-study"
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/groth16"
|
"github.com/arnaucube/go-snark-study/groth16"
|
||||||
)
|
)
|
||||||
|
|
||||||
// []*big.Int
|
// []*big.Int
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
## Installation in vim/nvim using plug
|
## Installation in vim/nvim using plug
|
||||||
Using [Plug](https://github.com/junegunn/vim-plug), add this lines into the `.vimrc`/`init.vim`:
|
Using [Plug](https://github.com/junegunn/vim-plug), add this lines into the `.vimrc`/`init.vim`:
|
||||||
```
|
```
|
||||||
Plug 'arnaucube/go-snark'
|
Plug 'arnaucube/go-snark-study'
|
||||||
Plug 'arnaucube/go-snark', {'rtp': 'vim-syntax'}
|
Plug 'arnaucube/go-snark-study', {'rtp': 'vim-syntax'}
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# go-snark wasm
|
# go-snark-study wasm
|
||||||
*Warning: this is an ongoing experimentation*
|
*Warning: this is an ongoing experimentation*
|
||||||
|
|
||||||
WASM wrappers for zkSNARK Pinocchio & Groth16 protocols.
|
WASM wrappers for zkSNARK Pinocchio & Groth16 protocols.
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
|
|
||||||
"github.com/arnaucube/go-snark"
|
"github.com/arnaucube/go-snark-study"
|
||||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||||
"github.com/arnaucube/go-snark/groth16"
|
"github.com/arnaucube/go-snark-study/groth16"
|
||||||
"github.com/arnaucube/go-snark/utils"
|
"github.com/arnaucube/go-snark-study/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user