core/vm, crypto/bn256: fix bn256 use and pairing corner case

This commit is contained in:
Péter Szilágyi
2017-08-17 16:46:46 +03:00
parent 0b978f91b6
commit 1335a6cc8c
4 changed files with 81 additions and 16 deletions

View File

@ -379,16 +379,22 @@ func Pair(g1 *G1, g2 *G2) *GT {
return &GT{optimalAte(g2.p, g1.p, new(bnPool))}
}
// PairingCheck calculates the Optimal Ate pairing for a set of points.
func PairingCheck(a []*G1, b []*G2) bool {
pool := new(bnPool)
e := newGFp12(pool)
e.SetOne()
acc := newGFp12(pool)
acc.SetOne()
for i := 0; i < len(a); i++ {
new_e := miller(b[i].p, a[i].p, pool)
e.Mul(e, new_e, pool)
if a[i].p.IsInfinity() || b[i].p.IsInfinity() {
continue
}
acc.Mul(acc, miller(b[i].p, a[i].p, pool), pool)
}
ret := finalExponentiation(e, pool)
e.Put(pool)
ret := finalExponentiation(acc, pool)
acc.Put(pool)
return ret.IsOne()
}

View File

@ -393,6 +393,5 @@ func optimalAte(a *twistPoint, b *curvePoint, pool *bnPool) *gfP12 {
if a.IsInfinity() || b.IsInfinity() {
ret.SetOne()
}
return ret
}