Circom compiler removes crucial constraint after simplication

42 views Asked by At

While testing Num2Bits template with n=8 from circomlib I faced this:

R1CS without simplification:

[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[0] ] * [ main.out[0] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[1] ] * [ main.out[1] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[2] ] * [ main.out[2] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[3] ] * [ main.out[3] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[4] ] * [ main.out[4] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[5] ] * [ main.out[5] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[6] ] * [ main.out[6] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[7] ] * [ main.out[7] ] - [  ] = 0
[INFO]  snarkJS: [  ] * [  ] - [ 21888242871839275222246405745257275088548364400416034343698204186575808495616main.out[0] +21888242871839275222246405745257275088548364400416034343698204186575808495615main.out[1] +21888242871839275222246405745257275088548364400416034343698204186575808495613main.out[2] +21888242871839275222246405745257275088548364400416034343698204186575808495609main.out[3] +21888242871839275222246405745257275088548364400416034343698204186575808495601main.out[4] +21888242871839275222246405745257275088548364400416034343698204186575808495585main.out[5] +218

R1CS with full simplification activated:

[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[0] ] * [ main.out[0] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[1] ] * [ main.out[1] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[2] ] * [ main.out[2] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[3] ] * [ main.out[3] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[4] ] * [ main.out[4] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[5] ] * [ main.out[5] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[6] ] * [ main.out[6] ] - [  ] = 0
[INFO]  snarkJS: [ 218882428718392752222464057452572750885483644004160343436982041865758084956161 +main.out[7] ] * [ main.out[7] ] - [  ] = 0

Why it removes the last constraint? It looks like the very important constraint that must be included to the R1CS since it checks the sum of bits and the original input. Or I miss something?

1

There are 1 answers

0
John Targaryen On

The simplification is happening because the addition constraint is getting removed, which is because when you compile with circom, --O2 is the default. Add --O1 or --O0 at the end of your circom command to avoid addition constraint deletion.