Closed drakstik closed 1 year ago
hi -- can you reproduce on develop
; (I can't). v0.9.0 (merge develop into master) is coming and may fix your issue.
hi -- can you reproduce on
develop
; (I can't). v0.9.0 (merge develop into master) is coming and may fix your issue.
I just reproduced it on v0.9.0. The problem is still there. Can't use 2D arrays, at least not this way.
Are we allowed to define a struct in this manner in Gnark?
type Matrix struct {
X [3][3]frontend.Variable `gnark:"X, secret"` // X = [N*N]frontend.Variable
Y [3][3]frontend.Variable `gnark:",public"`
}
If yes and you cannot reproduce the error on your side, what versions are you using? Also, by develop
do you mean this branch?: https://github.com/Consensys/gnark/tree/thedarkjester-develop
Yes, it is allowed. I think you have some dependency mismatch or maybe you are not running the code in the example?
I did
mkdir matrix
cd matrix
go mod init matrix
go get github.com/consensys/gnark
# create main.go as below
go mod tidy
go run main.go
file main.go
package main
import (
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
)
func main() {
// compiles our circuit into a R1CS
var circuit Matrix
ccs, _ := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
// groth16 zkSNARK: Setup
pk, vk, _ := groth16.Setup(ccs)
// witness definition
a := [3][3]frontend.Variable{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
b := [3][3]frontend.Variable{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
assignment := Matrix{X: a, Y: b} // X is secret, Y is public.
witness, _ := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
publicWitness, _ := witness.Public()
// groth16: Prove & Verify
proof, _ := groth16.Prove(ccs, pk, witness) // This proof can be sent alongside verification and public witness Y (i.e. the output).
groth16.Verify(proof, vk, publicWitness)
}
// A Matrix consists of two fields N=16
type Matrix struct {
X [3][3]frontend.Variable `gnark:"X, secret"` // X = [N*N]frontend.Variable
Y [3][3]frontend.Variable `gnark:",public"`
}
func (circuit *Matrix) Define(api frontend.API) error {
api.AssertIsEqual(circuit.Y[0][2], circuit.X[0][2])
return nil
}
Awesome, it worked. I did have dependency issues! Thanks for the fast response.
Hi, I am trying to work with 2D arrays, but I get this error:
This is the simple main.go code I'm running:
It fails at the "pk, vk, _ := groth16.Setup(ccs)" line in the main function.
I do not know if this is the same issue as #236 but please help!