Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: eddsa factorizing and code cleaning #285

Merged
merged 15 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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