Skip to content

bug: api.AssertIsLessOrEqual incorrect behavior on R1CS with constant variable #1227

@gbotrel

Description

@gbotrel

import (
	"testing"

	"github.com/consensys/gnark/frontend"
	"github.com/consensys/gnark/test"
)

type Circuit struct {
	X frontend.Variable
}

func (circuit *Circuit) Define(api frontend.API) error {
	api.AssertIsLessOrEqual(1, circuit.X)
	return nil
}

func TestConstantPath(t *testing.T) {
	assert := test.NewAssert(t)
	assert.CheckCircuit(&Circuit{},
		test.WithValidAssignment(&Circuit{X: 1}),   // 1 <= 1 --> true
		test.WithInvalidAssignment(&Circuit{X: 0})) // 1 <= 0 --> false
}

thanks to @wuestholz for reporting

Fails because of a bug in the R1CS compiler when the first parameter to api.AssertIsLessOrEqual is a constant.

Metadata

Metadata

Assignees

Labels

src: fuzzingIssue found using a fuzzing tooltype: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions