You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/zkEVM/concepts/circom-intro-brief.md
+34-35Lines changed: 34 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,50 +1,49 @@
1
-
2
1
!!!info
3
2
In this document, we describe the CIRCOM component of the zkProver. It is one of the four main components of the zkProver, as outlined [here](../architecture/zkprover/index.md). These principal components are; the Executor or Main SM, STARK Recursion, CIRCOM, and Rapid SNARK.
4
3
5
-
You may refer to the original [CIRCOM research paper](https://www.techrxiv.org/articles/preprint/CIRCOM_A_Robust_and_Scalable_Language_for_Building_Complex_Zero-Knowledge_Circuits/19374986/1) for more details.
4
+
You may refer to the original [CIRCOM paper](https://www.techrxiv.org/articles/preprint/CIRCOM_A_Robust_and_Scalable_Language_for_Building_Complex_Zero-Knowledge_Circuits/19374986/1) for more details.
6
5
7
-
As seen in the [zkProver Overview](../architecture/zkprover/index.md) document, the output of the STARK Recursion component is a STARK proof.
6
+
As seen in the [zkProver overview](../architecture/zkprover/index.md) document, the output of the STARK recursion component is a STARK proof.
8
7
9
8
The next step in the zkProver's process of providing validity proof is to produce the witness similar to the output of the STARK Recursion.
10
9
11
10
Although the zkProver is designed as a state machine emulating the EVM, in order to generate this witness, it makes use of a tool based on the Arithmetic circuits model, called CIRCOM.
12
11
13
12
CIRCOM takes the output of the STARK Recursion as input, so as to create its corresponding witness.
14
13
15
-
The witness is in turn taken as input to the Rapid SNARK, which is used to generate a SNARK proof published as the validity proof.
14
+
The witness is in turn taken as an input to the Rapid SNARK, which is used to generate a SNARK proof published as the validity proof.
16
15
17
16

18
17
19
-
In fact, CIRCOM takes a STARK proof as input and produces its corresponding Arithmetic circuit, expressed as the equivalent set of equations called Rank-1 Constraint System (R1CS).
18
+
In fact, CIRCOM takes a STARK proof as input and produces its corresponding Arithmetic circuit, expressed as the equivalent set of equations called rank-1 constraint system (R1CS).
20
19
21
20
The set of valid circuit input, intermediate and output values satisfying the R1CS is actually the witness related to the input STARK proof.
22
21
23
-
This document focuses on what CIRCOM is, its common context of implementation, and how the zkProver utilizes CIRCOM.
22
+
This document focuses on what CIRCOM is, its common implementation context, and how the zkProver utilizes CIRCOM.
24
23
25
24
## Circuit context
26
25
27
26
Arithmetic circuits are mostly used as standard models for studying the complexity of computations.
28
27
29
28
An Arithmetic circuit is composed of addition and multiplication gates, and wires that carry values that are elements of a prime finite field $\mathbb{F}_p$, where $p$ is typically a very large prime number.
30
29
31
-
In the context of ZK-Proof protocols, a prover can use an Arithmetic circuit to prove knowledge of a valid assignment to all wires of the circuit.
30
+
In the context of ZK-proof protocols, a prover can use an Arithmetic circuit to prove knowledge of a valid assignment to all wires of the circuit.
32
31
33
32
And if the proof is correct, the verifier is convinced that the computation expressed as the Arithmetic circuit is valid, but learns nothing about the wires’ assigned values.
34
33
35
-
Arithmetic circuits are commonly encoded in the form of a set of equations called Rank-1 Constraint System (R1CS).
34
+
Arithmetic circuits are commonly encoded in the form of R1CS.
36
35
37
36
Once obtained, the R1CS can later be used by a zk-SNARK protocol to generate verifiable proof.
38
37
39
38
A valid proof attests to the fact that the prover knows an assignment to all wires of the circuit that fulfills all the constraints of the R1CS.
40
39
41
-
An issue that arises, when applying Zero-Knowledge protocols to complex computations such as a circuit describing the logic of a ZK-rollup, is that the number of constraints to be verified can be extremely large.
40
+
An issue that arises, when applying zero-knowledge protocols to complex computations such as a circuit describing the logic of a ZK-rollup, is that the number of constraints to be verified can be extremely large.
42
41
43
42
CIRCOM was developed for the very purpose of scaling complex Arithmetic circuits by realizing them as combined instantiations of smaller Arithmetic circuits.
44
43
45
44
## What is CIRCOM?
46
45
47
-
CIRCOM is a Domain-Specific Language (DSL) used to define Arithmetic circuits, and it has an associated compiler of Arithmetic circuits to their respective Rank-1 Constraint System (or R1CS).
46
+
CIRCOM is a Domain-Specific Language (DSL) used to define Arithmetic circuits, and it has an associated compiler of Arithmetic circuits to their respective R1CS.
@@ -54,9 +53,9 @@ As described in the title of its [specifications paper](https://www.techrxiv.org
54
53
55
54
It is designed as a low-level circuit language, mimicking the design of electronic circuits, for naturally defining Arithmetic circuits.
56
55
57
-
As a Domain-Specific Language (DSL), it allows programmers to design and create Arithmetic circuits of their own choice, and later on apply these circuits to ZK tools.
56
+
As a DSL, it allows programmers to design and create Arithmetic circuits of their own choice, and later on apply these circuits to ZK tools.
58
57
59
-
One of the main peculiarities of CIRCOM is its modularity as a language. It allows the definition of parameterizable small circuits called templates, which can be instantiated to form part of larger circuits.
58
+
One of the main peculiarities of CIRCOM is its modularity as a language. It allows the definition of parameterizable small circuits called _templates_, which can be instantiated to form part of larger circuits.
60
59
61
60
In this regard, CIRCOM users can use templates to create their own custom circuits with varied complexity.
62
61
@@ -77,25 +76,25 @@ The CIRCOM compiler is mainly written in Rust and it is open source.
77
76
78
77
The CIRCOM language has its own peculiarities. The focus in this subsection is on a few features characteristic of CIRCOM.
79
78
80
-
Consider as an example, the `Multiplier` circuit with input signals $\texttt{a}$ and $\texttt{b}$, and an output signal $\texttt{c}$ satisfying the constraint $\texttt{a} \times \texttt{b} \texttt{ - c = 0}$.
79
+
Consider as an example, the _Multiplier_ circuit with input signals $\texttt{a}$ and $\texttt{b}$, and an output signal $\texttt{c}$ satisfying the constraint $\texttt{a} \times \texttt{b} \texttt{ - c = 0}$.
The figure above depicts a simple `Multiplier` Arithmetic circuit with input wires labeled $\texttt{a}$ and $\texttt{b}$ and an output wire labeled $\texttt{c}$ such that $\texttt{a} \times \texttt{b\ = } \texttt{c}$. The wires are referred to as signals. The constraint related to this Multiplier circuit is:
83
+
The figure above depicts a simple _Multiplier_ Arithmetic circuit with input wires labeled $\texttt{a}$ and $\texttt{b}$ and an output wire labeled $\texttt{c}$ such that $\texttt{a} \times \texttt{b\ = } \texttt{c}$. The wires are referred to as signals. The constraint related to this Multiplier circuit is:
85
84
86
85
$$
87
86
\texttt{a} \times \texttt{b} \texttt{ - c = 0}
88
87
$$
89
88
90
89
### The `pragma` instruction
91
90
92
-
The `pragma` instruction specifies the version of the CIRCOM compiler being used. It is meant to ensure compatibility between the circuit and the compiler version. If the two are incompatible, the compiler throws a warning.
91
+
The _pragma_ instruction specifies the version of the CIRCOM compiler being used. It is meant to ensure compatibility between the circuit and the compiler version. If the two are incompatible, the compiler throws a warning.
93
92
94
93
```
95
94
pragma circom 2.0.0;
96
95
```
97
96
98
-
As a precautionary measure, all files with the `.circom` extension should start with a `pragma` instruction. In the absence of this instruction, it is assumed that the code is compatible with the latest compiler version.
97
+
As a precautionary measure, all files with the _.circom_ extension should start with a _pragma_ instruction. In the absence of this instruction, it is assumed that the code is compatible with the latest compiler version.
99
98
100
99
### Declaration of signals
101
100
@@ -130,7 +129,7 @@ Templates are parametrizable in the sense that their outputs depend on free inpu
130
129
131
130
They are general descriptions of circuits, that have some input and output signals, as well as a relation between the inputs and the outputs.
132
131
133
-
The following code shows how a `Multiplier template` is created:
132
+
The following code shows how a _Multiplier template_ is created:
134
133
135
134
```
136
135
pragma circom 2.0.0;
@@ -147,15 +146,15 @@ template Multiplier () {
147
146
148
147
### Instantiation of templates
149
148
150
-
Although the above code succeeds in creating the `Multiplier template`, the template is yet to be instantiated.
149
+
Although the above code succeeds in creating the _Multiplier template_, the template is yet to be instantiated.
151
150
152
151
In CIRCOM, the instantiation of a template is called a component, and it is created as follows:
153
152
154
153
```
155
154
component main = Multiplier();
156
155
```
157
156
158
-
The `Multiplier template` does not depend on any parameter.
157
+
The _Multiplier template_ does not depend on any parameter.
159
158
160
159
However, it is possible to initially create a generic, parametrizable template that can later be instantiated using specific parameters to construct the circuit.
161
160
@@ -165,7 +164,7 @@ Small circuits can be defined which can be combined to create larger circuits by
165
164
166
165
### Compiling a circuit
167
166
168
-
As previously mentioned, the use of the operator "<==" in the `Multiplier template` has dual functionality:
167
+
As previously mentioned, the use of the operator "<==" in the _Multiplier template_ has dual functionality:
169
168
170
169
- It captures the arithmetic relation between signals, and
171
170
- It also provides a way to compute $\texttt{c}$ from $\texttt{a}$ and $\texttt{b}$.
@@ -174,13 +173,13 @@ In general, the description of a CIRCOM circuit also keeps dual functionality. T
174
173
175
174
This enables the compiler to easily generate the R1CS describing a circuit, together with instructions to compute intermediate and output values of a circuit.
176
175
177
-
Given a circuit with the `multiplier.circom` extension, the following line of code instructs the compiler to carry out the two types of tasks:
176
+
Given a circuit with the _multiplier.circom_ extension, the following line of code instructs the compiler to carry out the two types of tasks:
178
177
179
178
```
180
179
circom multiplier.circom --r1cs --c --wasm --sym
181
180
```
182
181
183
-
After compiling the `.circom` circuit, the compiler returns four files:
182
+
After compiling the _.circom_ circuit, the compiler returns four files,
184
183
185
184
- A file with the R1CS constraints (symbolic task)
186
185
- A C++ program for computing values of the circuit wires (computational task)
@@ -189,53 +188,53 @@ After compiling the `.circom` circuit, the compiler returns four files:
189
188
190
189
At this stage, either one of the C++ or WebAssembly programs generated by the compiler can be used to compute all signals that match the set of constraints of the circuit.
191
190
192
-
Whichever program is used, needs as input, a file containing a set of valid input values.
191
+
Whichever program is used, needs as input a file containing a set of valid input values.
193
192
194
193
Recall that a valid set of circuit input, intermediate and output values is called the witness.
195
194
196
195
### Private and public signals
197
196
198
-
Depending on the `template` being used, some signals are `private` while others are `public`.
197
+
Depending on the _template_ being used, some signals are _private_ while others are _public_.
199
198
200
-
In the case of the `Multiplier template`, a signal is `private` by default, unless it is declared to be `public` in the instantiation of the template as shown below.
199
+
In the case of the _Multiplier template_, a signal is _private_ by default, unless it is declared to be _public_ in the instantiation of the template as shown below.
201
200
202
201
```
203
202
component main {public [a]} = Multiplier();
204
203
```
205
204
206
-
According to the above line, the input signal $\texttt{a}$ is `public`, while $\texttt{b}$ is `private` by default.
205
+
According to the above line, the input signal $\texttt{a}$ is _public_, while $\texttt{b}$ is _private_ by default.
207
206
208
207
### Main component
209
208
210
-
The CIRCOM compiler needs a specific component as an entry point. And this initial component is called `main`.
209
+
The CIRCOM compiler needs a specific component as an entry point. And this initial component is called _main_.
211
210
212
-
In the same way the `Multiplier template` needed instantiation as a component, so does the `main` component.
211
+
In the same way the _Multiplier template_ needed instantiation as a component, so does the _main_ component.
213
212
214
-
However, unlike other intermediate components, the `main` component defines the global input and output signals of a circuit.
213
+
However, unlike other intermediate components, the _main_ component defines the global input and output signals of a circuit.
215
214
216
215
Denote a list of $\texttt{n}$ signals by $\{\mathtt{ s1, s2, \dots , sn }\}$.
217
216
218
-
The general syntax to specify the `main` component is the following:
217
+
The general syntax to specify the _main_ component is the following:
219
218
220
219
```
221
220
component main {public [s1,..,sn]} = templateID(v1,..,vn);
222
221
```
223
222
224
-
Specifying the list of public signals of the circuit, indicated as `{public [s1,..,sn]}`, is optional.
223
+
Specifying the list of public signals of the circuit, indicated as _{public [s1,..,sn]}_, is optional.
225
224
226
-
Note that global inputs are considered `private` signals while global outputs are considered `public`.
225
+
Note that global inputs are considered _private_ signals while global outputs are considered _public_.
227
226
228
-
However, the `main` component has a special attribute to set a list of global inputs as public signals.
227
+
However, the _main_ component has a special attribute to set a list of global inputs as public signals.
229
228
230
-
The rule of thumb is: Any other input signal not included in this list `{public [s1,..,sn]}`, is considered private.
229
+
The rule of thumb is: Any other input signal not included in this list _{public [s1,..,sn]}_, is considered private.
231
230
232
231
### Concluding CIRCOM's features
233
232
234
233
There are many more features that distinguish CIRCOM from other known ZK tools. The rest of these features delineated in the original [CIRCOM paper](https://www.techrxiv.org/articles/preprint/CIRCOM_A_Robust_and_Scalable_Language_for_Building_Complex_Zero-Knowledge_Circuits/19374986/1).
235
234
236
235
We conclude this document by putting together the mentioned CIRCOM features in one code example.
237
236
238
-
The `Multiplier template` is again used as an example. But the `pragma` instruction is omitted for simplicity's sake.
237
+
The _Multiplier template_ is again used as an example. But the _pragma_ instruction is omitted for simplicity's sake.
0 commit comments