Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct some typos in signals.md #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mkdocs/docs/circom-language/signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ signal inter;
This small example declares an input signal with identifier `in`, an N-dimension array of output signals with identifier `out` and an intermediate signal with identifier `inter`.

## Types of Signal Assignments
Signals can only be assigned using the operations `<--` or `<==` (with the signal to be assigned occurring on the left hand side operation) and `-->` or `==>` (with the signal to be assigned occurring on the right hand side). All these operations are translated into an assigment in the witness generation code produced by the compiler. However, the key difference between the 'double arrow' assigments `<==` and `==>` and the 'single arrow' assigments `<--` and `-->` is that only the former adds a constraint to the R1CS system stating that the signal is equal to the assigned expression. Hence, using `<--` and `-->` is considered dangerous and strongly discouraged for non expert circom programmers, as it is the most common source of programming buggy ZK-protocols using circom.
Signals can only be assigned using the operations `<--` or `<==` (with the signal to be assigned occurring on the left hand side operation) and `-->` or `==>` (with the signal to be assigned occurring on the right hand side). All these operations are translated into an assignment in the witness generation code produced by the compiler. However, the key difference between the 'double arrow' assignments `<==` and `==>` and the 'single arrow' assignments `<--` and `-->` is that only the former adds a constraint to the R1CS system stating that the signal is equal to the assigned expression. Hence, using `<--` and `-->` is considered dangerous and strongly discouraged for non-expert circom programmers, as it is the most common source of programming buggy ZK-protocols using circom.

The safe options for assignments are `<==` and `==>`, since the assigned value is the only solution to the constraint system. Using `<--` and `-->` should be avoided, and only used when the assigned expression cannot be included in an arithmetic constraint in R1CS, like in the following example.

```text
out[k] <-- (in >> k) & 1;
```
In such case, since `<--` and `-->` do not add any constraint to the R1CS system stating the relation between the signal and the assigned expresion, it is crucial to add other constraints expressing such relation. To this end, circom allows to add constraints to the system using the operation `===`, whose use is explained in more detailed [here](constraint-generation.md).
In such a case, since `<--` and `-->` do not add any constraint to the R1CS system stating the relation between the signal and the assigned expression, it is crucial to add other constraints expressing such relation. To this end, circom allows adding constraints to the system using the operation `===`, whose use is explained in more detail [here](constraint-generation.md).

## Public and Private Signals
Signals are always considered private. The programmer can distinguish between public and private signals only when defining the main component, by providing the list of public input signals.
Expand All @@ -36,7 +36,7 @@ template Multiplier2(){

component main {public [in1,in2]} = Multiplier2();
```
Since circom 2.0.4, it is also allowed to initialize intermediate and outputs signals right after their declaration. Then, the previous example can be rewritten as follows:
Since circom 2.0.4, it is also allowed to initialize intermediate and output signals right after their declaration. Then, the previous example can be rewritten as follows:

```text
pragma circom 2.0.0;
Expand All @@ -54,7 +54,7 @@ component main {public [in1,in2]} = Multiplier2();

This example declares input signals `in1` and `in2` of the main component as public signals.

In circom, all output signals of the main component are public (and cannot be made private), the input signals of the main component are private if not stated otherwise using the keyword public as above. The rest of signals are all private and cannot be made public.
In circom, all output signals of the main component are public (and cannot be made private), the input signals of the main component are private if not stated otherwise using the keyword public as above. The rest of the signals are all private and cannot be made public.

Thus, from the programmer's point of view, only public input and output signals are visible from outside the circuit, and hence no intermediate signal can be accessed.

Expand Down Expand Up @@ -125,7 +125,7 @@ template B(){
component main = B();
```

This example produces a compilation error since value of signal `outA` depends on the value of signal `in`, even though, such a value is the constant 3.
This example produces a compilation error since the value of signal `outA` depends on the value of signal `in`, even though such a value is the constant 3.

Signals can only be assigned using the operations `<--` or `<==` (see [Basic operators](../basic-operators)) with the signal on the left hand side and `-->` or `==>` (see [Basic operators](../basic-operators)) with the signal on the right hand side. The safe options are `<==` and `==>`, since they assign values and also generate constraints at the same time. Using `<--` and `-->` is, in general, dangerous and should only be used when the assigned expression cannot be included in a constraint, like in the following example.

Expand Down