예제 #1
0
    def test_basic(self):
        """Basic test in original source."""
        example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                         (5, 6)]
        G1 = example_graph
        n = num_vertices(G1)
        p = random_permutation(n)

        f = make_permutation_function(p)
        finv = make_inverse_permutation_function(p)
        G2 = apply_isomorphism(G1, f)

        assert apply_isomorphism(G1, f) == G2
        assert apply_isomorphism(G2, finv) == G1
예제 #2
0
 def test_convince_beyond_doubt(self):
     """Test convincing beyond doubt."""
     G1 = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6), (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     G2 = apply_isomorphism(G1, perm_f)
     convince_beyond_doubt(G1, G2, perm_list)
예제 #3
0
 def test_run_protocol(self):
     """Test a run of the protocol."""
     G1 = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6), (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     G2 = apply_isomorphism(G1, perm_f)
     assert run_protocol(G1, G2, perm_list)
예제 #4
0
 def test_zk_verifier_construction(self):
     """Tests construction of verifier."""
     example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                      (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     permuted_graph = apply_isomorphism(example_graph, perm_f)
     verifier = ZKVerifier(example_graph, permuted_graph)
예제 #5
0
 def test_messages_from_protocol(self):
     """Test retrieving the messages traded in the protocol."""
     G1 = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6), (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     G2 = apply_isomorphism(G1, perm_f)
     messages = messages_from_protocol(G1, G2, perm_list)
     assert len(messages) == 3
예제 #6
0
 def test_zk_graph_prover_construction(self):
     """
 Basic tests on how the ZK graph prover works.
 """
     example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                      (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     permuted_graph = apply_isomorphism(example_graph, perm_f)
     prover = ZKProver(example_graph, permuted_graph, perm_list)
예제 #7
0
 def test_permutation_ops(self):
     """
 Basic tests for how permutations work.
 """
     example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                      (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     permuted_graph = apply_isomorphism(example_graph, perm_f)
     assert len(permuted_graph) == len(example_graph)
     assert num_vertices(permuted_graph) == num_vertices(example_graph)
예제 #8
0
    def test_simulate_protocol(self):
        """Test that simulation of protocol works.

    Simulating a protocl is how the zero-knowledgeness of the protocol is proved.
    """
        G1 = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6), (5, 6)]
        perm_list = random_permutation(6)
        perm_f = make_permutation_function(perm_list)
        G2 = apply_isomorphism(G1, perm_f)
        sim_messages = simulate_protocol(G1, G2)
        assert len(sim_messages) == 3
예제 #9
0
 def test_zk_verifier_choose_graph(self):
     """Tests verifier graph choice."""
     example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                      (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     permuted_graph = apply_isomorphism(example_graph, perm_f)
     prover = ZKProver(example_graph, permuted_graph, perm_list)
     H = prover.send_isomorphic_copy()
     verifier = ZKVerifier(example_graph, permuted_graph)
     choice = verifier.choose_graph()
     assert choice in [1, 2]
예제 #10
0
 def test_zk_graph_prover_send_isomorphic(self):
     """
 Testing generation of random isomorphic graph. 
 """
     example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                      (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     permuted_graph = apply_isomorphism(example_graph, perm_f)
     prover = ZKProver(example_graph, permuted_graph, perm_list)
     isomorphism, H = prover.send_isomorphic_copy()
     assert num_vertices(H) == num_vertices(example_graph)
     assert len(H) == len(example_graph)
예제 #11
0
 def test_zk_verifier_acceptance(self):
     """Tests verifier graph accepts correct."""
     example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                      (5, 6)]
     perm_list = random_permutation(6)
     perm_f = make_permutation_function(perm_list)
     permuted_graph = apply_isomorphism(example_graph, perm_f)
     prover = ZKProver(example_graph, permuted_graph, perm_list)
     (isomorphism, H) = prover.send_isomorphic_copy()
     verifier = ZKVerifier(example_graph, permuted_graph)
     choice = verifier.choose_graph()
     witness = prover.prove_isomorphic_to(isomorphism, choice)
     assert verifier.accepts(witness, choice, H)
예제 #12
0
    def test_zk_graph_prove_isomorphic_to(self):
        """
    Test proofs of graph isomorphism.

    TODO(rbharath): Create a better test for this function.
    """
        example_graph = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6),
                         (5, 6)]
        perm_list = random_permutation(6)
        perm_f = make_permutation_function(perm_list)
        permuted_graph = apply_isomorphism(example_graph, perm_f)
        prover = ZKProver(example_graph, permuted_graph, perm_list)
        isomorphism, H = prover.send_isomorphic_copy()
        iso_1 = prover.prove_isomorphic_to(isomorphism, 1)
        assert isinstance(iso_1, types.FunctionType)
        iso_2 = prover.prove_isomorphic_to(isomorphism, 2)
        assert isinstance(iso_2, types.FunctionType)