-
Notifications
You must be signed in to change notification settings - Fork 82
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
Conversation
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.* |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm under the impression there are cases where addition is removed from the r1cs. See https://stackoverflow.com/questions/78136647/circom-does-not-create-a-constraint-for-addition/78177349#78177349
And
@Metachaser24 can you add these links as references to the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes adding now
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
Good to merge after resolving merge conflicts! |
7e4e7be
to
d9b8dd5
Compare
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: