Skip to content

Commit

Permalink
moved rollup/ into examples/; added MIT license in Neboulous code (me…
Browse files Browse the repository at this point in the history
…rkle trees); fixed integration tests with bigInt r1cs; modified config.yml to not run too long tests in circleCI server; removed the build tags
  • Loading branch information
ThomasPiellard committed Jun 5, 2020
1 parent 92746e0 commit 3449e74
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 123 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
- run: go test -v ./cmd/ -run=VersionIsGenerated # ensure version is generated
- run: go get golang.org/x/tools/cmd/goimports
- run: go generate ./...
- run: go test -v -tags bls377,debug ./...
- run: go test -v -tags bls381,debug ./...
- run: go test -v -tags bn256,debug ./...
- run: go test -v -short -tags debug ./...
- save_cache:
key: go-mod-v1-{{ checksum "go.sum" }}
paths:
Expand Down
30 changes: 0 additions & 30 deletions backend/assignment_test.backup

This file was deleted.

2 changes: 0 additions & 2 deletions backend/bls377/fft_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build bls377 !bn256,!bls381

/*
Copyright © 2020 ConsenSys
Expand Down
14 changes: 13 additions & 1 deletion backend/bls377/groth16/computeh_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
// +build bls377 !bn256,!bls381
// Copyright 2020 ConsenSys AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package groth16

Expand Down
14 changes: 8 additions & 6 deletions cmd/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
backend_bn256 "github.com/consensys/gnark/backend/bn256"
groth16_bn256 "github.com/consensys/gnark/backend/bn256/groth16"
"github.com/consensys/gnark/encoding/gob"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gurvy"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -104,13 +105,14 @@ func cmdProve(cmd *cobra.Command, args []string) {
os.Exit(-1)
}
// TODO clean that up with interfaces and type casts
var bigIntR1cs frontend.R1CS
switch curveID {
case gurvy.BLS377:
var r1cs backend_bls377.R1CS
if err := gob.Read(circuitPath, &r1cs, curveID); err != nil {
if err := gob.Read(circuitPath, &bigIntR1cs, curveID); err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
r1cs := backend_bls377.Cast(&bigIntR1cs)
fmt.Printf("%-30s %-30s %-d constraints\n", "loaded circuit", circuitPath, r1cs.NbConstraints)
// run setup
var pk groth16_bls377.ProvingKey
Expand Down Expand Up @@ -158,11 +160,11 @@ func cmdProve(cmd *cobra.Command, args []string) {

fmt.Printf("%-30s %-30s %-30s\n", "generated proof", proofPath, duration)
case gurvy.BLS381:
var r1cs backend_bls381.R1CS
if err := gob.Read(circuitPath, &r1cs, curveID); err != nil {
if err := gob.Read(circuitPath, &bigIntR1cs, curveID); err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
r1cs := backend_bls381.Cast(&bigIntR1cs)
fmt.Printf("%-30s %-30s %-d constraints\n", "loaded circuit", circuitPath, r1cs.NbConstraints)
// run setup
var pk groth16_bls381.ProvingKey
Expand Down Expand Up @@ -210,11 +212,11 @@ func cmdProve(cmd *cobra.Command, args []string) {

fmt.Printf("%-30s %-30s %-30s\n", "generated proof", proofPath, duration)
case gurvy.BN256:
var r1cs backend_bn256.R1CS
if err := gob.Read(circuitPath, &r1cs, curveID); err != nil {
if err := gob.Read(circuitPath, &bigIntR1cs, curveID); err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
r1cs := backend_bn256.Cast(&bigIntR1cs)
fmt.Printf("%-30s %-30s %-d constraints\n", "loaded circuit", circuitPath, r1cs.NbConstraints)
// run setup
var pk groth16_bn256.ProvingKey
Expand Down
16 changes: 9 additions & 7 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
backend_bn256 "github.com/consensys/gnark/backend/bn256"
groth16_bn256 "github.com/consensys/gnark/backend/bn256/groth16"
"github.com/consensys/gnark/encoding/gob"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gurvy"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -79,20 +80,21 @@ func cmdSetup(cmd *cobra.Command, args []string) {
os.Exit(-1)
}

// check curve ID
// check curve ID (TODO is curve.ID necessary now? Because the circuits are serialized with big.Int, here the curve.ID is "unknown")
curveID, err := gob.PeekCurveID(circuitPath)
if err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
// TODO clean that up with interfaces and type casts
var bigIntR1cs frontend.R1CS
switch curveID {
case gurvy.BLS377:
var r1cs backend_bls377.R1CS
if err := gob.Read(circuitPath, &r1cs, curveID); err != nil {
if err := gob.Read(circuitPath, &bigIntR1cs, curveID); err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
r1cs := backend_bls377.Cast(&bigIntR1cs)
fmt.Printf("%-30s %-30s %-d constraints\n", "loaded circuit", circuitPath, r1cs.NbConstraints)
// run setup
var pk groth16_bls377.ProvingKey
Expand All @@ -113,11 +115,11 @@ func cmdSetup(cmd *cobra.Command, args []string) {
}
fmt.Printf("%-30s %s\n", "generated proving key", pkPath)
case gurvy.BLS381:
var r1cs backend_bls381.R1CS
if err := gob.Read(circuitPath, &r1cs, curveID); err != nil {
if err := gob.Read(circuitPath, &bigIntR1cs, curveID); err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
r1cs := backend_bls381.Cast(&bigIntR1cs)
fmt.Printf("%-30s %-30s %-d constraints\n", "loaded circuit", circuitPath, r1cs.NbConstraints)
// run setup
var pk groth16_bls381.ProvingKey
Expand All @@ -138,11 +140,11 @@ func cmdSetup(cmd *cobra.Command, args []string) {
}
fmt.Printf("%-30s %s\n", "generated proving key", pkPath)
case gurvy.BN256:
var r1cs backend_bn256.R1CS
if err := gob.Read(circuitPath, &r1cs, curveID); err != nil {
if err := gob.Read(circuitPath, &bigIntR1cs, curveID); err != nil {
fmt.Println("error:", err)
os.Exit(-1)
}
r1cs := backend_bn256.Cast(&bigIntR1cs)
fmt.Printf("%-30s %-30s %-d constraints\n", "loaded circuit", circuitPath, r1cs.NbConstraints)
// run setup
var pk groth16_bn256.ProvingKey
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions rollup/circuit_test.go → examples/rollup/circuit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func TestCircuitSignature(t *testing.T) {

func TestCircuitInclusionProof(t *testing.T) {

if testing.Short() {
t.Skip("skipping rollup tests for circleCI")
}

notInInpuList := " is not in the input list"

// 16 accounts so we know that the proof length is 5
Expand Down Expand Up @@ -262,6 +266,10 @@ func TestCircuitInclusionProof(t *testing.T) {

func TestCircuitUpdateAccount(t *testing.T) {

if testing.Short() {
t.Skip("skipping rollup tests for circleCI")
}

notInInpuList := " is not in the input list"

// 16 accounts so we know that the proof length is 5
Expand Down Expand Up @@ -375,6 +383,10 @@ func TestCircuitUpdateAccount(t *testing.T) {

func TestCircuitFull(t *testing.T) {

if testing.Short() {
t.Skip("skipping rollup tests for circleCI")
}

nbAccounts := 16 // 16 accounts so we know that the proof length is 5
depth := 5 // size fo the inclusion proofs
batchSize := 1 // nbTranfers to batch in a proof
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions gadgets/accumulator/merkle/verify.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/*
Original Copyright 2015 https://gitlab.com/NebulousLabs
*/

