Skip to content

Commit e1ffd8d

Browse files
authored
fix: handle OR call for constant inputs (#1592)
1 parent 124b693 commit e1ffd8d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

frontend/cs/r1cs/api.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,31 @@ func (builder *builder[E]) Or(_a, _b frontend.Variable) frontend.Variable {
408408
builder.AssertIsBoolean(a)
409409
builder.AssertIsBoolean(b)
410410

411+
_aC, aConstant := builder.constantValue(a)
412+
_bC, bConstant := builder.constantValue(b)
413+
414+
if aConstant && bConstant {
415+
if builder.cs.IsOne(_aC) || builder.cs.IsOne(_bC) {
416+
return builder.cstOne()
417+
}
418+
return builder.cstZero()
419+
}
420+
421+
// if one input is constant, ensure we put it in b
422+
if aConstant {
423+
a, b = b, a
424+
_bC = _aC
425+
bConstant = aConstant
426+
}
427+
428+
if bConstant {
429+
if builder.cs.IsOne(_bC) {
430+
return builder.cstOne()
431+
} else {
432+
return a
433+
}
434+
}
435+
411436
// the formulation used is for easing up the conversion to sparse r1cs
412437
res := builder.newInternalVariable()
413438
builder.MarkBoolean(res)

0 commit comments

Comments
 (0)