def test_process_commit_with_sigs(bls_bft_replicas, pre_prepare_no_bls):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_no_bls)
        for verifier_bls_bft in bls_bft_replicas:
            verifier_bls_bft.process_commit(commit,
                                            sender_bls_bft.node_id)
Ejemplo n.º 2
0
def test_validate_commit_correct_sig_first_time(bls_bft_replicas,
                                                pre_prepare_no_bls):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_no_bls)
        for verifier_bls_bft in bls_bft_replicas:
            assert not verifier_bls_bft.validate_commit(
                commit, sender_bls_bft.node_id, pre_prepare_no_bls)
def test_validate_commit_correct_sig_second_time(bls_bft_replicas, pre_prepare_with_bls):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_with_bls)
        for verifier_bls_bft in bls_bft_replicas:
            assert verifier_bls_bft.validate_commit(commit,
                                                    sender_bls_bft.node_id,
                                                    pre_prepare_with_bls) is None
def test_validate_commit_correct_sig(bls_bft_replicas, state_root):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, state_root)
        for verifier_bls_bft in bls_bft_replicas:
            verifier_bls_bft.validate_commit(commit,
                                             sender_bls_bft.node_id,
                                             state_root)
def test_validate_commit_incorrect_value(bls_bft_replicas, pre_prepare_incorrect, pre_prepare_no_bls):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_incorrect)
        for verifier_bls_bft in bls_bft_replicas:
            status = verifier_bls_bft.validate_commit(commit,
                                                      sender_bls_bft.node_id,
                                                      pre_prepare_no_bls)
            assert status == BlsBftReplica.CM_BLS_SIG_WRONG
def test_process_commit_with_sigs(bls_bft_replicas, state_root):
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(
            sender_bls_bft,
            (0, 0),
            state_root)
        for verifier_bls_bft in bls_bft_replicas:
            verifier_bls_bft.process_commit(commit,
                                            sender_bls_bft.node_id)
def test_validate_commit_incorrect_sig(bls_bft_replicas, state_root):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, generate_state_root())
        for verifier_bls_bft in bls_bft_replicas:
            status = verifier_bls_bft.validate_commit(commit,
                                                      sender_bls_bft.node_id,
                                                      state_root)
            assert status == BlsBftReplica.CM_BLS_SIG_WRONG
Ejemplo n.º 8
0
def test_validate_commit_incorrect_value_ledger_id(
        bls_bft_replicas, pre_prepare_no_bls,
        pre_prepare_with_bls_pool_ledger):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_no_bls)
        for verifier_bls_bft in bls_bft_replicas:
            status = verifier_bls_bft.validate_commit(
                commit, sender_bls_bft.node_id,
                pre_prepare_with_bls_pool_ledger)
            assert status == BlsBftReplica.CM_BLS_SIG_WRONG
def test_validate_commit_signature_without_pool_state_root(bls_bft_replicas, multi_signature):
    key = (0, 0)
    params = create_pre_prepare_params(state_root=multi_signature.value.state_root_hash)
    pre_prepare = PrePrepare(*params)
    setattr(pre_prepare, f.BLS_MULTI_SIG.nm, multi_signature)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare)
        for verifier_bls_bft in bls_bft_replicas:
            assert verifier_bls_bft.validate_commit(commit,
                                                    sender_bls_bft.node_id,
                                                    pre_prepare) is None
def test_validate_commit_does_not_use_committed_pool_state(bls_bft_replicas, pre_prepare_with_bls, monkeypatch):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_with_bls)
        for verifier_bls_bft in bls_bft_replicas:
            monkeypatch.setattr(verifier_bls_bft._bls_bft.bls_key_register,
                                'get_pool_root_hash_committed',
                                lambda: None)
            assert verifier_bls_bft.validate_commit(commit,
                                                    sender_bls_bft.node_id,
                                                    pre_prepare_with_bls) is None
            monkeypatch.undo()
