From 7fcfb98a28d6db9e982b60ab6d16fa0f79313baa Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Fri, 20 Jun 2025 10:31:28 +0200 Subject: [PATCH 1/3] crypto/bn256/gnark: align marshaling behavior --- crypto/bn256/gnark/g2.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crypto/bn256/gnark/g2.go b/crypto/bn256/gnark/g2.go index 07452cc2d870..51979f949240 100644 --- a/crypto/bn256/gnark/g2.go +++ b/crypto/bn256/gnark/g2.go @@ -39,16 +39,16 @@ func (g *G2) Unmarshal(buf []byte) (int, error) { g.inner.Y.A1.SetZero() return 128, nil } - if err := g.inner.X.A0.SetBytesCanonical(buf[0:32]); err != nil { + if err := g.inner.X.A1.SetBytesCanonical(buf[0:32]); err != nil { return 0, err } - if err := g.inner.X.A1.SetBytesCanonical(buf[32:64]); err != nil { + if err := g.inner.X.A0.SetBytesCanonical(buf[32:64]); err != nil { return 0, err } - if err := g.inner.Y.A0.SetBytesCanonical(buf[64:96]); err != nil { + if err := g.inner.Y.A1.SetBytesCanonical(buf[64:96]); err != nil { return 0, err } - if err := g.inner.Y.A1.SetBytesCanonical(buf[96:128]); err != nil { + if err := g.inner.Y.A0.SetBytesCanonical(buf[96:128]); err != nil { return 0, err } @@ -69,17 +69,17 @@ func (g *G2) Unmarshal(buf []byte) (int, error) { func (g *G2) Marshal() []byte { output := make([]byte, 128) - xA0Bytes := g.inner.X.A0.Bytes() - copy(output[:32], xA0Bytes[:]) - xA1Bytes := g.inner.X.A1.Bytes() - copy(output[32:64], xA1Bytes[:]) + copy(output[:32], xA1Bytes[:]) - yA0Bytes := g.inner.Y.A0.Bytes() - copy(output[64:96], yA0Bytes[:]) + xA0Bytes := g.inner.X.A0.Bytes() + copy(output[32:64], xA0Bytes[:]) yA1Bytes := g.inner.Y.A1.Bytes() - copy(output[96:128], yA1Bytes[:]) + copy(output[64:96], yA1Bytes[:]) + + yA0Bytes := g.inner.Y.A0.Bytes() + copy(output[96:128], yA0Bytes[:]) return output } From a29786b48040893d3f79b8855772078c9086c9a6 Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Fri, 20 Jun 2025 10:44:02 +0200 Subject: [PATCH 2/3] crypto/bn256/gnark: align marshaling behavior --- crypto/bn256/gnark/g2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/bn256/gnark/g2.go b/crypto/bn256/gnark/g2.go index 51979f949240..96fd3fe0c0e6 100644 --- a/crypto/bn256/gnark/g2.go +++ b/crypto/bn256/gnark/g2.go @@ -21,7 +21,7 @@ type G2 struct { // Unmarshal deserializes `buf` into `g` // // The input is expected to be in the EVM format: -// 128 bytes: [32-byte x.0][32-byte x.1][32-byte y.0][32-byte y.1] +// 128 bytes: [32-byte x.1][32-byte x.0][32-byte y.1][32-byte y.0] // where each value is a big-endian integer. // // This method also checks whether the point is on the From b2311cb1194ac0c3840a3d785f35181670860a4d Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Fri, 20 Jun 2025 10:44:29 +0200 Subject: [PATCH 3/3] crypto/bn256/gnark: align marshaling behavior --- crypto/bn256/gnark/g2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/bn256/gnark/g2.go b/crypto/bn256/gnark/g2.go index 96fd3fe0c0e6..48a797e5a722 100644 --- a/crypto/bn256/gnark/g2.go +++ b/crypto/bn256/gnark/g2.go @@ -64,7 +64,7 @@ func (g *G2) Unmarshal(buf []byte) (int, error) { // Marshal serializes the point into a byte slice. // // The output is in EVM format: 128 bytes total. -// [32-byte x.0][32-byte x.1][32-byte y.0][32-byte y.1] +// [32-byte x.1][32-byte x.0][32-byte y.1][32-byte y.0] // where each value is a big-endian integer. func (g *G2) Marshal() []byte { output := make([]byte, 128)