Skip to content

Commit 1e1907a

Browse files
authored
Merge pull request 0xPolygon#525 from 0xPolygon/zkevm-specs-sec-review
zkEVM review - sections Specs to Concepts
2 parents bbb23fe + 8488319 commit 1e1907a

33 files changed

+683
-656
lines changed

docs/zkEVM/concepts/circom-intro-brief.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,49 @@
1-
21
!!!info
32
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.
43

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.
65

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.
87

98
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.
109

1110
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.
1211

1312
CIRCOM takes the output of the STARK Recursion as input, so as to create its corresponding witness.
1413

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.
1615

1716
![CIRCOM's input and output](../../img/zkEVM/01circom-witness-zkprover.png)
1817

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).
2019

2120
The set of valid circuit input, intermediate and output values satisfying the R1CS is actually the witness related to the input STARK proof.
2221

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.
2423

2524
## Circuit context
2625

2726
Arithmetic circuits are mostly used as standard models for studying the complexity of computations.
2827

2928
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.
3029

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.
3231

3332
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.
3433

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.
3635

3736
Once obtained, the R1CS can later be used by a zk-SNARK protocol to generate verifiable proof.
3837

3938
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.
4039

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.
4241

4342
CIRCOM was developed for the very purpose of scaling complex Arithmetic circuits by realizing them as combined instantiations of smaller Arithmetic circuits.
4443

4544
## What is CIRCOM?
4645

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.
4847

4948
![CIRCOM Overall Context](../../img/zkEVM/02circom-overall-context.png)
5049

@@ -54,9 +53,9 @@ As described in the title of its [specifications paper](https://www.techrxiv.org
5453

5554
It is designed as a low-level circuit language, mimicking the design of electronic circuits, for naturally defining Arithmetic circuits.
5655

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.
5857

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.
6059

6160
In this regard, CIRCOM users can use templates to create their own custom circuits with varied complexity.
6261

@@ -77,25 +76,25 @@ The CIRCOM compiler is mainly written in Rust and it is open source.
7776

7877
The CIRCOM language has its own peculiarities. The focus in this subsection is on a few features characteristic of CIRCOM.
7978

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}$.
8180

8281
![A simple Multiplier Arithmetic circuit](../../img/zkEVM/03circom-simple-arith-circuit.png)
8382

84-
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:
8584

8685
$$
8786
\texttt{a} \times \texttt{b} \texttt{ - c = 0}
8887
$$
8988

9089
### The `pragma` instruction
9190

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.
9392

9493
```
9594
pragma circom 2.0.0;
9695
```
9796

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.
9998

10099
### Declaration of signals
101100

@@ -130,7 +129,7 @@ Templates are parametrizable in the sense that their outputs depend on free inpu
130129

131130
They are general descriptions of circuits, that have some input and output signals, as well as a relation between the inputs and the outputs.
132131

133-
The following code shows how a `Multiplier template` is created:
132+
The following code shows how a _Multiplier template_ is created:
134133

135134
```
136135
pragma circom 2.0.0;
@@ -147,15 +146,15 @@ template Multiplier () {
147146

148147
### Instantiation of templates
149148

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.
151150

152151
In CIRCOM, the instantiation of a template is called a component, and it is created as follows:
153152

154153
```
155154
component main = Multiplier();
156155
```
157156

158-
The `Multiplier template` does not depend on any parameter.
157+
The _Multiplier template_ does not depend on any parameter.
159158

160159
However, it is possible to initially create a generic, parametrizable template that can later be instantiated using specific parameters to construct the circuit.
161160

@@ -165,7 +164,7 @@ Small circuits can be defined which can be combined to create larger circuits by
165164

166165
### Compiling a circuit
167166

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:
169168

170169
- It captures the arithmetic relation between signals, and
171170
- 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
174173

175174
This enables the compiler to easily generate the R1CS describing a circuit, together with instructions to compute intermediate and output values of a circuit.
176175

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:
178177

179178
```
180179
circom multiplier.circom --r1cs --c --wasm --sym
181180
```
182181

183-
After compiling the `.circom` circuit, the compiler returns four files:
182+
After compiling the _.circom_ circuit, the compiler returns four files,
184183

185184
- A file with the R1CS constraints (symbolic task)
186185
- 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:
189188

190189
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.
191190

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.
193192

194193
Recall that a valid set of circuit input, intermediate and output values is called the witness.
195194

196195
### Private and public signals
197196

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_.
199198

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.
201200

202201
```
203202
component main {public [a]} = Multiplier();
204203
```
205204

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.
207206

208207
### Main component
209208

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_.
211210

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.
213212

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.
215214

216215
Denote a list of $\texttt{n}$ signals by $\{\mathtt{ s1, s2, \dots , sn }\}$.
217216

218-
The general syntax to specify the `main` component is the following:
217+
The general syntax to specify the _main_ component is the following:
219218

220219
```
221220
component main {public [s1,..,sn]} = templateID(v1,..,vn);
222221
```
223222

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.
225224

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_.
227226

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.
229228

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.
231230

232231
### Concluding CIRCOM's features
233232

234233
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).
235234

236235
We conclude this document by putting together the mentioned CIRCOM features in one code example.
237236

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.
239238

240239
```
241240
template Multiplier() {

0 commit comments

Comments
 (0)