Skip to content

Commit 31733da

Browse files
gbotrelbgravenorstNicolasMassart
authored
v0.6.0 (#10)
* remove gnarkd section * updated groth16 benchmarks with gnark v0.5.0 numbers * Added redirect. Signed-off-by: bgravenorst <[email protected]> * updating submodule to latest * docs: cs *frontend.ConstraintSystem to api frontend.API * docs: reflect Assert changes in debug_test.md * docs: added Hints documentation * update submodule remove failing minify module * docs: remove curveID from Define * docs: minor clean up * fix vale error * fix markdownlint errors * fix markdownlint errors Co-authored-by: bgravenorst <[email protected]> Co-authored-by: Nicolas MASSART <[email protected]>
1 parent 2a1d695 commit 31733da

File tree

9 files changed

+57
-62
lines changed

9 files changed

+57
-62
lines changed

docs/Concepts/schemes_curves.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Proving schemes and curves
66

77
`gnark` supports two proving schemes [Groth16](https://eprint.iacr.org/2016/260.pdf) and
88
[PlonK](https://eprint.iacr.org/2019/953.pdf). These schemes can be instantiated with any of the
9-
following four elliptic curves: *BN254*, *BLS12-381*, *BLS12-377* or *BW6-761*.
9+
following elliptic curves: *BN254*, *BLS12-381*, *BLS12-377*, *BLS24-315*, *BW6-633* or *BW6-761*.
1010

1111
An ID is supplied to `gnark` to choose the proving scheme and the instantiating curve.
1212

docs/HowTo/debug_test.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,44 @@ witness.
2020
the solver couldn't perform an operation needed to verify a constraint.
2121
For example, a division by 0.
2222

23+
!!! tip
24+
You can run the program with `-tags=debug` to display a more verbose stack trace.
25+
2326
### Print values
2427

25-
The easiest way to debug a circuit is to use `cs.Println()`, which behaves like `fmt.Println`, except
28+
The easiest way to debug a circuit is to use `api.Println()`, which behaves like `fmt.Println`, except
2629
it outputs the values when they are solved. For example:
2730

2831
```go
29-
cs.Println("A.X", pubKey.A.X)
32+
api.Println("A.X", pubKey.A.X)
3033
```
3134

3235
!!! note
33-
With solving errors and `cs.Println`, `gnark` outputs a stack trace which contain the exact line number to refer to in the circuit definition.
36+
With solving errors and `api.Println`, `gnark` outputs a stack trace which contain the exact line number to refer to in the circuit definition.
3437

3538
## Test
3639

3740
You can implement tests as Go unit tests, in a `_test.go` file. For example:
3841

3942
```go
4043
// assert object wrapping testing.T
41-
assert := groth16.NewAssert(t)
44+
assert := test.NewAssert(t)
4245

4346
// declare the circuit
44-
var mimcCircuit Circuit
45-
46-
// compile the circuit into a R1CS
47-
r1cs, err := frontend.Compile(ecc.BN254, backend.GROTH16, &mimcCircuit)
48-
assert.NoError(err)
49-
50-
{
51-
// assign invalid values to a witness, ensure the proof fails
52-
var witness Circuit
53-
witness.Hash.Assign(42)
54-
witness.PreImage.Assign(42)
55-
assert.ProverFailed(r1cs, &witness)
56-
}
57-
58-
{
59-
// assign valid values to a witness, ensure the proof is valid
60-
var witness Circuit
61-
witness.PreImage.Assign(35)
62-
witness.Hash.Assign("16130099170765464552823636852555369511329944820189892919423002775646948828469")
63-
assert.ProverSucceeded(r1cs, &witness)
64-
}
47+
var cubicCircuit Circuit
48+
49+
assert.ProverFailed(&cubicCircuit, &Circuit{
50+
PreImage: frontend.Value(42),
51+
Hash: frontend.Value(42),
52+
})
53+
54+
assert.ProverSucceeded(&cubicCircuit, &Circuit{
55+
PreImage: frontend.Value(35),
56+
Hash: frontend.Value("16130099170765464552823636852555369511329944820189892919423002775646948828469"),
57+
}, test.WithCurves(ecc.BN254))
58+
6559
```
60+
61+
See the [test package documentation](https://pkg.go.dev/github.com/consensys/gnark/[email protected]) for more details.
62+
63+
In particular, the default behavior of the assert helper is to test the circuit across all supported curves and backends, ensure correct serialization, and cross-test the constraint system solver against a `big.Int` test execution engine.

docs/HowTo/write/circuit_api.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@ description: How to write a gnark circuit
77
As described in [Circuit structure](circuit_structure.md), `MyCircuit` implements:
88

99
```go
10-
func Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error
10+
func Define(api frontend.API) error
1111
```
1212

13-
* `curveID` is injected at compile time to handle different code paths depending on the curve
14-
(for example, hash functions like MiMC have variations depending on the `curveID`)
13+
* `api` is the root object to manipulate when defining constraints.
1514

16-
* `cs` is the root object to manipulate when defining constraints.
17-
18-
Use `x² := cs.Mul(x, x)` to write $x \times x$. For example, to prove that we know the solution to
15+
Use `x² := api.Mul(x, x)` to write $x \times x$. For example, to prove that we know the solution to
1916
the cubic equation $x^3 + x + 5 = y$, write:
2017

2118
```go
22-
x3 := cs.Mul(circuit.X, circuit.X, circuit.X)
23-
cs.AssertIsEqual(circuit.Y, cs.Add(x3, circuit.X, 5))
19+
x3 := api.Mul(circuit.X, circuit.X, circuit.X)
20+
api.AssertIsEqual(circuit.Y, api.Add(x3, circuit.X, 5))
2421
```
2522

2623
!!! info
@@ -29,7 +26,7 @@ cs.AssertIsEqual(circuit.Y, cs.Add(x3, circuit.X, 5))
2926
This allows flexibility on the circuit definition side when coding, for example:
3027
3128
```go
32-
cs.Mul(X, 2, cs.Add(Y, Z, 42))
29+
api.Mul(X, 2, api.Add(Y, Z, 42))
3330
```
3431

3532
Constants bigger than base field modulus will be reduced $\mod n$.

docs/HowTo/write/circuit_structure.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A `gnark` circuit must implement the `frontend/Circuit` interface:
99
```go
1010
type Circuit interface {
1111
// Define declares the circuit's Constraints
12-
Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error
12+
Define(api frontend.API) error
1313
}
1414
```
1515

@@ -26,13 +26,13 @@ type myComponent struct {
2626
X frontend.Variable
2727
}
2828

29-
func (circuit *MyCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
29+
func (circuit *MyCircuit) Define(api frontend.API) error {
3030
// ... see Cicuit API section
3131
}
3232
```
3333

3434
At compile time, `frontend.Compile(...)` recursively parses the struct fields that contains
35-
`frontend.Variable` to build the `frontend.ConstraintSystem`.
35+
`frontend.Variable` to build the `frontend.constraintSystem`.
3636

3737
By default, a `frontend.Variable` has the `gnark:",secret"` visibility.
3838

docs/HowTo/write/instructions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Use standard `for` loops inside a circuit definition.
1515
!!! example "check that `X*X*X*X*X... == Y`"
1616

1717
```go
18-
func (circuit *Circuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
18+
func (circuit *Circuit) Define(api frontend.API) error {
1919
for i := 0; i < n; i++ {
20-
circuit.X = cs.Mul(circuit.X, circuit.X)
20+
circuit.X = api.Mul(circuit.X, circuit.X)
2121
}
22-
cs.AssertIsEqual(circuit.X, circuit.Y)
22+
api.AssertIsEqual(circuit.X, circuit.Y)
2323
return nil
2424
}
2525
```
@@ -31,7 +31,7 @@ this doesn't translate well in a *declarative* API to define the circuit, becaus
3131
of the `frontend.Compile` method is an arithmetic representation that must encode the various
3232
branches.
3333

34-
`gnark` offers `cs.Select(...)` API, which is similar to Prolog-like languages.
34+
`gnark` offers `api.Select(...)` API, which is similar to Prolog-like languages.
3535

3636
```go
3737
// Select if b is true, yields i1 else yields i2

docs/HowTo/write/standard_library.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ We provide the following functions in `gnark/std`:
1414
=== "MiMC hash"
1515

1616
```go
17-
func (circuit *mimcCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
17+
func (circuit *mimcCircuit) Define(api frontend.API) error {
1818
// ...
19-
hFunc, _ := mimc.NewMiMC("seed", curveID)
19+
hFunc, _ := mimc.NewMiMC("seed", api.Curve())
2020
computedHash := hFunc.Hash(cs, circuit.Data)
2121
// ...
2222
}
@@ -31,8 +31,8 @@ We provide the following functions in `gnark/std`:
3131
Message frontend.Variable `gnark:",public"`
3232
}
3333

34-
func (circuit *eddsaCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
35-
edCurve, _ := twistededwards.NewEdCurve(curveID)
34+
func (circuit *eddsaCircuit) Define(api frontend.API) error {
35+
edCurve, _ := twistededwards.NewEdCurve(api.Curve())
3636
circuit.PublicKey.Curve = edCurve
3737

3838
eddsa.Verify(cs, circuit.Signature, circuit.Message, circuit.PublicKey)
@@ -48,8 +48,8 @@ We provide the following functions in `gnark/std`:
4848
Path, Helper []frontend.Variable
4949
}
5050

51-
func (circuit *merkleCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
52-
hFunc, _ := mimc.NewMiMC("seed", curveID)
51+
func (circuit *merkleCircuit) Define(api frontend.API) error {
52+
hFunc, _ := mimc.NewMiMC("seed", api.Curve())
5353
merkle.VerifyProof(cs, hFunc, circuit.RootHash, circuit.Path, circuit.Helper)
5454
return nil
5555
}
@@ -66,7 +66,7 @@ We provide the following functions in `gnark/std`:
6666
Hash frontend.Variable
6767
}
6868

69-
func (circuit *verifierCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
69+
func (circuit *verifierCircuit) Define(api frontend.API) error {
7070
// pairing data
7171
var pairingInfo sw.PairingContext
7272
pairingInfo.Extension = fields.GetBLS377ExtensionFp12(cs)

docs/Tutorials/eddsa.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ It also needs a `frontend.ConstraintSystem` object, on which the functions from
156156
[gnark API](../HowTo/write/circuit_api.md) are called.
157157

158158
```go
159-
func Verify(cs *frontend.ConstraintSystem, sig Signature, msg frontend.Variable, pubKey PublicKey) error {
159+
func Verify(api frontend.API, sig Signature, msg frontend.Variable, pubKey PublicKey) error {
160160
// ...
161161
}
162162
```
@@ -172,7 +172,7 @@ import (
172172
"github.com/consensys/gnark/std/hash/mimc"
173173
)
174174
175-
func Verify(cs *frontend.ConstraintSystem, sig Signature, msg frontend.Variable, pubKey PublicKey) error {
175+
func Verify(api frontend.API, sig Signature, msg frontend.Variable, pubKey PublicKey) error {
176176
177177
// compute H(R, A, M)
178178
data := []frontend.Variable{
@@ -235,11 +235,11 @@ Next, continue the implementation with the computation of the right-hand side:
235235

236236
!!! tip "Debugging"
237237

238-
You can print values using `cs.Println` that behaves like `fmt.Println`,
238+
You can print values using `api.Println` that behaves like `fmt.Println`,
239239
except it will output the values at proving time (when they are solved).
240240

241241
```go
242-
cs.Println("A.X", pubKey.A.X)
242+
api.Println("A.X", pubKey.A.X)
243243
```
244244

245245
Until now, you have only used objects which are defined in the `gnark` standard library, for example,
@@ -251,8 +251,8 @@ Use the gnark API, to assert that the left-hand side is equal to the right-hand
251251

252252
```go
253253
// ensures that lhs==rhs
254-
cs.AssertIsEqual(lhs.X, rhs.X)
255-
cs.AssertIsEqual(lhs.Y, rhs.Y)
254+
api.AssertIsEqual(lhs.X, rhs.X)
255+
api.AssertIsEqual(lhs.Y, rhs.Y)
256256
```
257257

258258
!!! info
@@ -294,9 +294,9 @@ import (
294294
"github.com/consensys/gnark-crypto/ecc"
295295
)
296296
297-
func (circuit *eddsaCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
297+
func (circuit *eddsaCircuit) Define(api frontend.API) error {
298298
299-
params, err := twistededwards.NewEdCurve(curveID)
299+
params, err := twistededwards.NewEdCurve(api.Curve())
300300
if err != nil {
301301
return err
302302
}
@@ -419,5 +419,5 @@ Last step is to generate the proof and verify it.
419419
```go
420420
assert := groth16.NewAssert(t)
421421
var witness Circuit
422-
assert.ProverFailed(r1cs, &witness) // .ProverSucceeded
422+
assert.ProverFailed(&circuit, &witness) // .ProverSucceeded
423423
```

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ easily added.
5353
}
5454

5555
// Define declares the circuit's constraints
56-
func (circuit *Circuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
56+
func (circuit *Circuit) Define(api frontend.API) error {
5757
// hash function
58-
mimc, err := mimc.NewMiMC("seed", curveID)
58+
mimc, err := mimc.NewMiMC("seed", api.Curve())
5959

6060
// specify constraints
6161
// mimc(preImage) == hash
62-
cs.AssertIsEqual(circuit.Hash, mimc.Hash(cs, circuit.PreImage))
62+
api.AssertIsEqual(circuit.Hash, mimc.Hash(cs, circuit.PreImage))
6363

6464
return nil
6565
}

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ copyright: gnark and its documentation are licensed under Apache 2.0 license
1919
#extra project info and template customisation
2020
extra:
2121
content_vars:
22-
gnark_version: "v0.4.0" # this is used in external URL (godoc, ...)
22+
gnark_version: "v0.6.0" # this is used in external URL (godoc, ...)
2323
logo_is_text: true
2424
latest_version_warning:
2525
url_contains: /latest/

0 commit comments

Comments
 (0)