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_process_commit_with_multiple_sigs( bls_bft_replicas, pre_prepare_with_bls_multi, create_audit_txn_with_multiple_ledgers): for sender_bls_bft in bls_bft_replicas: commit = create_commit_bls_sig(sender_bls_bft, (0, 0), pre_prepare_with_bls_multi) assert commit.blsSigs is not None for verifier_bls_bft in bls_bft_replicas: verifier_bls_bft.process_commit(commit, sender_bls_bft.node_id)
def test_validate_commit_correct_sig_with_multiple_sigs( bls_bft_replicas, pre_prepare_no_bls, create_audit_txn_with_multiple_ledgers): 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 process_commits_for_key(key, pre_prepare, bls_bfts): for sender_bls_bft in bls_bfts: commit = create_commit_bls_sig( sender_bls_bft, key, pre_prepare) for verifier_bls_bft in bls_bfts: verifier_bls_bft.process_commit(commit, sender_bls_bft.node_id)
def calculate_multi_sig(creator, bls_bft_with_commits, quorums, pre_prepare): key = (0, 0) for bls_bft_with_commit in bls_bft_with_commits: commit = create_commit_bls_sig(bls_bft_with_commit, key, pre_prepare) creator.process_commit(commit, bls_bft_with_commit.node_id) if not creator._can_calculate_multi_sig(key, quorums): return None return creator._calculate_multi_sig(key, pre_prepare)
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_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()
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_rolling_release_for_bls_fixes(bls_bft_replicas, nodes_updated, quorums, multi_signature, pre_prepare_with_bls, ledger_id, state_root): key = (0, 0) for i in range(len(bls_bft_replicas)): commit = create_commit_bls_sig(bls_bft_replicas[i], (0, 0), pre_prepare_with_bls) if i < nodes_updated: assert commit.blsSigs is not None assert len(commit.blsSigs.items()) == 2 for verifier_bls_bft in bls_bft_replicas: status = verifier_bls_bft.validate_commit( commit, bls_bft_replicas[i].node_id, pre_prepare_with_bls) assert status != BlsBftReplica.CM_BLS_SIG_WRONG verifier_bls_bft.process_commit(commit, bls_bft_replicas[i].node_id) for bls_bft in bls_bft_replicas: bls_bft.process_order(key, quorums, pre_prepare_with_bls) params = create_pre_prepare_params(state_root, ledger_id=ledger_id) params_initial = copy(params) for i in range(len(bls_bft_replicas)): params_res = bls_bft_replicas[i].update_pre_prepare( copy(params), ledger_id) assert params_res != params_initial if i < nodes_updated: assert len(params_res) - len(params_initial) == 2 pre_prepare = PrePrepare(*params_res) if quorums.bls_signatures.is_reached( nodes_updated) and i < nodes_updated: assert len(pre_prepare.blsMultiSigs) == 2 for verifier_bls_bft in bls_bft_replicas: status = verifier_bls_bft.validate_pre_prepare( pre_prepare, bls_bft_replicas[i].node_id) assert status != BlsBftReplica.PPR_BLS_MULTISIG_WRONG verifier_bls_bft.process_pre_prepare(pre_prepare, bls_bft_replicas[i].node_id) for i in range(len(bls_bft_replicas)): if quorums.bls_signatures.is_reached( nodes_updated) and i < nodes_updated: assert bls_bft_replicas[i]._bls_bft.bls_store.get( multi_signature.value.state_root_hash) assert bls_bft_replicas[i]._bls_bft.bls_store.get( "2UQ3Da54cQ6SamunzXVAtBozFnkACELBH7HzbRPgfKzm") else: assert bls_bft_replicas[i]._bls_bft.bls_store.get( multi_signature.value.state_root_hash)
def test_validate_commit_with_multiple_sigs_one_sig_incorrect( bls_bft_replicas, pre_prepare_with_bls, create_audit_txn_with_multiple_ledgers): key = (0, 0) for sender_bls_bft in bls_bft_replicas: fake_sig = base58.b58encode( b"somefakesignaturesomefakesignaturesomefakesignature").decode( "utf-8") commit = create_commit_bls_sig(sender_bls_bft, key, pre_prepare_with_bls) commit.blsSigs[str(3)] = fake_sig for verifier_bls_bft in bls_bft_replicas: status = verifier_bls_bft.validate_commit(commit, sender_bls_bft.node_id, pre_prepare_with_bls) assert status == BlsBftReplica.CM_BLS_SIG_WRONG
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_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)