Skip to content

bug: Using Range Checking component leads to incorrect # of inputs in Solidity verifier #860

@puma314

Description

@puma314

Description

In a simple circuit when using the range checking component (as shown in a simple test example below), the Verifier.sol that is exported has 4 public inputs, even though the circuit only has 3 public inputs. When generating a proof and outputting the public witness to verify the proof in Solidity the public witness has only has 3 public inputs (which makes sense). What is the 4th public input that should be passed to the on-chain verifier?

Note that the generated proof still verifies in go when using groth16.Verify(proof, vk, publicWitness). If the rangecheck component is removed, then the generated Verifier.sol has the correct verifyProof function signature with 3 public inputs.

type MyCircuit struct {
	X frontend.Variable `gnark:",public"`
	Y frontend.Variable `gnark:",public"`
	Z frontend.Variable `gnark:",public"`
	A frontend.Variable `gnark:"-"`
}

func (circuit *MyCircuit) Define(api frontend.API) error {
	api.AssertIsEqual(circuit.Z, api.Add(circuit.X, circuit.Y))
	rangeChecker := rangecheck.New(api)
	rangeChecker.Check(circuit.X, 100)
	return nil
}

func TestSanity(t *testing.T) {
	circuit := MyCircuit{}

	r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
	if err != nil {
		panic(err)
	}
	_, vk, err := groth16.Setup(r1cs)
	if err != nil {
		panic(err)
	}

	buf := new(bytes.Buffer)
	err = vk.ExportSolidity(buf)
	if err != nil {
		panic(err)
	}
	content := buf.String()

	contractFile, err := os.Create("Verifier.sol")
	if err != nil {
		panic(err)
	}
	w := bufio.NewWriter(contractFile)
	// write the new content to the writer
	_, err = w.Write([]byte(content))
	if err != nil {
		panic(err)
	}
	contractFile.Close()
}

Generated Verifier.sol function signature:

 function verifyProof(
        uint256[8] calldata proof,
        uint256[4] calldata input
    ) public view {

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