mirror of
https://github.com/arnaucube/go-snark-study.git
synced 2026-02-02 17:26:41 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
478006134d | ||
|
|
aec3022978 | ||
|
|
2461f86bda | ||
|
|
3308c3d94e |
42
README.md
42
README.md
@@ -1,17 +1,17 @@
|
||||
# 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
|
||||
|
||||
|
||||
- `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
|
||||
- `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 to understand the concepts. Do not use in production.
|
||||
|
||||
Not finished, implementing this in my free time to understand it better, so I don't have much time.
|
||||
|
||||
## 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) :
|
||||
|
||||
0. write circuit
|
||||
@@ -33,26 +33,16 @@ Minimal complete flow implementation:
|
||||
- [x] generate proofs
|
||||
- [x] verify proofs with BN128 pairing
|
||||
|
||||
Improvements from the minimal implementation:
|
||||
- [x] allow to call functions in circuits language
|
||||
- [x] allow `import` in circuits language
|
||||
- [ ] allow `for` in circuits language
|
||||
- [ ] move witness values calculation outside the setup phase
|
||||
- [x] Groth16
|
||||
- [ ] multiple optimizations
|
||||
- [x] wasm proof generation
|
||||
- [x] wasm proof verification
|
||||
|
||||
## WASM usage
|
||||
Ongoing 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
|
||||
- [](https://godoc.org/github.com/arnaucube/go-snark) zkSnark
|
||||
- [](https://godoc.org/github.com/arnaucube/go-snark/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/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/circuitcompiler) Circuit Compiler
|
||||
- [](https://godoc.org/github.com/arnaucube/go-snark-study) zkSnark
|
||||
- [](https://godoc.org/github.com/arnaucube/go-snark-study/groth16) zkSnark Groth16
|
||||
- [](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-study/fields) Finite Fields operations
|
||||
- [](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-study/circuitcompiler) Circuit Compiler
|
||||
|
||||
### CLI usage
|
||||
*The cli still needs some improvements, such as seting input files, etc.*
|
||||
@@ -205,7 +195,7 @@ assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true))
|
||||
```
|
||||
|
||||
##### 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:
|
||||
```go
|
||||
@@ -227,7 +217,7 @@ go test ./... -v
|
||||
```
|
||||
|
||||
## 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
|
||||
[](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.
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
)
|
||||
|
||||
// Bn128 is the data structure of the BN128
|
||||
|
||||
@@ -3,7 +3,7 @@ package bn128
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
)
|
||||
|
||||
type G1 struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package bn128
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
)
|
||||
|
||||
type G2 struct {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"math/big"
|
||||
"strconv"
|
||||
|
||||
"github.com/arnaucube/go-snark/r1csqap"
|
||||
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||
)
|
||||
|
||||
// Circuit is the data structure of the compiled circuit
|
||||
|
||||
@@ -32,7 +32,7 @@ const (
|
||||
var eof = rune(0)
|
||||
|
||||
func isWhitespace(ch rune) bool {
|
||||
return ch == ' ' || ch == '\t' || ch == '\n'
|
||||
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\v' || ch == '\f'
|
||||
}
|
||||
|
||||
func isLetter(ch rune) bool {
|
||||
|
||||
10
cli/main.go
10
cli/main.go
@@ -11,11 +11,11 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
|
||||
snark "github.com/arnaucube/go-snark"
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/groth16"
|
||||
"github.com/arnaucube/go-snark/r1csqap"
|
||||
"github.com/arnaucube/go-snark/utils"
|
||||
snark "github.com/arnaucube/go-snark-study"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/groth16"
|
||||
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||
"github.com/arnaucube/go-snark-study/utils"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# go-snark /externalVerif
|
||||
# go-snark-study /externalVerif
|
||||
Utilities to verify zkSNARK proofs generated by other tools.
|
||||
|
||||
## 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:
|
||||
```go
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/arnaucube/go-snark/groth16"
|
||||
"github.com/arnaucube/go-snark/utils"
|
||||
"github.com/arnaucube/go-snark-study/groth16"
|
||||
"github.com/arnaucube/go-snark-study/utils"
|
||||
)
|
||||
|
||||
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 (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/arnaucube/go-snark/bn128"
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark/r1csqap"
|
||||
"github.com/arnaucube/go-snark-study/bn128"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||
)
|
||||
|
||||
type Pk struct { // Proving Key
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/r1csqap"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## 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
|
||||
- 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
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"math/big"
|
||||
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
)
|
||||
|
||||
// Transpose transposes the *big.Int matrix
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
8
snark.go
8
snark.go
@@ -7,10 +7,10 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
|
||||
"github.com/arnaucube/go-snark/bn128"
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/fields"
|
||||
"github.com/arnaucube/go-snark/r1csqap"
|
||||
"github.com/arnaucube/go-snark-study/bn128"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/fields"
|
||||
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||
)
|
||||
|
||||
type Pk struct { // Proving Key pk:=(pkA, pkB, pkC, pkH)
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/groth16"
|
||||
"github.com/arnaucube/go-snark/r1csqap"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/groth16"
|
||||
"github.com/arnaucube/go-snark-study/r1csqap"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
snark "github.com/arnaucube/go-snark"
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/groth16"
|
||||
snark "github.com/arnaucube/go-snark-study"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/groth16"
|
||||
)
|
||||
|
||||
// []*big.Int
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
snark "github.com/arnaucube/go-snark"
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/groth16"
|
||||
snark "github.com/arnaucube/go-snark-study"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/groth16"
|
||||
)
|
||||
|
||||
// []*big.Int
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
## Installation in vim/nvim using plug
|
||||
Using [Plug](https://github.com/junegunn/vim-plug), add this lines into the `.vimrc`/`init.vim`:
|
||||
```
|
||||
Plug 'arnaucube/go-snark'
|
||||
Plug 'arnaucube/go-snark', {'rtp': 'vim-syntax'}
|
||||
Plug 'arnaucube/go-snark-study'
|
||||
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*
|
||||
|
||||
WASM wrappers for zkSNARK Pinocchio & Groth16 protocols.
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"math/big"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/arnaucube/go-snark"
|
||||
"github.com/arnaucube/go-snark/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark/groth16"
|
||||
"github.com/arnaucube/go-snark/utils"
|
||||
"github.com/arnaucube/go-snark-study"
|
||||
"github.com/arnaucube/go-snark-study/circuitcompiler"
|
||||
"github.com/arnaucube/go-snark-study/groth16"
|
||||
"github.com/arnaucube/go-snark-study/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user