def pairing_check(G1_left, G2_left, G1_right, G2_right) -> bool: final_exponentiation = final_exponentiate( pairing( G2_left, G1_left, final_exponentiate=False, ) * pairing( G2_right, G1_right, final_exponentiate=False, )) return final_exponentiation == FQ12.one()
def verify(m: bytes, pub: int, sig: bytes) -> bool: final_exponentiation = final_exponentiate( pairing(FQP_point_to_FQ2_point(decompress_G2(sig)), G1, False) * pairing(FQP_point_to_FQ2_point(hash_to_G2(m)), neg(decompress_G1(pub)), False)) return final_exponentiation == FQ12.one()
from typing import Sequence from py_ecc.optimized_bn128 import G1, final_exponentiate, neg, pairing, FQ12 from pybls.typings import Message, G1Point, G2Point from pybls.g1pubs.hash import hash_to_g2 TARGET = FQ12.one() def pair_check(sig: G2Point, msg: Message, pub: G1Point) -> bool: f = pairing(sig, neg(G1), final_exponentiate=False) * pairing( hash_to_g2(msg), pub, final_exponentiate=False) return final_exponentiate(f) == TARGET def pair_check_multiple(sig: G2Point, pubs: Sequence[G1Point], msgs: Sequence[Message]) -> bool: size = len(pubs) if size == 0: raise Exception("empty pubkey vector") if len(msgs) == 0: raise Exception("empty message vector") if size != len(msgs): raise Exception("size of public keys and messages should be equal") f = pairing(sig, neg(G1), final_exponentiate=False) for i in range(size): f *= pairing(hash_to_g2(msgs[i]), pubs[i], final_exponentiate=False) return final_exponentiate(f) == TARGET
def FQ12One(cls) -> "FQ12": return FQ12.one()
def verify(m, pub, sig): final_exponentiation = final_exponentiate( pairing(decompress_G2(sig), G1, False) * pairing(hash_to_G2(m), neg(decompress_G1(pub)), False)) return final_exponentiation == FQ12.one()