Skip to content

Commit

Permalink
clone point to avoid race condition in MakeAffine
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharm committed Apr 3, 2024
1 parent 54d4f93 commit 19712af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions pairing/bn254/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (s *Suite) Pair(p1 kyber.Point, p2 kyber.Point) kyber.Point {
return s.GT().Point().(*pointGT).Pair(p1, p2)
}

// NB: Not safe for concurrent calls
func (s *Suite) ValidatePairing(p1, p2, inv1, inv2 kyber.Point) bool {
p2.(*pointG2).g.MakeAffine()
inv2.(*pointG2).g.MakeAffine()
Expand Down
26 changes: 14 additions & 12 deletions pairing/bn254/twist.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,25 @@ func (c *twistPoint) Mul(a *twistPoint, scalar *big.Int) {
}

func (c *twistPoint) MakeAffine() {
if c.z.IsOne() {
res := c.Clone()
if res.z.IsOne() {
return
} else if c.z.IsZero() {
c.x.SetZero()
c.y.SetOne()
c.t.SetZero()
} else if res.z.IsZero() {
res.x.SetZero()
res.y.SetOne()
res.t.SetZero()
return
}

zInv := (&gfP2{}).Invert(&c.z)
t := (&gfP2{}).Mul(&c.y, zInv)
zInv := (&gfP2{}).Invert(&res.z)
t := (&gfP2{}).Mul(&res.y, zInv)
zInv2 := (&gfP2{}).Square(zInv)
c.y.Mul(t, zInv2)
t.Mul(&c.x, zInv2)
c.x.Set(t)
c.z.SetOne()
c.t.SetOne()
res.y.Mul(t, zInv2)
t.Mul(&res.x, zInv2)
res.x.Set(t)
res.z.SetOne()
res.t.SetOne()
c.Set(res)
}

func (c *twistPoint) Neg(a *twistPoint) {
Expand Down

0 comments on commit 19712af

Please sign in to comment.