Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Functions | Variables
analyzer.parse_r1cs Namespace Reference

Functions

def get_index (annotation_set, annotation)
 
def get_constraints (constraints_set, annotation_index)
 
def get_constraints_from_annotation_pattern (constraints_set, annotation_pattern)
 
def is_in_lin_comb (linear_combination, annotation_index)
 

Variables

 path_zeth = os.environ["ZETH_DEBUG_DIR"]
 
string filename = "r1cs.json"
 
 file_path = os.path.join(path_zeth, filename)
 
 data = r1cs_file.read()
 
 r1cs_obj = json.loads(data)
 
 r1cs_variables_nb = r1cs_obj["num_variables"]
 
 r1cs_constraints_nb = r1cs_obj["num_constraints"]
 
 variables_annotations_set = r1cs_obj["variables_annotations"]
 
 constraints_set = r1cs_obj["constraints"]
 
string annotation_to_check = "joinsplit_gadget phi bits_31"
 
def annotation_index = get_index(variables_annotations_set, annotation_to_check)
 
def constraints_using_annotation = get_constraints(constraints_set, annotation_index)
 
string regex = "rho"
 
def res = get_constraints_from_annotation_pattern(constraints_set, regex)
 

Function Documentation

◆ get_constraints()

def analyzer.parse_r1cs.get_constraints (   constraints_set,
  annotation_index 
)
Returns the set of constraints in which a given wire figures
(wire = index of a variable annotation)
The set of constraints has the structure below:


"constraints":
    [
        {
            "constraint_id": ID,
            "constraint_annotation": ANNOTATION
            "linear_combination": {
                # `index:` Index of the wire/variable
                # `value:` Scalar by which the wire value is multiplied
                # by in the linear combination A
                "A": [
                        { "index": "0", "value": "0x1" }
                    ],
                "B": [
                        { "index": "530", "scalar": "0x1" },
                        { "index": "531", "scalar": "0x2" },
                        { "index": "532", "scalar": "0x4" }
                    ],
                "C": [
                        { "index": "2", "scalar": "0x1" }
                    ]
            }
        }
    ]

Definition at line 31 of file parse_r1cs.py.

31 def get_constraints(constraints_set, annotation_index):
32  """
33  Returns the set of constraints in which a given wire figures
34  (wire = index of a variable annotation)
35  The set of constraints has the structure below:
36 
37 
38  "constraints":
39  [
40  {
41  "constraint_id": ID,
42  "constraint_annotation": ANNOTATION
43  "linear_combination": {
44  # `index:` Index of the wire/variable
45  # `value:` Scalar by which the wire value is multiplied
46  # by in the linear combination A
47  "A": [
48  { "index": "0", "value": "0x1" }
49  ],
50  "B": [
51  { "index": "530", "scalar": "0x1" },
52  { "index": "531", "scalar": "0x2" },
53  { "index": "532", "scalar": "0x4" }
54  ],
55  "C": [
56  { "index": "2", "scalar": "0x1" }
57  ]
58  }
59  }
60  ]
61  """
62 
63  # Array of ID of the constraints using the provided annotation index
64  constraints_id = []
65  for i in range(len(constraints_set)):
66  lin_com_a = constraints_set[i]["linear_combination"]["A"]
67  lin_com_b = constraints_set[i]["linear_combination"]["B"]
68  lin_com_c = constraints_set[i]["linear_combination"]["C"]
69  found_in_a = is_in_lin_comb(lin_com_a, annotation_index)
70  found_in_b = is_in_lin_comb(lin_com_b, annotation_index)
71  found_in_c = is_in_lin_comb(lin_com_c, annotation_index)
72  if found_in_a or found_in_b or found_in_c:
73  constraints_id.append(constraints_set[i]["constraint_id"])
74  print("Constraint: ", str(constraints_set[i]))
75  return constraints_id
76 
Here is the call graph for this function:

◆ get_constraints_from_annotation_pattern()

def analyzer.parse_r1cs.get_constraints_from_annotation_pattern (   constraints_set,
  annotation_pattern 
)
Returns a set of constraints which annotation matches the given pattern.
The regex is given by the user (which can be quite dangerous but
the goal of this script is not to be robust anyway)

Definition at line 77 of file parse_r1cs.py.

77 def get_constraints_from_annotation_pattern(constraints_set, annotation_pattern):
78  """
79  Returns a set of constraints which annotation matches the given pattern.
80  The regex is given by the user (which can be quite dangerous but
81  the goal of this script is not to be robust anyway)
82  """
83 
84  # Array of ID of the constraints using the provided annotation index
85  constraints_id = []
86  for i in range(len(constraints_set)):
87  constraint_annotation = constraints_set[i]["constraint_annotation"]
88  x = re.search(annotation_pattern, constraint_annotation)
89  # If there has been a match
90  if x is not None:
91  constraints_id.append(constraints_set[i]["constraint_id"])
92  print("Constraint: ", str(constraints_set[i]))
93  return constraints_id
94 
95 