Ejemplo n.º 11
0
def test_preprepare_multisig_replaces_saved(bls_bft_replicas, quorums,
                                            pre_prepare_no_bls,
                                            pre_prepare_with_bls):
    # have locally calculated multi-sigs
    key = (0, 0)
    state_root = pre_prepare_no_bls.stateRootHash
    for sender_bls_bft_replica in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft_replica, key,
                                       pre_prepare_no_bls)
        for verifier_bls_bft_replica in bls_bft_replicas:
            # use 3 of 4 commits only
            if verifier_bls_bft_replica != sender_bls_bft_replica:
                verifier_bls_bft_replica.process_commit(
                    commit, sender_bls_bft_replica.node_id)
    process_ordered(key, bls_bft_replicas, pre_prepare_no_bls, quorums)

    # get locally calculated multi-sigs
    local_multi_sigs = {}
    for bls_bft_replica in bls_bft_replicas:
        local_multi_sigs[
            bls_bft_replica.node_id] = bls_bft_replica._bls_bft.bls_store.get(
                state_root)

    # have multi-sig for PrePrepare (make it different from the local one by using al 4 nodes)
    # get multi-sigs get with PrePrepare and make sure they differ from local ones
    # the local ones must be overridden
    multi_sigs = []
    for bls_bft_replica in bls_bft_replicas:
        bls_bft_replica.process_pre_prepare(pre_prepare_with_bls,
                                            bls_bft_replicas[0].node_id)
        multi_sig = bls_bft_replica._bls_bft.bls_store.get(state_root)
        local_multi_sig = local_multi_sigs[bls_bft_replica.node_id]
        assert multi_sig
        assert local_multi_sig
        assert multi_sig != local_multi_sig
        multi_sigs.append(multi_sig)

    # all saved multi-sigs are equal
    assert all(x == multi_sigs[0] for x in multi_sigs)
def test_preprepare_multisig_replaces_saved(bls_bft_replicas, quorums,
                                            pre_prepare_no_bls, pre_prepare_with_bls):
    # have locally calculated multi-sigs
    key = (0, 0)
    state_root = pre_prepare_no_bls.stateRootHash
    for sender_bls_bft_replica in bls_bft_replicas:
        commit = create_commit_bls_sig(
            sender_bls_bft_replica,
            key,
            pre_prepare_no_bls)
        for verifier_bls_bft_replica in bls_bft_replicas:
            # use 3 of 4 commits only
            if verifier_bls_bft_replica != sender_bls_bft_replica:
                verifier_bls_bft_replica.process_commit(commit,
                                                        sender_bls_bft_replica.node_id)
    process_ordered(key, bls_bft_replicas, pre_prepare_no_bls, quorums)

    # get locally calculated multi-sigs
    local_multi_sigs = {}
    for bls_bft_replica in bls_bft_replicas:
        local_multi_sigs[bls_bft_replica.node_id] = bls_bft_replica._bls_bft.bls_store.get(state_root)

    # have multi-sig for PrePrepare (make it different from the local one by using al 4 nodes)
    # get multi-sigs get with PrePrepare and make sure they differ from local ones
    # the local ones must be overridden
    multi_sigs = []
    for bls_bft_replica in bls_bft_replicas:
        bls_bft_replica.process_pre_prepare(pre_prepare_with_bls, bls_bft_replicas[0].node_id)
        multi_sig = bls_bft_replica._bls_bft.bls_store.get(state_root)
        local_multi_sig = local_multi_sigs[bls_bft_replica.node_id]
        assert multi_sig
        assert local_multi_sig
        assert multi_sig != local_multi_sig
        multi_sigs.append(multi_sig)

    # all saved multi-sigs are equal
    assert all(x == multi_sigs[0] for x in multi_sigs)
Ejemplo n.º 13
0
def test_process_commit_with_sigs(bls_bft_replicas, pre_prepare_no_bls):
    key = (0, 0)
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_no_bls)
        for verifier_bls_bft in bls_bft_replicas:
            verifier_bls_bft.process_commit(commit, sender_bls_bft.node_id)