You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi, given gnark's current architecture, I suspect you'll come up with a wish list at some point to make your life easier -- feel free to create issues in gnark repo / participate in discussions.
Might be of interest to you: Consensys/gnark#452 . In particular there is an example on how to build a R1CS without using the frontend; note that the APIs / interfaces are still quite experimental.
funcExampleR1CS_GetConstraints() {
// build a constraint system; this is (usually) done by the frontend package// for this Example we want to manipulate the constraints and output a string representation// and build the linear expressions "manually".r1cs:=cs.NewR1CS(0)
ONE:=r1cs.AddPublicVariable("1") // the "ONE" wireY:=r1cs.AddPublicVariable("Y")
X:=r1cs.AddSecretVariable("X")
v0:=r1cs.AddInternalVariable() // X²v1:=r1cs.AddInternalVariable() // X³// coefficientscOne:=r1cs.FromInterface(1)
cFive:=r1cs.FromInterface(5)
// X² == X * Xr1cs.AddConstraint(constraint.R1C{
L: constraint.LinearExpression{r1cs.MakeTerm(&cOne, X)},
R: constraint.LinearExpression{r1cs.MakeTerm(&cOne, X)},
O: constraint.LinearExpression{r1cs.MakeTerm(&cOne, v0)},
})
// X³ == X² * Xr1cs.AddConstraint(constraint.R1C{
L: constraint.LinearExpression{r1cs.MakeTerm(&cOne, v0)},
R: constraint.LinearExpression{r1cs.MakeTerm(&cOne, X)},
O: constraint.LinearExpression{r1cs.MakeTerm(&cOne, v1)},
})
// Y == X³ + X + 5r1cs.AddConstraint(constraint.R1C{
R: constraint.LinearExpression{r1cs.MakeTerm(&cOne, ONE)},
L: constraint.LinearExpression{r1cs.MakeTerm(&cOne, Y)},
O: constraint.LinearExpression{
r1cs.MakeTerm(&cFive, ONE),
r1cs.MakeTerm(&cOne, X),
r1cs.MakeTerm(&cOne, v1),
},
})
// get the constraintsconstraints, r:=r1cs.GetConstraints()
for_, r1c:=rangeconstraints {
fmt.Println(r1c.String(r))
// for more granularity use constraint.NewStringBuilder(r) that embeds a string.Builder// and has WriteLinearExpression and WriteTerm methods.
}
// Output:// X ⋅ X == v0// v0 ⋅ X == v1// Y ⋅ 1 == 5 + X + v1
}
The text was updated successfully, but these errors were encountered:
Hi! Thanks for this. You hit the spot, this is more or less what I was looking for (I was planning on forking gnark for this because all I needed was internal haha), even though the frontend API is terrific what I need is something more low-level like this.
hi, given gnark's current architecture, I suspect you'll come up with a wish list at some point to make your life easier -- feel free to create issues in gnark repo / participate in discussions.
Might be of interest to you: Consensys/gnark#452 . In particular there is an example on how to build a
R1CS
without using thefrontend
; note that the APIs / interfaces are still quite experimental.The text was updated successfully, but these errors were encountered: