-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
bn256: added consensys/gurvy bn256 implementation #21812
Conversation
It's merged |
Well then I know what to work on next :D |
crypto/bn256/bn256_fuzz.go
Outdated
@@ -2,14 +2,15 @@ | |||
// Use of this source code is governed by a BSD-style license that can be found | |||
// in the LICENSE file. | |||
|
|||
// +build gofuzz | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: add the build flags back in
Also, it's super-picky about input -- essentially disqualifyiing everything that is not exactly the correct size. A more forgiving implementation could instead read input in chunks of |
Maybe let's do something like this too: diff --git a/crypto/bn256/bn256_fuzz.go b/crypto/bn256/bn256_fuzz.go
index 6aa1421170..dda80ff149 100644
--- a/crypto/bn256/bn256_fuzz.go
+++ b/crypto/bn256/bn256_fuzz.go
@@ -8,42 +8,44 @@ package bn256
import (
"bytes"
+ "fmt"
+ "io"
"math/big"
cloudflare "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare"
google "github.com/ethereum/go-ethereum/crypto/bn256/google"
)
-// FuzzAdd fuzzez bn256 addition between the Google and Cloudflare libraries.
-func FuzzAdd(data []byte) int {
- // Ensure we have enough data in the first place
- if len(data) != 128 {
- return 0
+func getG1Points(input io.Reader) (*cloudflare.G1, *google.G1) {
+ xc, err := cloudflare.RandomG1()
+ if err != nil {
+ // insufficient input
+ return nil, nil
+ }
+ dat, err := xc.MarshalText()
+ if err != nil {
+ panic("marshalling failed")
}
- // Ensure both libs can parse the first curve point
- xc := new(cloudflare.G1)
- _, errc := xc.Unmarshal(data[:64])
-
xg := new(google.G1)
- _, errg := xg.Unmarshal(data[:64])
-
- if (errc == nil) != (errg == nil) {
- panic("parse mismatch")
- } else if errc != nil {
- return 0
+ if _, err := xg.Unmarshal(dat); err != nil {
+ panic(fmt.Sprintf("Could not marshal couldflare -> google:", err))
}
- // Ensure both libs can parse the second curve point
- yc := new(cloudflare.G1)
- _, errc = yc.Unmarshal(data[64:])
+ return xc, xg
- yg := new(google.G1)
- _, errg = yg.Unmarshal(data[64:])
+}
- if (errc == nil) != (errg == nil) {
- panic("parse mismatch")
- } else if errc != nil {
+// FuzzAdd fuzzez bn256 addition between the Google and Cloudflare libraries.
+func FuzzAdd(data []byte) int {
+ input := bytes.NewReader(data)
+ xc, xg := getG1Points(input)
+ if xc == nil {
return 0
}
+ yc, yg := getG1Points(input)
+ if yc == nil {
+ return 0
+ }
+ // Ensure both libs can parse the second curve point
// Add the two points and ensure they result in the same output
rc := new(cloudflare.G1)
rc.Add(xc, yc) |
Or let me make an alternative PR about that first... ? |
I think that should be an alternative pr @holiman (that could get merged in first) |
@MariusVanDerWijden hi :) . We're making a pass on the |
Perfect! thank you very much @gbotrel |
00d0077
to
2c1ef34
Compare
54d0871
to
284e4ef
Compare
One problem we currently face is that |
Hmm. Sounds like this is inherent to Gurvy, right? So seems like there's nothing you can really do here? @MariusVanDerWijden |
@MariusVanDerWijden this issue should be fixed, using [email protected] should work, let me know if you have other issues, happy to help. |
284e4ef
to
77b1bed
Compare
@MariusVanDerWijden is this still WIP or good to go? |
I think its good to go, will rebase once more |
8c4750c
to
e21a527
Compare
@MariusVanDerWijden can you make Cheers, |
e21a527
to
bdc5f73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please look into the go.mod changes
go.mod
Outdated
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf | ||
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498 | ||
github.com/edsrzf/mmap-go v1.0.0 | ||
github.com/fatih/color v1.3.0 | ||
github.com/fatih/color v1.7.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are probably not actual changes related to this pr, are they? Might need a rebase ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's super weird, whenever I run go test ./...
it just updates the go-mod
with some unrelated changes. I removed them now by hand
bdc5f73
to
239ba97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pr adds consensys' gurvy bn256 variant into the code for differential fuzzing.
Since it is specially built with the correct parameters we don't need to vendor it.