Skip to content

Commit

Permalink
Merge pull request #878 from Consensys/chore/example-cleanup
Browse files Browse the repository at this point in the history
chore: cleanup documentation examples
  • Loading branch information
Tabaie authored Oct 20, 2023
2 parents 653506f + df6040d commit 4dbc3c6
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 196 deletions.
12 changes: 0 additions & 12 deletions std/algebra/emulated/sw_bls12381/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,26 @@ func ExamplePairing() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
secretWitness, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness")
}
publicWitness, err := secretWitness.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness")
}
proof, err := groth16.Prove(ccs, pk, secretWitness)
if err != nil {
panic(err)
} else {
fmt.Println("proof")
}
err = groth16.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
} else {
fmt.Println("verify")
}
}

Expand Down
12 changes: 0 additions & 12 deletions std/algebra/emulated/sw_bn254/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,26 @@ func ExamplePairing() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
secretWitness, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness")
}
publicWitness, err := secretWitness.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness")
}
proof, err := groth16.Prove(ccs, pk, secretWitness)
if err != nil {
panic(err)
} else {
fmt.Println("proof")
}
err = groth16.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
} else {
fmt.Println("verify")
}
}

Expand Down
12 changes: 0 additions & 12 deletions std/algebra/emulated/sw_bw6761/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,26 @@ func ExamplePairing() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
secretWitness, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness")
}
publicWitness, err := secretWitness.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness")
}
proof, err := groth16.Prove(ccs, pk, secretWitness)
if err != nil {
panic(err)
} else {
fmt.Println("proof")
}
err = groth16.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
} else {
fmt.Println("verify")
}
}

Expand Down
3 changes: 0 additions & 3 deletions std/commitments/kzg/native_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kzg_test

import (
"crypto/rand"
"fmt"

"github.com/consensys/gnark-crypto/ecc"
fr_bls12377 "github.com/consensys/gnark-crypto/ecc/bls12-377/fr"
Expand Down Expand Up @@ -126,6 +125,4 @@ func Example_native() {
if err != nil {
panic("circuit verification failed: " + err.Error())
}
fmt.Println("done")
// Output: done
}
2 changes: 0 additions & 2 deletions std/commitments/kzg/nonnative_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,4 @@ func Example_emulated() {
if err != nil {
panic("circuit verification failed: " + err.Error())
}
fmt.Println("done")
// Output: done
}
21 changes: 2 additions & 19 deletions std/lookup/logderivlookup/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,27 @@ func Example() {
ccs, err := frontend.Compile(field, r1cs.NewBuilder, &LookupCircuit{})
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
secretWitness, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness")
}
publicWitness, err := secretWitness.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness")
}
proof, err := groth16.Prove(ccs, pk, secretWitness)
if err != nil {
panic(err)
} else {
fmt.Println("proof")
}
err = groth16.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
} else {
fmt.Println("verify")
}
// Output:
// compiled
// setup done
// secret witness
// public witness
// proof
// verify
fmt.Println("done")
// Output: done
}
23 changes: 4 additions & 19 deletions std/math/cmp/doc_isless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cmp_test

import (
"fmt"
"math/big"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
"github.com/consensys/gnark/std/math/cmp"
"math/big"
)

// sortCheckerCircuit is a circuit that uses BoundedComparator.IsLess method to
Expand Down Expand Up @@ -42,43 +43,27 @@ func ExampleBoundedComparator_IsLess() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
secretWitness, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness")
}
publicWitness, err := secretWitness.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness")
}
proof, err := groth16.Prove(ccs, pk, secretWitness)
if err != nil {
panic(err)
} else {
fmt.Println("proof")
}
err = groth16.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
} else {
fmt.Println("verify")
}
// Output: compiled
// setup done
// secret witness
// public witness
// proof
// verify
fmt.Println("done")
// Output: done
}
20 changes: 2 additions & 18 deletions std/math/emulated/doc_example_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,27 @@ func ExampleField() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
witnessData, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness parsed")
}
publicWitnessData, err := witnessData.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness parsed")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
proof, err := groth16.Prove(ccs, pk, witnessData, backend.WithSolverOptions(solver.WithHints(emulated.GetHints()...)))
if err != nil {
panic(err)
} else {
fmt.Println("proved")
}
err = groth16.Verify(proof, vk, publicWitnessData)
if err != nil {
panic(err)
} else {
fmt.Println("verified")
}
// Output: compiled
// secret witness parsed
// public witness parsed
// setup done
// proved
// verified
fmt.Println("done")
// Output: done
}
20 changes: 2 additions & 18 deletions std/math/emulated/field_hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,43 +74,27 @@ func ExampleField_NewHint() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
witnessData, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness parsed")
}
publicWitnessData, err := witnessData.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness parsed")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
proof, err := groth16.Prove(ccs, pk, witnessData, backend.WithSolverOptions(solver.WithHints(HintExample)))
if err != nil {
panic(err)
} else {
fmt.Println("proved")
}
err = groth16.Verify(proof, vk, publicWitnessData)
if err != nil {
panic(err)
} else {
fmt.Println("verified")
}
// Output: compiled
// secret witness parsed
// public witness parsed
// setup done
// proved
// verified
fmt.Println("done")
// Output: done
}
21 changes: 2 additions & 19 deletions std/multicommit/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,27 @@ func ExampleWithCommitment() {
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
secretWitness, err := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness")
}
publicWitness, err := secretWitness.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness")
}
proof, err := groth16.Prove(ccs, pk, secretWitness)
if err != nil {
panic(err)
} else {
fmt.Println("proof")
}
err = groth16.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
} else {
fmt.Println("verify")
}
// Output:
// compiled
// setup done
// secret witness
// public witness
// proof
// verify
fmt.Println("done")
// Output: done
}
Loading

0 comments on commit 4dbc3c6

Please sign in to comment.