◆ get_index()

def analyzer.parse_r1cs.get_index (   annotation_set,
  annotation 
)
Finds the index corresponding to `annotation`
in the annotation set (which has the structure below)

"variables_annotations":
    [
        { "index": INDEX, "annotation": ANNOTATION },

        ...

        { "index": INDEX, "annotation": ANNOTATION }
    ]

Definition at line 11 of file parse_r1cs.py.

11 def get_index(annotation_set, annotation):
12  """
13  Finds the index corresponding to `annotation`
14  in the annotation set (which has the structure below)
15 
16  "variables_annotations":
17  [
18  { "index": INDEX, "annotation": ANNOTATION },
19 
20  ...
21 
22  { "index": INDEX, "annotation": ANNOTATION }
23  ]
24  """
25 
26  for i in range(len(annotation_set)):
27  if annotation_set[i]["annotation"] == annotation:
28  return annotation_set[i]["index"]
29 
30 

◆ is_in_lin_comb()

def analyzer.parse_r1cs.is_in_lin_comb (   linear_combination,
  annotation_index 
)
Inspects all the elements of the linear combination and returns
true is the variable corresponding to the annotation_index
is used in the linear combination

Definition at line 96 of file parse_r1cs.py.

96 def is_in_lin_comb(linear_combination, annotation_index):
97  """
98  Inspects all the elements of the linear combination and returns
99  true is the variable corresponding to the annotation_index
100  is used in the linear combination
101  """
102 
103  # Inspect all the linear terms
104  for i in range(len(linear_combination)):
105  if linear_combination[i]["index"] == annotation_index:
106  return True
107 
108 
Here is the caller graph for this function:

Variable Documentation

◆ annotation_index

def analyzer.parse_r1cs.annotation_index = get_index(variables_annotations_set, annotation_to_check)

Definition at line 134 of file parse_r1cs.py.

◆ annotation_to_check

string analyzer.parse_r1cs.annotation_to_check = "joinsplit_gadget phi bits_31"

Definition at line 133 of file parse_r1cs.py.

◆ constraints_set

analyzer.parse_r1cs.constraints_set = r1cs_obj["constraints"]

Definition at line 127 of file parse_r1cs.py.

◆ constraints_using_annotation

def analyzer.parse_r1cs.constraints_using_annotation = get_constraints(constraints_set, annotation_index)

Definition at line 139 of file parse_r1cs.py.

◆ data

analyzer.parse_r1cs.data = r1cs_file.read()

Definition at line 116 of file parse_r1cs.py.

◆ file_path

analyzer.parse_r1cs.file_path = os.path.join(path_zeth, filename)

Definition at line 114 of file parse_r1cs.py.

◆ filename

string analyzer.parse_r1cs.filename = "r1cs.json"

Definition at line 111 of file parse_r1cs.py.

◆ path_zeth

analyzer.parse_r1cs.path_zeth = os.environ["ZETH_DEBUG_DIR"]

Definition at line 110 of file parse_r1cs.py.

◆ r1cs_constraints_nb

analyzer.parse_r1cs.r1cs_constraints_nb = r1cs_obj["num_constraints"]

Definition at line 121 of file parse_r1cs.py.

◆ r1cs_obj

analyzer.parse_r1cs.r1cs_obj = json.loads(data)

Definition at line 119 of file parse_r1cs.py.

◆ r1cs_variables_nb

analyzer.parse_r1cs.r1cs_variables_nb = r1cs_obj["num_variables"]

Definition at line 120 of file parse_r1cs.py.

◆ regex

string analyzer.parse_r1cs.regex = "rho"

Definition at line 142 of file parse_r1cs.py.

◆ res

Definition at line 144 of file parse_r1cs.py.

◆ variables_annotations_set

analyzer.parse_r1cs.variables_annotations_set = r1cs_obj["variables_annotations"]

Definition at line 126 of file parse_r1cs.py.

test_commands.mock.str
str
Definition: mock.py:18
analyzer.parse_r1cs.get_constraints_from_annotation_pattern
def get_constraints_from_annotation_pattern(constraints_set, annotation_pattern)
Definition: parse_r1cs.py:77
analyzer.parse_r1cs.get_index
def get_index(annotation_set, annotation)
Definition: parse_r1cs.py:11
analyzer.parse_r1cs.is_in_lin_comb
def is_in_lin_comb(linear_combination, annotation_index)
Definition: parse_r1cs.py:96
analyzer.parse_r1cs.get_constraints
def get_constraints(constraints_set, annotation_index)
Definition: parse_r1cs.py:31