kilic / bls12-381

High-speed BLS12-381 implementation in Go
Apache License 2.0
124 stars 47 forks source link

`Affine(p *PointG1)` changes the underlying PointG1 #37

Open AnomalRoil opened 2 years ago

AnomalRoil commented 2 years ago

Currently, the Affine function is calling g.affine(p, p): https://github.com/kilic/bls12-381/blob/3a0f2553a3b9888a7201144592780f2300ad9ffb/g1.go#L336-L338

But then it changes the underlying point p, because of this Set: https://github.com/kilic/bls12-381/blob/3a0f2553a3b9888a7201144592780f2300ad9ffb/g1.go#L352-L355

This is unexpected from a function that's supposed to return an affine representation, since it actually mutates the point (and can cause nasty race conditions in code assuming the Affine is really just a getter and not a setter.)