Skip to content

bug: api.Select does not enforce condition to be bool on PlonK frontend #1246

@gbotrel

Description

@gbotrel

Following test fails:

// 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(&notBoolCond{},
		test.WithInvalidAssignment(&notBoolCond{
			Condition: 2,
			Y1:        2,
			Y2:        4,
		}),
	)
}

Thanks to Least Authority for the report --

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions