Skip to content

Commit

Permalink
fix: shift constraint indices by nb of public vars (#1128)
Browse files Browse the repository at this point in the history
* fix: shift constraint indices by nb of public vars

* perf: break early if all found
  • Loading branch information
ivokub authored May 14, 2024
1 parent 78e19f6 commit e822c15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions frontend/cs/scs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,19 +722,24 @@ func (builder *builder) GetWireConstraints(wires []frontend.Variable, addMissing
}
lookup[ww.WireID()] = struct{}{}
}
nbPub := builder.cs.GetNbPublicVariables()
res := make([][2]int, 0, len(wires))
iterator := builder.cs.GetSparseR1CIterator()
for c, constraintIdx := iterator.Next(), 0; c != nil; c, constraintIdx = iterator.Next(), constraintIdx+1 {
if _, ok := lookup[int(c.XA)]; ok {
res = append(res, [2]int{constraintIdx, 0})
res = append(res, [2]int{nbPub + constraintIdx, 0})
delete(lookup, int(c.XA))
continue
}
if _, ok := lookup[int(c.XB)]; ok {
res = append(res, [2]int{constraintIdx, 1})
res = append(res, [2]int{nbPub + constraintIdx, 1})
delete(lookup, int(c.XB))
continue
}
if len(lookup) == 0 {
// we can break early if we found constraints for all the wires
break
}
}
if addMissing {
nbWitnessWires := builder.cs.GetNbPublicVariables() + builder.cs.GetNbSecretVariables()
Expand All @@ -748,7 +753,7 @@ func (builder *builder) GetWireConstraints(wires []frontend.Variable, addMissing
QL: constraint.CoeffIdOne,
QO: constraint.CoeffIdMinusOne,
}, builder.genericGate)
res = append(res, [2]int{constraintIdx, 0})
res = append(res, [2]int{nbPub + constraintIdx, 0})
delete(lookup, k)
}
}
Expand Down

0 comments on commit e822c15

Please sign in to comment.