tests/fuzzers/bn256: add PairingCheck fuzzer#27252
Merged
holiman merged 2 commits intoethereum:masterfrom May 16, 2023
Merged
Conversation
holiman
reviewed
May 11, 2023
Contributor
holiman
left a comment
There was a problem hiding this comment.
IMO let's keep it in one method, the inputs are the same (and probably the interesting paths/inputs too), so splitting it doesn't make much sense to me
Comment on lines
160
to
184
Contributor
There was a problem hiding this comment.
Suggested change
| // gnark uses a different pairing algorithm than google & cloudflare, so the results might not match up | |
| // which is not a problem because of the bilinearity of the pairing. | |
| return 1 | |
| } | |
| func FuzzPairingCheck(data []byte) int { | |
| input := bytes.NewReader(data) | |
| pc, pg, ps := getG1Points(input) | |
| if pc == nil { | |
| return 0 | |
| } | |
| tc, tg, ts := getG2Points(input) | |
| if tc == nil { | |
| return 0 | |
| } | |
| // Pair the two points and ensure they result in the same output | |
| clOK := cloudflare.PairingCheck([]*cloudflare.G1{pc}, []*cloudflare.G2{tc}) | |
| gOK := google.PairingCheck([]*google.G1{pg}, []*google.G2{tg}) | |
| if clOK != gOK { | |
| panic("pairing check mismatch: cloudflare/google") | |
| } | |
| cOK, err := bn254.PairingCheck([]bn254.G1Affine{*ps}, []bn254.G2Affine{*ts}) | |
| // gnark uses a different pairing algorithm than google & cloudflare, so the results might not match up | |
| // which is not a problem because of the bilinearity of the pairing. | |
| // Pair the two points and ensure they result in the same output | |
| clOK := cloudflare.PairingCheck([]*cloudflare.G1{pc}, []*cloudflare.G2{tc}) | |
| gOK := google.PairingCheck([]*google.G1{pg}, []*google.G2{tg}) | |
| if clOK != gOK { | |
| panic("pairing check mismatch: cloudflare/google") | |
| } | |
| cOK, err := bn254.PairingCheck([]bn254.G1Affine{*ps}, []bn254.G2Affine{*ts}) |
Contributor
There was a problem hiding this comment.
Suggested change
| pc, pg, _ := getG1Points(input) | |
| pc, pg, ps := getG1Points(input) |
Contributor
There was a problem hiding this comment.
Suggested change
| tc, tg, _ := getG2Points(input) | |
| tc, tg, ts := getG2Points(input) |
holiman
reviewed
May 11, 2023
Contributor
There was a problem hiding this comment.
Suggested change
| compile_fuzzer tests/fuzzers/bn256 FuzzPairingCheck fuzzBn256PairingCheck |
0a02166 to
6e77459
Compare
holiman
approved these changes
May 16, 2023
devopsbo3
pushed a commit
to HorizenOfficial/go-ethereum
that referenced
this pull request
Nov 10, 2023
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
devopsbo3
added a commit
to HorizenOfficial/go-ethereum
that referenced
this pull request
Nov 10, 2023
This reverts commit 625cbea.
devopsbo3
added a commit
to HorizenOfficial/go-ethereum
that referenced
this pull request
Nov 10, 2023
This reverts commit 625cbea.
19 tasks
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Dec 9, 2024
* tests/fuzzers/bn256: scale gnark result by constant * tests/fuzzers/bn256: scale gnark result by constant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR removes Gnark from the Pair fuzzer. Because gnark uses a different pairing algorithm, it might produce a different result than the other implementations. However this is not an issue, since the bilinearity of a pairing means both results are correct.
In order to preserve some fuzzing of the gnark pairing, I added a fuzzer that fuzzes the pairingCheck function, which does a pairing and verifies that the result is not equal to one. This is the function we use in ethereum, the pairing algorithm is not under consensus, only the pairing check algorithm.