diff --git a/frontend/cs/r1cs/api_assertions.go b/frontend/cs/r1cs/api_assertions.go index e62679d11..cae64710d 100644 --- a/frontend/cs/r1cs/api_assertions.go +++ b/frontend/cs/r1cs/api_assertions.go @@ -130,12 +130,6 @@ func (builder *builder) mustBeLessOrEqVar(a, bound frontend.Variable) { // but a can be either constant or a wire. nbBits := builder.cs.FieldBitLen() - if ca, aConst := builder.constantValue(a); aConst { - // if a is a constant, we only need the number of bits of a; - // the binary decomposition of the bound will fail if nbBits(bound) > nbBits(a) - ba := builder.cs.ToBigInt(ca) - nbBits = ba.BitLen() - } aBits := bits.ToBinary(builder, a, bits.WithNbDigits(nbBits), bits.WithUnconstrainedOutputs(), bits.OmitModulusCheck()) boundBits := bits.ToBinary(builder, bound, bits.WithNbDigits(nbBits)) diff --git a/internal/regression_tests/issue1227/issue_1227_test.go b/internal/regression_tests/issue1227/issue_1227_test.go index 3315f54d2..a93429952 100644 --- a/internal/regression_tests/issue1227/issue_1227_test.go +++ b/internal/regression_tests/issue1227/issue_1227_test.go @@ -8,17 +8,22 @@ import ( ) type Circuit struct { - X frontend.Variable + constVal int + X frontend.Variable } func (circuit *Circuit) Define(api frontend.API) error { - api.AssertIsLessOrEqual(1, circuit.X) + api.AssertIsLessOrEqual(circuit.constVal, circuit.X) return nil } func TestConstantPath(t *testing.T) { assert := test.NewAssert(t) - assert.CheckCircuit(&Circuit{}, + assert.CheckCircuit(&Circuit{constVal: 1}, test.WithValidAssignment(&Circuit{X: 1}), // 1 <= 1 --> true test.WithInvalidAssignment(&Circuit{X: 0})) // 1 <= 0 --> false + // test edge case where constant is 0 + assert.CheckCircuit(&Circuit{constVal: 0}, + test.WithValidAssignment(&Circuit{X: 1}), // 0 <= 1 --> true + test.WithValidAssignment(&Circuit{X: 0})) // 0 <= 0 --> true }