diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-17 21:46:46 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-08-17 21:46:46 +0800 |
commit | 1335a6cc8c65aabe5e4b35b013f91f474a243442 (patch) | |
tree | f8eb49459dcf023f2781632b86510f83a5bddbf6 /crypto/bn256/bn256.go | |
parent | 0b978f91b6adcc4b595391096a72db73bc625bcf (diff) | |
download | go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.tar go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.tar.gz go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.tar.bz2 go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.tar.lz go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.tar.xz go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.tar.zst go-tangerine-1335a6cc8c65aabe5e4b35b013f91f474a243442.zip |
core/vm, crypto/bn256: fix bn256 use and pairing corner case
Diffstat (limited to 'crypto/bn256/bn256.go')
-rw-r--r-- | crypto/bn256/bn256.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crypto/bn256/bn256.go b/crypto/bn256/bn256.go index 92418369b..7144c31a8 100644 --- a/crypto/bn256/bn256.go +++ b/crypto/bn256/bn256.go @@ -379,16 +379,22 @@ func Pair(g1 *G1, g2 *G2) *GT { return >{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() } |