-
Notifications
You must be signed in to change notification settings - Fork 517
bug: Using Range Checking component leads to incorrect # of inputs in Solidity verifier #860
Copy link
Copy link
Closed
Description
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 {
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels