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

add simplification flags to usage guide #180

Merged
merged 4 commits into from
Apr 1, 2024
Merged

Conversation

Metachaser24
Copy link
Contributor

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Mention the issue number that your changes are addressing. Use the format "Fixes #" to automatically link your pull request to the relevant issue.

Type of Change

documentation update. Added -O0 flag to the compilation step

Checklist:

@Divide-By-0
Copy link
Member

Can you add a note about not using the default which is --O2 due to a hyperlink to addition constraint deletion: https://stackoverflow.com/questions/78136647/circom-does-not-create-a-constraint-for-addition

```
*Note: You can add -l to specify the directory where the directive `include` should look for the circuits indicated. For our repo use circom -l node_modules instead of circom.
*Note: You can add -l to specify the directory where the directive `include` should look for the circuits indicated. For our repo use `circom -l node_modules` instead of circom. Additionally, we generally recommend using the `--O0` flag for optimization during compilation for beginners. However, if you're more experienced with Circom, feel free to use the `--O1` flag instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of additional constraints.*
Copy link
Member

@saleel saleel Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Divide-By-0 Addition constraints are removed during optimization by subtracting the added value from out instead..right?
out = a * b + c become out - c = a * b, but the addition is still part of the R1CS?

Copy link
Member

@Divide-By-0 Divide-By-0 Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes adding now

Copy link
Member

@saleel saleel Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick test:

signal d <== b + 5;
c === a * d;

With -O0

[  ] * [  ] - [ 51 +main.b +21888242871839275222246405745257275088548364400416034343698204186575808495616main.d ] = 0
[ 21888242871839275222246405745257275088548364400416034343698204186575808495616main.a ] * [ main.d ] - [ 21888242871839275222246405745257275088548364400416034343698204186575808495616main.c ] = 0

With -O2

[ 21888242871839275222246405745257275088548364400416034343698204186575808495616main.a ] * [ 51 +main.b ] - [ 21888242871839275222246405745257275088548364400416034343698204186575808495616main.c ] = 0

Even though addition constraint is removed in O2, the result is effectively same. The addition output gets added on to the next constraint where its used.

Even when circuit has only one addition contract we cannot generate witness that doesn't match the condition even though r1cs are empty.
Edit: ^ this might be a property of snarkjs, and doesn't mean its not possible to produce fake witnesses that pass using other approaches

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Divide-By-0 @Metachaser24 I think O2 (default) should be used ideally as it reduce the total constraints without loosing intended assertions.
Or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Divide-By-0 @Metachaser24 I think O2 (default) should be used ideally as it reduce the total constraints without loosing intended assertions. Or am I missing something?

I think there are cases where they do corrupt the logic of the circuit. One example is an addition constraint unconnected to anything else -- we used to have this for address plus one which wasn't constrained -- Pierre made a fake input pass for a similar case. I'm worried the pattern appears for other combinations of + and * as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the worst case, it also gives proof malleability -- i.e. a nullifier constraint might have an addition somewhere then people might be able to forge a different nullifier that technically proves knowledge of preimage, but may not satisfy uniqueness any longer (since that specific value is no longer constrained).

@Divide-By-0
Copy link
Member

Good to merge after resolving merge conflicts!

@Divide-By-0 Divide-By-0 merged commit 5613d74 into main Apr 1, 2024
5 checks passed
@saleel saleel deleted the Metachaser24-patch branch April 19, 2024 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants