From 0c35f159d72daf0ecd378c99c414cc8ae946ecf7 Mon Sep 17 00:00:00 2001 From: Gautam Botrel Date: Tue, 13 Aug 2024 16:04:42 -0500 Subject: [PATCH] test: added non regression test for api.Select bool cond --- .../issue1246/issue1246_test.go | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 internal/regression_tests/issue1246/issue1246_test.go diff --git a/internal/regression_tests/issue1246/issue1246_test.go b/internal/regression_tests/issue1246/issue1246_test.go new file mode 100644 index 0000000000..12f77f2815 --- /dev/null +++ b/internal/regression_tests/issue1246/issue1246_test.go @@ -0,0 +1,37 @@ +package issue1246_test + +import ( + "testing" + + "github.com/consensys/gnark/frontend" + "github.com/consensys/gnark/test" +) + +// Circuit definition +// here we aim to catch the case where the API doesn't enforce the condition to be a boolean +type notBoolCond struct { + Condition, Y1, Y2 frontend.Variable +} + +func (circuit *notBoolCond) Define(api frontend.API) error { + d := api.Select(circuit.Condition, circuit.Y1, circuit.Y2) + + // per api definition, d should hold either Y1 or Y2. + // we have y1 = 2, y2 = 4, condition = 2 (non boolean) + // r = condition(y1-y2) + y2 + api.AssertIsEqual(d, 0) + + return nil +} + +func TestSelectConditionNonBool(t *testing.T) { + assert := test.NewAssert(t) + + assert.CheckCircuit(¬BoolCond{}, + test.WithInvalidAssignment(¬BoolCond{ + Condition: 2, + Y1: 2, + Y2: 4, + }), + ) +}