/*
The MIT License (MIT)
Copyright (c) 2015 Nebulous
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/*
Copyright © 2020 ConsenSys
Expand Down
68 changes: 0 additions & 68 deletions gadgets/accumulator/merkle/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,74 +32,6 @@ import (
"github.com/consensys/gurvy/bn256/fr"
)

// func TestLeaf(t *testing.T) {

// // computation of expected result
// leafPrefix := []byte{0x00}
// var leaf fr.Element
// leaf.SetRandom()
// h := bn256.NewMiMC("seed")
// h.Write(leafPrefix)
// h.Write(leaf.Bytes())
// binExpectedRes := h.Sum([]byte{})

// var tmp fr.Element
// tmp.SetBytes(binExpectedRes)
// expectedRes := make(map[string]fr.Element)
// expectedRes["res"] = tmp

// // computation of leafNode using gadget
// circuit := frontend.New()
// hg, err := mimc.NewMiMCGadget("seed", gurvy.BN256)
// if err != nil {
// t.Fatal(err)
// }
// res := leafSum(&circuit, hg, circuit.SECRET_INPUT("leaf"))
// res.Tag("res")
// assignment := backend_common.NewAssignment()
// assignment.Assign(backend_common.Secret, "leaf", leaf)

// r1cs := backend_bn256.New(&circuit)

// assert := groth16.NewAssert(t)
// assert.CorrectExecution(&r1cs, assignment, expectedRes)
// }

// func TestNode(t *testing.T) {

// // computation of expected result
// nodePrefix := []byte{0x01}
// var node1, node2 fr.Element
// node1.SetRandom()
// node2.SetRandom()
// h := bn256.NewMiMC("seed")
// h.Write(nodePrefix)
// h.Write(node1.Bytes())
// h.Write(node2.Bytes())
// binExpectedRes := h.Sum([]byte{})
// var tmp fr.Element
// tmp.SetBytes(binExpectedRes)
// expectedRes := make(map[string]fr.Element)
// expectedRes["res"] = tmp

// // computation of leafNode using gadget
// circuit := frontend.New()
// hg, err := mimc.NewMiMCGadget("seed", gurvy.BN256)
// if err != nil {
// t.Fatal(err)
// }
// res := nodeSum(&circuit, hg, circuit.SECRET_INPUT("node1"), circuit.SECRET_INPUT("node2"))
// res.Tag("res")
// assignment := backend_common.NewAssignment()
// assignment.Assign(backend_common.Secret, "node1", node1)
// assignment.Assign(backend_common.Secret, "node2", node2)

// r1cs := backend_bn256.New(&circuit)

// assert := groth16.NewAssert(t)
// assert.CorrectExecution(&r1cs, assignment, expectedRes)
// }

func TestVerify(t *testing.T) {

// generate random data
Expand Down
11 changes: 5 additions & 6 deletions integration_test.go.backup → integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
"testing"

"github.com/consensys/gnark/backend"
"github.com/consensys/gnark/encoding/gob"
"github.com/consensys/gnark/internal/generators/testcircuits/circuits"
"github.com/consensys/gnark/internal/utils/encoding/gob"
"github.com/consensys/gurvy"
)

func TestIntegration(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration tests")
t.Skip("skipping integration tests for circleCI")
}
// create temporary dir for integration test
parentDir := "./integration_test"
Expand All @@ -50,7 +51,7 @@ func TestIntegration(t *testing.T) {
fInputGood := filepath.Join(parentDir, name+".good.input")
fInputBad := filepath.Join(parentDir, name+".bad.input")

buildTags := curve.ID.String() + ",debug"
buildTags := "debug"
// 2: input files to disk
if err := good.WriteFile(fInputGood); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -106,11 +107,9 @@ func TestIntegration(t *testing.T) {
}
// serialize to disk
fCircuit := filepath.Join(parentDir, name+".r1cs")
if err := gob.Write(fCircuit, circuit.R1CS, curve.ID); err != nil {
if err := gob.Write(fCircuit, circuit.R1CS, gurvy.BN256); err != nil {
t.Fatal(err)
}

spv(name, circuit.Good, circuit.Bad)

}
}

0 comments on commit 3449e74

Please sign in to comment.