-
Notifications
You must be signed in to change notification settings - Fork 360
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
Refactored backend and frontend to avoid use of build tags (curve dependency) #23
Changes from 18 commits
d0029c5
1bf01be
9bd28bb
299e7d5
98137f3
3b1144c
0dc462c
13c8e70
60456e9
b6db966
c6ad99b
f898a7c
5be7e7e
483fba1
e396b06
1907ffa
6fedfbb
e0ff260
2150ebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package backend | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDuplicateAssignment(t *testing.T) { | ||
|
||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Fatalf("duplicate assignment will panic.") | ||
} | ||
}() | ||
|
||
a := NewAssignment() | ||
a.Assign(Public, "x", 1) | ||
a.Assign(Secret, "x", 1) | ||
} | ||
|
||
func TestVisibility(t *testing.T) { | ||
assert := require.New(t) | ||
a := NewAssignment() | ||
a.Assign(Public, "x", 1) | ||
a.Assign(Secret, "y", 1) | ||
|
||
assert.True(a["x"].IsPublic) | ||
assert.False(a["y"].IsPublic) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,12 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to remove the +build tags :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this file inside bls377 and nowhere else? Should we generate fft_test from template, too? |
||
*/ | ||
|
||
package groth16 | ||
package backend_bls377 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/consensys/gnark/curve/fr" | ||
"github.com/consensys/gurvy/bls377/fr" | ||
) | ||
|
||
func TestFFT(t *testing.T) { | ||
|
@@ -47,7 +47,7 @@ func TestFFT(t *testing.T) { | |
fftExpected[1].SetString("176691886079129423236139828277131126232163084109021849887887564") | ||
fftExpected[2].SetString("8444461749428370424248824938781546531375899335154063827935233455917408882477") | ||
fftExpected[3].SetString("8444461749428193732362745809358310391547622204027831664851124434067521319365") | ||
fft(poly, w) | ||
FFT(poly, w) | ||
|
||
for i := 0; i < 4; i++ { | ||
if !poly[i].Equal(&fftExpected[i]) { | ||
|
@@ -90,16 +90,16 @@ func BenchmarkFFT(b *testing.B) { | |
rootOfUnity.SetString(RootOfUnityStr) | ||
|
||
const nbGates = 500000 | ||
subGroup := newDomain(rootOfUnity, MaxOrder, nbGates) | ||
subGroup := NewDomain(rootOfUnity, MaxOrder, nbGates) | ||
|
||
a := make([]fr.Element, subGroup.cardinality) | ||
a := make([]fr.Element, subGroup.Cardinality) | ||
for i := 0; i < len(a); i++ { | ||
a[i].SetRandom() | ||
} | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
fft(a, subGroup.generator) | ||
FFT(a, subGroup.Generator) | ||
} | ||
} | ||
|
||
|
@@ -115,18 +115,18 @@ func TestNewDomain(t *testing.T) { | |
for i := uint(0); i < uint(25); i++ { | ||
m := 1 << i // m = 2^i | ||
|
||
S := newDomain(rootOfUnity, MaxOrder, m) | ||
S := NewDomain(rootOfUnity, MaxOrder, m) | ||
|
||
// test S.GeneratorSqRt^2 == S.Generator | ||
var generatorSqRtSq fr.Element | ||
generatorSqRtSq.Mul(&S.generatorSqRt, &S.generatorSqRt) | ||
if generatorSqRtSq != S.generator { | ||
generatorSqRtSq.Mul(&S.GeneratorSqRt, &S.GeneratorSqRt) | ||
if generatorSqRtSq != S.Generator { | ||
t.Error("GeneratorSqRt^2 != Generator") | ||
} | ||
|
||
// test order of S.Generator | ||
var generatorPow fr.Element | ||
generatorPow.Set(&S.generator) | ||
generatorPow.Set(&S.Generator) | ||
for j := uint(0); j < i; j++ { | ||
if generatorPow.Equal(&one) { | ||
t.Error("Generator order too small: expected:", m, "received:", 1<<j) | ||
|
@@ -141,27 +141,27 @@ func TestNewDomain(t *testing.T) { | |
|
||
// test S.Generator * S.GeneratorInv == 1 | ||
var inverseTest fr.Element | ||
inverseTest.Mul(&S.generator, &S.generatorInv) | ||
inverseTest.Mul(&S.Generator, &S.GeneratorInv) | ||
if !inverseTest.Equal(&one) { | ||
t.Error("Generator inverse incorrect: expected: 1 received:", inverseTest.FromMont()) | ||
break | ||
} | ||
|
||
// test S.GeneratorSqRt * S.GeneratorSqRtInv == 1 | ||
inverseTest.Mul(&S.generatorSqRt, &S.generatorSqRtInv) | ||
inverseTest.Mul(&S.GeneratorSqRt, &S.GeneratorSqRtInv) | ||
if !inverseTest.Equal(&one) { | ||
t.Error("GeneratorSqRt inverse incorrect: expected: 1 received:", inverseTest.FromMont()) | ||
break | ||
} | ||
|
||
// test S.Cardinality, S.CardinalityInv | ||
if S.cardinality != m { | ||
t.Error("Cardinality incorrect: expected:", m, "received:", S.cardinality) | ||
if S.Cardinality != m { | ||
t.Error("Cardinality incorrect: expected:", m, "received:", S.Cardinality) | ||
break | ||
} | ||
var cardinalityelement fr.Element | ||
cardinalityelement.SetUint64(uint64(S.cardinality)) | ||
inverseTest.Mul(&cardinalityelement, &S.cardinalityInv) | ||
cardinalityelement.SetUint64(uint64(S.Cardinality)) | ||
inverseTest.Mul(&cardinalityelement, &S.CardinalityInv) | ||
if !inverseTest.Equal(&one) { | ||
t.Error("CardinalityInv incorrect: expected: 1 received:", inverseTest.FromMont()) | ||
break | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
while is that file commited? need to restore these tests maybe?