Open ilitteri opened 1 year ago
first, thanks for the nice reproductible snippet 👍
Now: (keep in mind; this constraint/
package is quite recent, up until last month, it was only used internally by gnark frontend / backend.)
NewR1CS
method to do that behind the scenes is reasonable 👍 schema.NbPublic
is different than r1cs.GetNbPublicVariables
both return what they should; the schema cares about the structure of the circuit, and returns the number of public variables there. The r1cs
cares about the actual number of public variables it has (including the one wire). witness.Fill
may not be the best choice; if the witness is generated outside of gnark, it can directly be decoded (UnmarshalBinary
)
The next piece of code proves that $x \cdot y = z$ where $x, z$ are public variables and $y$ is a private variable (witness):
For you to be able to run this, you'll need the
buildWitness
function:This code works but only because I added manually the following line:
If you remove this line and the -1 in the patch from the line:
you'll get the following error when proving:
The error says that we are specting 2 variables (1 public and 1 private) when this is wrong. We've already declared 3 variables (2 public and 1 private).
Users mustn't be responsible for handling this like that.