github.com/ethereum/go-ethereum@v1.16.1/crypto/bn256/gnark/native_format_test.go (about) 1 package bn256 2 3 import ( 4 "testing" 5 6 "github.com/consensys/gnark-crypto/ecc/bn254" 7 ) 8 9 func TestNativeGnarkFormatIncompatibility(t *testing.T) { 10 // Use official gnark serialization 11 _, _, g1Gen, _ := bn254.Generators() 12 wrongSer := g1Gen.Bytes() 13 14 var evmG1 G1 15 _, err := evmG1.Unmarshal(wrongSer[:]) 16 if err == nil { 17 t.Fatalf("points serialized using the official bn254 serialization algorithm, should not work with the evm format") 18 } 19 } 20 21 func TestSerRoundTrip(t *testing.T) { 22 _, _, g1Gen, g2Gen := bn254.Generators() 23 24 expectedG1 := G1{inner: g1Gen} 25 bytesG1 := expectedG1.Marshal() 26 27 expectedG2 := G2{inner: g2Gen} 28 bytesG2 := expectedG2.Marshal() 29 30 var gotG1 G1 31 gotG1.Unmarshal(bytesG1) 32 33 var gotG2 G2 34 gotG2.Unmarshal(bytesG2) 35 36 if !expectedG1.inner.Equal(&gotG1.inner) { 37 t.Errorf("serialization roundtrip failed for G1") 38 } 39 if !expectedG2.inner.Equal(&gotG2.inner) { 40 t.Errorf("serialization roundtrip failed for G2") 41 } 42 }