Skip to content

Commit

Permalink
revert: revert builder.linearExpression method
Browse files Browse the repository at this point in the history
  • Loading branch information
gbotrel committed Dec 22, 2022
1 parent e7711d3 commit 6fc0594
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frontend/cs/r1cs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (builder *builder) Println(a ...frontend.Variable) {
if i > 0 {
sbb.WriteByte(' ')
}
if v, ok := builder.linearExpression(arg); ok {
if v, ok := arg.(expr.LinearExpression); ok {
assertIsSet(v)

sbb.WriteString("%s")
Expand Down
2 changes: 1 addition & 1 deletion frontend/cs/r1cs/api_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (builder *builder) AssertIsBoolean(i1 frontend.Variable) {
func (builder *builder) AssertIsLessOrEqual(_v frontend.Variable, bound frontend.Variable) {
v := builder.toVariable(_v)

if b, ok := builder.linearExpression(bound); ok {
if b, ok := bound.(expr.LinearExpression); ok {
assertIsSet(b)
builder.mustBeLessOrEqVar(v, b)
} else {
Expand Down
18 changes: 4 additions & 14 deletions frontend/cs/r1cs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (builder *builder) MarkBoolean(v frontend.Variable) {
return
}
// v is a linear expression
l, _ := builder.linearExpression(v)
l := v.(expr.LinearExpression)
sort.Sort(l)

key := l.HashCode()
Expand All @@ -232,7 +232,7 @@ func (builder *builder) IsBoolean(v frontend.Variable) bool {
return (builder.isCstZero(&b) || builder.isCstOne(&b))
}
// v is a linear expression
l, _ := builder.linearExpression(v)
l := v.(expr.LinearExpression)
sort.Sort(l)

key := l.HashCode()
Expand Down Expand Up @@ -285,7 +285,7 @@ func (builder *builder) ConstantValue(v frontend.Variable) (*big.Int, bool) {
}

func (builder *builder) constantValue(v frontend.Variable) (constraint.Coeff, bool) {
if _v, ok := builder.linearExpression(v); ok {
if _v, ok := v.(expr.LinearExpression); ok {
assertIsSet(_v)

if len(_v) != 1 {
Expand Down Expand Up @@ -361,7 +361,7 @@ func (builder *builder) NewHint(f hint.Function, nbOutputs int, inputs ...fronte
// TODO @gbotrel hint input pass
// ensure inputs are set and pack them in a []uint64
for i, in := range inputs {
if t, ok := builder.linearExpression(in); ok {
if t, ok := in.(expr.LinearExpression); ok {
assertIsSet(t)
hintInputs[i] = builder.getLinearExpression(t)
} else {
Expand Down Expand Up @@ -449,13 +449,3 @@ func (builder *builder) compress(le expr.LinearExpression) expr.LinearExpression
builder.cs.AddConstraint(builder.newR1C(le, one, t))
return t
}

func (builder *builder) linearExpression(v frontend.Variable) (expr.LinearExpression, bool) {
switch t := v.(type) {
case expr.LinearExpression:
return t, true
case *expr.LinearExpression:
return *t, true
}
return nil, false
}

0 comments on commit 6fc0594

Please sign in to comment.