Exemplo n.º 1
0
def verify_multiple(pubkeys: Sequence[BLSPubkey], messages: Sequence[bytes],
                    signature: BLSSignature, domain: int) -> bool:
    len_msgs = len(messages)

    if len(pubkeys) != len_msgs:
        raise ValidationError(
            "len(pubkeys) (%s) should be equal to len(messages) (%s)" %
            (len(pubkeys), len_msgs))

    try:
        o = FQ12([1] + [0] * 11)
        for m_pubs in set(messages):
            # aggregate the pubs
            group_pub = Z1
            for i in range(len_msgs):
                if messages[i] == m_pubs:
                    group_pub = add(group_pub, decompress_G1(pubkeys[i]))

            o *= pairing(hash_to_G2(m_pubs, domain),
                         group_pub,
                         final_exponentiate=False)
        o *= pairing(decompress_G2(signature),
                     neg(G1),
                     final_exponentiate=False)

        final_exponentiation = final_exponentiate(o)
        return final_exponentiation == FQ12.one()
    except (ValidationError, ValueError, AssertionError):
        return False
Exemplo n.º 2
0
Arquivo: bls.py Projeto: jvmaia/py-evm
def verify(message: bytes, pubkey: int, signature: bytes, domain: int) -> bool:
    try:
        final_exponentiation = final_exponentiate(
            pairing(
                FQP_point_to_FQ2_point(decompress_G2(signature)),
                G1,
                final_exponentiate=False,
            ) * pairing(
                FQP_point_to_FQ2_point(hash_to_G2(message, domain)),
                neg(decompress_G1(pubkey)),
                final_exponentiate=False,
            ))
        return final_exponentiation == FQ12.one()
    except (ValidationError, ValueError, AssertionError):
        return False
Exemplo n.º 3
0
 def FQ12One(cls) -> "FQ12":
     return FQ12.one()
Exemplo n.º 4
0
def verify(message: bytes, pubkey: int, signature: bytes, domain: int) -> bool:
    final_exponentiation = final_exponentiate(
        pairing(FQP_point_to_FQ2_point(decompress_G2(signature)), G1, False) *
        pairing(FQP_point_to_FQ2_point(hash_to_G2(message, domain)),
                neg(decompress_G1(pubkey)), False))
    return final_exponentiation == FQ12.one()