def test_basic(self):
        """Conducts a basic test of the running the 3-coloring protocol."""
        security_parameter = 512
        one_way_permutation = blum_blum_shub.blum_blum_shub(security_parameter)
        hardcore_predicate = blum_blum_shub.parity
        G = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6), (5, 6)]
        coloring = {
            1: 0,
            2: 1,
            3: 2,
            4: 1,
            5: 2,
            6: 0,
        }

        prover = ZK3ColProver(G, coloring, one_way_permutation,
                              hardcore_predicate)
        verifier = ZK3ColVerifier(G, one_way_permutation, hardcore_predicate)

        committed_coloring = prover.commit_to_coloring()
        chosen_edge = verifier.choose_edge(committed_coloring)

        revealed = prover.reveal_colors(*chosen_edge)
        revealed_colors = (
            verifier.verifier.decode(revealed[0],
                                     committed_coloring[chosen_edge[0]]),
            verifier.verifier.decode(revealed[1],
                                     committed_coloring[chosen_edge[1]]),
        )
        is_valid = verifier.accepts(revealed)

        print("{} != {} and commitment is valid? {}".format(
            revealed_colors[0], revealed_colors[1], is_valid))
示例#2
0
    def test_bit_commitment(self):
        """Test that bit commitment works."""
        security_parameter = 10
        one_way_perm = blum_blum_shub.blum_blum_shub(security_parameter)
        hardcorePred = blum_blum_shub.parity

        print('Bit commitment')
        scheme = BBSBitCommitmentScheme(one_way_perm, hardcorePred,
                                        security_parameter)
        verifier = BBSBitCommitmentVerifier(one_way_perm, hardcorePred)
 def test_commit_to_coloring(self):
     """Test commit to coloring"""
     security_parameter = 512
     G = [(1, 2), (1, 4), (1, 3), (2, 5), (2, 5), (3, 6), (5, 6)]
     coloring = {
         1: 0,
         2: 1,
         3: 2,
         4: 1,
         5: 2,
         6: 0,
     }
     one_way_permutation = blum_blum_shub.blum_blum_shub(security_parameter)
     hardcore_predicate = blum_blum_shub.parity
     prover = ZK3ColProver(G, coloring, one_way_permutation,
                           hardcore_predicate)
     committed_coloring = prover.commit_to_coloring()
     assert len(committed_coloring) == 6
示例#4
0
def run_protocol(G, coloring, security_parameter=512):
  """Runs one round of the 3 coloring protocol for two graphs."""
  one_way_permutation = blum_blum_shub.blum_blum_shub(security_parameter)
  hardcore_predicate = blum_blum_shub.parity

  prover = ZK3ColProver(G, coloring, one_way_permutation, hardcore_predicate)
  verifier = ZK3ColVerifier(G, one_way_permutation, hardcore_predicate)

  committed_coloring = prover.commit_to_coloring()
  chosen_edge = verifier.choose_edge(committed_coloring)

  revealed = prover.reveal_colors(*chosen_edge)
  revealed_colors = (
      verifier.verifier.decode(revealed[0], committed_coloring[chosen_edge[0]]),
      verifier.verifier.decode(revealed[1], committed_coloring[chosen_edge[1]]),
  )
  is_valid = verifier.accepts(revealed)

  print("{} != {} and commitment is valid? {}".format(
      revealed_colors[0], revealed_colors[1], is_valid))

  return is_valid
示例#5
0
 def test_basic(self):
   """Basic tests."""
   owp = blum_blum_shub()
   print(owp(70203203))
   print(owp(12389))
示例#6
0
import random

from starks.zero_knowledge import num_vertices
from starks.zero_knowledge import random_permutation
from starks import blum_blum_shub
from starks import commitment

ONE_WAY_PERMUTATION = blum_blum_shub.blum_blum_shub(512)
HARDCORE_PREDICATE = blum_blum_shub.parity


class ZK3ColProver(object):
  """Proves in zero-knowledge a 3-coloring for a given graph.

  TODO(rbharath): This class is pretty stateful. Swap out for a less stateful
  implementation.
  """

  def __init__(self,
               graph,
               coloring,
               one_way_permutation=ONE_WAY_PERMUTATION,
               hardcore_predicate=HARDCORE_PREDICATE):
    self.graph = [tuple(sorted(e)) for e in graph]
    self.coloring = coloring
    self.vertices = list(range(1, num_vertices(graph) + 1))
    self.one_way_permutation = one_way_permutation
    self.hardcore_predicate = hardcore_predicate
    self.vertexToScheme = None

  def commit_to_coloring(self):
示例#7
0
 def test_pred_construction(self):
     """Test predicate construction works."""
     security_parameter = 10
     one_way_perm = blum_blum_shub.blum_blum_shub(security_parameter)
     hardcorePred = blum_blum_shub.parity