def verifying_two_distinct_messages(agg_sig, pubkeys, messages):
    len_msg = len(messages)
    agg_pub1 = bls._AggregatePKs(
        [key for i, key in enumerate(pubkeys) if i % len_msg == 0])
    app_pub2 = bls._AggregatePKs(
        [key for i, key in enumerate(pubkeys) if i % len_msg == 1])
    return bls.AggregateVerify([agg_pub1, app_pub2], messages, agg_sig)
Esempio n. 2
0
def case06_eth_aggregate_pubkeys():
    for pubkey in PUBKEYS:
        encoded_pubkey = encode_hex(pubkey)
        aggregate_pubkey = spec.eth_aggregate_pubkeys([pubkey])
        # Should be unchanged
        assert aggregate_pubkey == milagro_bls._AggregatePKs([pubkey
                                                              ]) == pubkey
        # Valid pubkey
        yield f'eth_aggregate_pubkeys_valid_{(hash(bytes(encoded_pubkey, "utf-8"))[:8]).hex()}', {
            'input': [encode_hex(pubkey)],
            'output': encode_hex(aggregate_pubkey),
        }

    # Valid pubkeys
    aggregate_pubkey = spec.eth_aggregate_pubkeys(PUBKEYS)
    assert aggregate_pubkey == milagro_bls._AggregatePKs(PUBKEYS)
    yield f'eth_aggregate_pubkeys_valid_pubkeys', {
        'input': [encode_hex(pubkey) for pubkey in PUBKEYS],
        'output': encode_hex(aggregate_pubkey),
    }

    # Invalid pubkeys -- len(pubkeys) == 0
    expect_exception(spec.eth_aggregate_pubkeys, [])
    expect_exception(milagro_bls._AggregatePKs, [])
    yield f'eth_aggregate_pubkeys_empty_list', {
        'input': [],
        'output': None,
    }

    # Invalid pubkeys -- [ZERO_PUBKEY]
    expect_exception(spec.eth_aggregate_pubkeys, [ZERO_PUBKEY])
    expect_exception(milagro_bls._AggregatePKs, [ZERO_PUBKEY])
    yield f'eth_aggregate_pubkeys_zero_pubkey', {
        'input': [encode_hex(ZERO_PUBKEY)],
        'output': None,
    }

    # Invalid pubkeys -- G1 point at infinity
    expect_exception(spec.eth_aggregate_pubkeys, [G1_POINT_AT_INFINITY])
    expect_exception(milagro_bls._AggregatePKs, [G1_POINT_AT_INFINITY])
    yield f'eth_aggregate_pubkeys_infinity_pubkey', {
        'input': [encode_hex(G1_POINT_AT_INFINITY)],
        'output': None,
    }

    # Invalid pubkeys -- b'\x40\x00\x00\x00....\x00' pubkey
    x40_pubkey = b'\x40' + b'\00' * 47
    expect_exception(spec.eth_aggregate_pubkeys, [x40_pubkey])
    expect_exception(milagro_bls._AggregatePKs, [x40_pubkey])
    yield f'eth_aggregate_pubkeys_x40_pubkey', {
        'input': [encode_hex(x40_pubkey)],
        'output': None,
    }
Esempio n. 3
0
def test_verify_multiple_aggregate_signatures(SKs, messages):
    signature_set = [(bls.Aggregate([bls.Sign(sk, msg) for sk in SKs]),
                      bls._AggregatePKs([bls.SkToPk(sk) for sk in SKs]), msg)
                     for msg in messages]
    assert bls.VerifyMultipleAggregateSignatures(signature_set)
    bad_signature_set = [(aggsig, aggkey, msg + b'\xbadd')
                         for aggsig, aggkey, msg in signature_set]
    assert not bls.VerifyMultipleAggregateSignatures(bad_signature_set)
Esempio n. 4
0
def test_aggregate_pks(signature_points, result_point):
    signatures = [G1_to_pubkey(pt) for pt in signature_points]
    result_signature = G1_to_pubkey(result_point)
    assert bls._AggregatePKs(signatures) == result_signature
def verifying_one_message(agg_sig, pubkeys, message):
    agg_pub = bls._AggregatePKs(pubkeys)
    return bls.Verify(agg_pub, message, agg_sig)