From 4bec5417ebfdc2744f4e4efca453ebb020dee2cf Mon Sep 17 00:00:00 2001 From: Ivo Kubjas Date: Fri, 29 Aug 2025 22:10:57 +0000 Subject: [PATCH 1/3] fix: handle OR call for constant inputs --- frontend/cs/r1cs/api.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frontend/cs/r1cs/api.go b/frontend/cs/r1cs/api.go index 56b8e70f4..41b9d2ddd 100644 --- a/frontend/cs/r1cs/api.go +++ b/frontend/cs/r1cs/api.go @@ -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 1 + } + return 0 + } + + // 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 1 + } else { + return a + } + } + // the formulation used is for easing up the conversion to sparse r1cs res := builder.newInternalVariable() builder.MarkBoolean(res) From 75c450fb997f6aa1604f8361308f31309c33cbf0 Mon Sep 17 00:00:00 2001 From: Ivo Kubjas Date: Tue, 2 Sep 2025 09:06:17 +0000 Subject: [PATCH 2/3] chore: use stored cnst instead of ints --- frontend/cs/r1cs/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/cs/r1cs/api.go b/frontend/cs/r1cs/api.go index 41b9d2ddd..5e28b78ea 100644 --- a/frontend/cs/r1cs/api.go +++ b/frontend/cs/r1cs/api.go @@ -413,9 +413,9 @@ func (builder *builder[E]) Or(_a, _b frontend.Variable) frontend.Variable { if aConstant && bConstant { if builder.cs.IsOne(_aC) || builder.cs.IsOne(_bC) { - return 1 + return builder.cstOne() } - return 0 + return builder.cstZero() } // if one input is constant, ensure we put it in b From a4c3a11ae9a0084ec5cea17560030ac3bdddd3b1 Mon Sep 17 00:00:00 2001 From: Ivo Kubjas Date: Tue, 2 Sep 2025 09:10:35 +0000 Subject: [PATCH 3/3] chore: return constant LE --- frontend/cs/r1cs/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/cs/r1cs/api.go b/frontend/cs/r1cs/api.go index 5e28b78ea..c94c4a2fe 100644 --- a/frontend/cs/r1cs/api.go +++ b/frontend/cs/r1cs/api.go @@ -427,7 +427,7 @@ func (builder *builder[E]) Or(_a, _b frontend.Variable) frontend.Variable { if bConstant { if builder.cs.IsOne(_bC) { - return 1 + return builder.cstOne() } else { return a }