Skip to content

Commit 8ee0391

Browse files
committed
bn256: fix String() method
Previously, when g.p == nil, String() crashed. In other method like Add(), a point with g.p==nil is treated as an identity element.
1 parent a4c6cb3 commit 8ee0391

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: bn256/bn256.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func RandomG1(r io.Reader) (*big.Int, *G1, error) {
5454
}
5555

5656
func (e *G1) String() string {
57+
if e.p == nil {
58+
e.p = newCurvePoint(nil)
59+
}
5760
return "bn256.G1" + e.p.String()
5861
}
5962

@@ -175,6 +178,9 @@ func RandomG2(r io.Reader) (*big.Int, *G2, error) {
175178
}
176179

177180
func (e *G2) String() string {
181+
if e.p == nil {
182+
e.p = newTwistPoint(nil)
183+
}
178184
return "bn256.G2" + e.p.String()
179185
}
180186

@@ -277,8 +283,11 @@ type GT struct {
277283
p *gfP12
278284
}
279285

280-
func (g *GT) String() string {
281-
return "bn256.GT" + g.p.String()
286+
func (e *GT) String() string {
287+
if e.p == nil {
288+
e.p = newGFp12(nil)
289+
}
290+
return "bn256.GT" + e.p.String()
282291
}
283292

284293
// ScalarMult sets e to a*k and then returns e.

0 commit comments

Comments
 (0)