コード例 #1
0
ファイル: test_apr.py プロジェクト: apguerrera/starks
    def test_get_witness(self):
        """Test that a witness can be extracted from the APR instance.

    # TODO(rbharath): Make this test non-trivial to check the witness has
    # required properties.
    """
        width = 2
        # Set the field small in tests since primitive polynomial generation is slow.
        p = 2
        m = 17
        Zp = IntegersModP(p)
        polysOver = polynomials_over(Zp)
        #x^17 + x^3 + 1 is primitive
        coefficients = [Zp(0)] * 18
        coefficients[0] = Zp(1)
        coefficients[3] = Zp(1)
        coefficients[17] = Zp(1)
        poly = polysOver(coefficients)
        field = FiniteField(p, m, polynomialModulus=poly)
        steps = 3
        extension_factor = 8
        inp = [field(0), field(1)]
        polysOver = multivariates_over(field, width).factory
        X_1 = polysOver({(1, 0): field(1)})
        X_2 = polysOver({(0, 1): field(1)})
        step_polys = [X_2, X_1 + X_2]
        air = AIR(field, width, inp, steps, step_polys, extension_factor)
        apr = APR(air)
        # TODO(rbharath): Uncomment this and reactivate it
        witness = apr.generate_witness()
コード例 #2
0
ファイル: test_air.py プロジェクト: apguerrera/starks
 def test_binary_air(self):
     """"Test construction of a binary AIR."""
     steps = 512 - 1
     # This finite field is of size 2^17
     p = 2
     m = 17
     # TODO(rbharath): Extension factor shouldn't be an
     # argument.
     extension_factor = 8
     Zp = IntegersModP(p)
     polysOver = polynomials_over(Zp)
     #field = FiniteField(p, m)
     #x^17 + x^3 + 1 is primitive
     coefficients = [Zp(0)] * 18
     coefficients[0] = Zp(1)
     coefficients[3] = Zp(1)
     coefficients[17] = Zp(1)
     poly = polysOver(coefficients)
     field = FiniteField(p, m, polynomialModulus=poly)
     width = 2
     inp = [field(0), field(1)]
     polysOver = multivariates_over(field, width).factory
     [X_1, X_2] = generate_Xi_s(field, width)
     step_polys = [X_2, X_1 + X_2]
     air = AIR(field, width, inp, steps, step_polys, extension_factor)
コード例 #3
0
ファイル: test_apr.py プロジェクト: apguerrera/starks
 def test_apr_constructor(self):
     """Test that the APR class can be initialized."""
     width = 2
     # Set the field small in tests since primitive polynomial generation is slow.
     p = 2
     m = 2
     Zp = IntegersModP(p)
     polysOver = polynomials_over(Zp)
     field = FiniteField(p, m)
     #m = 17
     ##x^17 + x^3 + 1 is primitive
     #coefficients = [Zp(0)] * 18
     #coefficients[0] = Zp(1)
     #coefficients[3] = Zp(1)
     #coefficients[17] = Zp(1)
     #poly = polysOver(coefficients)
     #field = FiniteField(p, m, polynomialModulus=poly)
     steps = 7
     extension_factor = 8
     inp = [field(0), field(1)]
     polysOver = multivariates_over(field, width).factory
     X_1 = polysOver({(1, 0): field(1)})
     X_2 = polysOver({(0, 1): field(1)})
     step_polys = [X_2, X_1 + X_2]
     air = AIR(field, width, inp, steps, step_polys, extension_factor)
     apr = APR(air)
コード例 #4
0
ファイル: utils.py プロジェクト: apguerrera/starks
def generate_Xi_s(field: Field, width: int):
    """
  Constructs polynomials X_1,..,X_width

  This helper method generates "index" polynomials. Using
  these polynomials makes it easier to write more complex
  polynomials programmatically.
  """
    polysOver = multivariates_over(field, width).factory
    Xi_s = []
    for i in range(width):
        pre = (0, ) * i
        post = (0, ) * (width - (i + 1))
        index = pre + (1, ) + post
        X_i = polysOver({index: field(1)})
        Xi_s.append(X_i)
    return Xi_s
コード例 #5
0
ファイル: test_air.py プロジェクト: apguerrera/starks
 def test_trace_extraction(self):
     """
 Tests construction of trace for a AIR
 """
     width = 2
     steps = 512 - 1
     extension_factor = 8
     modulus = 2**256 - 2**32 * 351 + 1
     field = IntegersModP(modulus)
     inp = [field(0), field(1)]
     polysOver = multivariates_over(field, width).factory
     [X_1, X_2] = generate_Xi_s(field, width)
     step_polys = [X_2, X_1 + X_2]
     air = AIR(field, width, inp, steps, step_polys, extension_factor)
     assert len(air.computational_trace) == 512 - 1
     for state in air.computational_trace:
         assert len(state) == width
         for dim in range(width):
             assert isinstance(state[dim], field)
コード例 #6
0
ファイル: test_air.py プロジェクト: apguerrera/starks
 def test_higher_dim_trace(self):
     """
 Checks trace generation for multidimensional state.
 """
     width = 2
     steps = 5
     modulus = 2**256 - 2**32 * 351 + 1
     field = IntegersModP(modulus)
     inp = [field(0), field(1)]
     polysOver = multivariates_over(field, width).factory
     X_1 = polysOver({(1, 0): field(1)})
     X_2 = polysOver({(0, 1): field(1)})
     step_polys = [X_2, X_1 + X_2]
     trace, output = get_computational_trace(inp, steps, width, step_polys)
     assert list(trace[0]) == [0, 1]
     assert list(trace[1]) == [1, 1]
     assert list(trace[2]) == [1, 2]
     assert list(trace[3]) == [2, 3]
     assert list(trace[4]) == [3, 5]
コード例 #7
0
ファイル: air.py プロジェクト: apguerrera/starks
    def generate_constraint_polynomials(self):
        """Constructs the constraint polynomials for this AIR instance.

    A constraint polynomial is in F[X_1,..,X_w, Y_1,.., Y_w].
    An AIR instance can hold a set of constraint polynomials
    each of which enforces a transition constraint.
    Intuitively, X_1,...,X_1 is the vector of current states
    and Y_1,...,Y_w is the vector of the next state. It can be
    useful at times to have more than one constraint for
    enforcing various transition properties.
    """
        # Let's make polynomials in F[x_1,..,x_w,y_1,...,y_w]]
        multi = multivariates_over(self.field, 2 * self.width).factory
        multivars = generate_Xi_s(self.field, 2 * self.width)
        Xs = multivars[:self.width]
        Ys = multivars[self.width:]
        constraints = []
        for i in range(self.width):
            step_poly = self.step_polys[i]
            Y_i = Ys[i]
            # The constraint_poly
            poly = Y_i - step_poly(Xs)
            constraints.append(poly)
        return constraints