Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions frontend/cs/r1cs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,31 @@ func (builder *builder[E]) Or(_a, _b frontend.Variable) frontend.Variable {
builder.AssertIsBoolean(a)
builder.AssertIsBoolean(b)

_aC, aConstant := builder.constantValue(a)
_bC, bConstant := builder.constantValue(b)

if aConstant && bConstant {
if builder.cs.IsOne(_aC) || builder.cs.IsOne(_bC) {
return builder.cstOne()
}
return builder.cstZero()
}

// if one input is constant, ensure we put it in b
if aConstant {
a, b = b, a
_bC = _aC
bConstant = aConstant
}

if bConstant {
if builder.cs.IsOne(_bC) {
return builder.cstOne()
} else {
return a
}
}

// the formulation used is for easing up the conversion to sparse r1cs
res := builder.newInternalVariable()
builder.MarkBoolean(res)
Expand Down
Loading