Exemplo n.º 1
0
def _correct_slashable_vote_data_params(params, validators, messages,
                                        privkeys):
    valid_params = copy.deepcopy(params)

    num_validators = len(validators)

    key = "aggregate_signature_poc_0_indices"
    (poc_0_indices, poc_0_signatures) = _get_indices_and_signatures(
        num_validators,
        messages[0],
        privkeys,
    )
    valid_params[key] = poc_0_indices

    key = "aggregate_signature_poc_1_indices"
    # NOTE: does not guarantee non-empty intersection
    (poc_1_indices, poc_1_signatures) = _get_indices_and_signatures(
        num_validators,
        messages[1],
        privkeys,
    )
    valid_params[key] = poc_1_indices

    signatures = poc_0_signatures + poc_1_signatures
    aggregate_signature = bls.aggregate_signatures(signatures)

    valid_params["aggregate_signature"] = aggregate_signature

    return valid_params
Exemplo n.º 2
0
def test_signature_aggregation(msg, privkeys):
    domain = 0
    sigs = [sign(msg, k, domain=domain) for k in privkeys]
    pubs = [privtopub(k) for k in privkeys]
    aggsig = aggregate_signatures(sigs)
    aggpub = aggregate_pubkeys(pubs)
    assert verify(msg, aggpub, aggsig, domain=domain)
Exemplo n.º 3
0
def test_multi_aggregation(msg_1, msg_2, privkeys_1, privkeys_2):
    domain = 0

    sigs_1 = [sign(msg_1, k, domain=domain) for k in privkeys_1]
    pubs_1 = [privtopub(k) for k in privkeys_1]
    aggsig_1 = aggregate_signatures(sigs_1)
    aggpub_1 = aggregate_pubkeys(pubs_1)

    sigs_2 = [sign(msg_2, k, domain=domain) for k in privkeys_2]
    pubs_2 = [privtopub(k) for k in privkeys_2]
    aggsig_2 = aggregate_signatures(sigs_2)
    aggpub_2 = aggregate_pubkeys(pubs_2)

    msgs = [msg_1, msg_2]
    pubs = [aggpub_1, aggpub_2]
    aggsig = aggregate_signatures([aggsig_1, aggsig_2])

    assert verify_multiple(
        pubkeys=pubs,
        messages=msgs,
        signature=aggsig,
        domain=domain,
    )
Exemplo n.º 4
0
def aggregate_votes(
    bitfield: Bitfield, sigs: Iterable[BLSSignature],
    voting_sigs: Iterable[BLSSignature],
    voting_committee_indices: Iterable[CommitteeIndex]
) -> Tuple[Bitfield, BLSSignature]:
    """
    Aggregate the votes.
    """
    # Update the bitfield and append the signatures
    sigs = tuple(sigs) + tuple(voting_sigs)
    bitfield = pipe(
        bitfield,
        *(set_voted(index=committee_index)
          for committee_index in voting_committee_indices))

    return bitfield, bls.aggregate_signatures(sigs)
Exemplo n.º 5
0
def aggregate_votes(bitfield: bytes,
                    sigs: Iterable[bytes],
                    voting_sigs: Iterable[bytes],
                    voting_committee_indices: Iterable[int]) -> Tuple[bytes, Tuple[int, int]]:
    """
    Aggregate the votes.
    """
    # Update the bitfield and append the signatures
    sigs = tuple(sigs) + tuple(voting_sigs)
    bitfield = pipe(
        bitfield,
        *(
            set_voted(index=committee_index)
            for committee_index in voting_committee_indices
        )
    )

    return bitfield, bls.aggregate_signatures(sigs)