예제 #1
0
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()
예제 #2
0
파일: bls.py 프로젝트: vardan10/py-evm
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()
예제 #3
0
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
예제 #4
0
 def FQ12One(cls) -> "FQ12":
     return FQ12.one()
예제 #5
0
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()