Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: index out of range [0] with length 0 #96

Closed
chiumichael opened this issue May 10, 2021 · 3 comments · Fixed by #126
Closed

panic: runtime error: index out of range [0] with length 0 #96

chiumichael opened this issue May 10, 2021 · 3 comments · Fixed by #126

Comments

@chiumichael
Copy link

Hi there,

I'm trying to build the whole pipeline of circuit compilation, proofing and verification, but I'm encountering a

panic: runtime error: index out of range [0] with length 0

at the groth16 setup stage. I've tried to closely model this after the example code in the gnark/examples directory, so I'm not sure what I'm missing.

Any help would be greatly appreciated!

type TestCircuit struct {
	XONE 	frontend.Variable 	`gnark:",public"`
	XTWO 	frontend.Variable 	`gnark:",public"`
}

func (circuit *TestCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
	my_x2 := cs.Add(circuit.XONE, 0)
	cs.AssertIsEqual(cs.Add(4, my_x2), circuit.XTWO)
	return nil
}

func main() {

	var circuit TestCircuit
	r1cs, err_r1cs := frontend.Compile(ecc.BN254, backend.GROTH16, &circuit)
	if err_r1cs != nil {
		fmt.Println("circuit compilation error")
	}

	var witness TestCircuit
	witness.XONE.Assign(1)
	witness.XTWO.Assign(5)

	_, _, err2 := groth16.Setup(r1cs)	// pk = proving key, vk = verifier key
	if err2 != nil {
		fmt.Println("groth16 setup error")
	}

	// _, err3 := groth16.Prove(r1cs, pk, &witness)
	// if err3 != nil {
	// 	fmt.Println("proof error")
	// }
	// err4 = groth16.Verify(proof, vk, &witness)
	// if err4 != nil {
	// 	fmt.Println("invalid proof")
	// }

}
@ThomasPiellard
Copy link
Collaborator

Hi @chiumichael , so your code is correct, there is a bug on the FFT on our end when the size of the domain is one (it's the case for your circuit because you only have one constraint). The fix will be pushed shortly on gnark-crypto.

Thanks for raising the issue!

@chiumichael
Copy link
Author

Np, and thanks for the prompt reply!

I have a quick follow up question though: In the cubic example (gnark/examples/cubic), isn't there only one constraint there as well?

@ThomasPiellard
Copy link
Collaborator

No in cubic there are 3 constraints, internally it looks like this:

x*x = a
a*x = b
(b+x+5)*1 = y

In this internal representation each line is in fact a constraint, and should be interpreted as constraints rather than instructions. The user provides the necessary inputs (namely x and y in the cubic example) so this system of constraints has only one solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants