Skip to content

Commit

Permalink
refactor: eddsa factorizing and code cleaning (#285)
Browse files Browse the repository at this point in the history
* build: updated to latest gnark-crypto

* build: updated to latest gnark-crypto

* refactor: introduce Curve interface in std/ and updated eddsa tests

* feat: added std/eddsa publicKey and signature assign helpers

* refactor(std): merged twistededwards and bandersnatch. IsOnCurve failing for bandersnatch

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* test: test all twisted ed curve operations

* Fixes #283 : ensure test.Assert compile cache handles different objects of same type (#284)

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* fix: apply pr patch

* style: make twistededwards/Point methods package private
  • Loading branch information
gbotrel committed Mar 22, 2022
1 parent 45dacc0 commit 3adc130
Show file tree
Hide file tree
Showing 20 changed files with 1,008 additions and 2,005 deletions.
19 changes: 8 additions & 11 deletions examples/rollup/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package rollup

import (
tedwards "github.com/consensys/gnark-crypto/ecc/twistededwards"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/accumulator/merkle"
"github.com/consensys/gnark/std/algebra/twistededwards"
Expand Down Expand Up @@ -87,18 +88,8 @@ type TransferConstraints struct {
}

func (circuit *Circuit) postInit(api frontend.API) error {
// edward curve params
params, err := twistededwards.NewEdCurve(api.Compiler().Curve())
if err != nil {
return err
}

for i := 0; i < batchSize; i++ {
// setting sender public key
circuit.PublicKeysSender[i].Curve = params

// setting receiver public key
circuit.PublicKeysReceiver[i].Curve = params

// setting the sender accounts before update
circuit.SenderAccountsBefore[i].PubKey = circuit.PublicKeysSender[i]
Expand Down Expand Up @@ -163,7 +154,13 @@ func verifyTransferSignature(api frontend.API, t TransferConstraints, hFunc mimc
hFunc.Write(t.Nonce, t.Amount, t.SenderPubKey.A.X, t.SenderPubKey.A.Y, t.ReceiverPubKey.A.X, t.ReceiverPubKey.A.Y)
htransfer := hFunc.Sum()

err := eddsa.Verify(api, t.Signature, htransfer, t.SenderPubKey)
curve, err := twistededwards.NewEdCurve(api, tedwards.BN254)
if err != nil {
return err
}

hFunc.Reset()
err = eddsa.Verify(curve, t.Signature, htransfer, t.SenderPubKey, &hFunc)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion examples/rollup/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ func createAccount(i int) (Account, eddsa.PrivateKey) {
src := rand.NewSource(int64(i))
r := rand.New(src)

privkey, _ = eddsa.GenerateKey(r)
pkey, err := eddsa.GenerateKey(r)
if err != nil {
panic(err)
}
privkey = *pkey

acc.pubKey = privkey.PublicKey

return acc, privkey
Expand Down
1 change: 1 addition & 0 deletions frontend/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func parseCircuit(builder Builder, circuit Circuit) (err error) {
// leafs are Constraints that need to be initialized in the context of compiling a circuit
var handler schema.LeafHandler = func(visibility schema.Visibility, name string, tInput reflect.Value) error {
if tInput.CanSet() {
// log.Trace().Str("name", name).Str("visibility", visibility.String()).Msg("init input wire")
switch visibility {
case schema.Secret:
tInput.Set(reflect.ValueOf(builder.AddSecretVariable(name)))
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/consensys/gnark
go 1.17

require (
github.com/consensys/bavard v0.1.9
github.com/consensys/gnark-crypto v0.6.1
github.com/consensys/bavard v0.1.10
github.com/consensys/gnark-crypto v0.6.2-0.20220317143658-fb0d80a11bf4
github.com/fxamacker/cbor/v2 v2.2.0
github.com/leanovate/gopter v0.2.9
github.com/rs/zerolog v1.26.1
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/consensys/bavard v0.1.9 h1:t9wg3/7Ko73yE+eKcavgMYcPMO1hinadJGlbSCdXTiM=
github.com/consensys/bavard v0.1.9/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.6.1 h1:MuWaJyWzSw8wQUOfiZOlRwYjfweIj8dM/u2NN6m0O04=
github.com/consensys/gnark-crypto v0.6.1/go.mod h1:s41Bl3YIpNgu/zdvlSzf/xZkyV8MUmoBY96RmuB8x70=
github.com/consensys/bavard v0.1.10 h1:1I/IvY7bkX/O7QLNCEuV2+YBKdTetzw3gnBbvFaWiEE=
github.com/consensys/bavard v0.1.10/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.6.2-0.20220317140519-d6352e5d4ded h1:sAAl/I9EYA7zsfjnPQ+5h6X9+Fx2HBbFGFsVHlG6t/Y=
github.com/consensys/gnark-crypto v0.6.2-0.20220317140519-d6352e5d4ded/go.mod h1:BnexKTAHX6j7zpGXR/s6E/R0tyYtbnXlbhIMQkNdcPs=
github.com/consensys/gnark-crypto v0.6.2-0.20220317143658-fb0d80a11bf4 h1:ZsuTwNqDe83xtYP8SplQ9iOoXgOoLg9WzP04VfqOjGc=
github.com/consensys/gnark-crypto v0.6.2-0.20220317143658-fb0d80a11bf4/go.mod h1:BnexKTAHX6j7zpGXR/s6E/R0tyYtbnXlbhIMQkNdcPs=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
Binary file modified internal/stats/latest.stats
Binary file not shown.
Binary file not shown.
79 changes: 0 additions & 79 deletions std/algebra/twistededwards/bandersnatch/curve.go

This file was deleted.

Loading

0 comments on commit 3adc130

Please sign in to comment.