Question: how to capture the error of api.AssertIsEqual() func ? #1222
Replies: 6 comments
-
api.Assertxx funcitos will assert if the condition fails. |
Beta Was this translation helpful? Give feedback.
-
I know, but the functionality I want to implement is: in the main function, I execute groth16.Verify(proof, vk, publicWitness) for verification, check for any errors, and then perform corresponding operations. It's something like the following code: err := groth16.Verify(proof, vk, publicWitness)
if err == nil {
fmt.Println("verify success!!!")
} else {
fmt.Println("other op")
} could id come true? |
Beta Was this translation helpful? Give feedback.
-
Please check whether the following code is what you want. func TestCubic_Groth16_BN254(t *testing.T) {
field := ecc.BN254.ScalarField()
assert := test.NewAssert(t)
var circuit Circuit
assignment := &Circuit{
X: 3,
Y: 35,
}
_r1cs, err := frontend.Compile(field, r1cs.NewBuilder, &circuit)
assert.NoError(err)
pk, vk, err := groth16.Setup(_r1cs)
assert.NoError(err)
wit, err := frontend.NewWitness(assignment, ecc.BN254.ScalarField())
assert.NoError(err)
proof, err := groth16.Prove(_r1cs, pk, wit)
assert.NoError(err)
//rebuild the pubWitness, verify pass
values1 := make(chan interface{})
go func() {
defer close(values1)
values1 <- fr_bn254.NewElement(35)
}()
pubWit, _ := witness.New(ecc.BN254.ScalarField())
pubWit.Fill(1, 0, values1)
err = groth16.Verify(proof, vk, pubWit)
if err != nil {
fmt.Printf("err: %v\n", err)
} else {
fmt.Printf("verification pass\n")
}
//rebuild the pubWitness, verify fail
values2 := make(chan interface{})
go func() {
defer close(values2)
values2 <- fr_bn254.NewElement(36)
}()
pubWit, _ = witness.New(ecc.BN254.ScalarField())
pubWit.Fill(1, 0, values2)
err = groth16.Verify(proof, vk, pubWit)
if err != nil {
fmt.Printf("err: %v\n", err)
} else {
fmt.Printf("verification pass\n")
}
} |
Beta Was this translation helpful? Give feedback.
-
Basically the same, thank you for the components |
Beta Was this translation helpful? Give feedback.
-
Are you trying to verify the proof in-circuit or out-circuit? For out-circuit implementation you can switch on |
Beta Was this translation helpful? Give feedback.
-
Converted to discussion as seems to be question about gnark usage, not an issue. |
Beta Was this translation helpful? Give feedback.
-
How can I intercept and handle the error that occurs from the function
api.AssertIsEqual(0, 1)
without the program terminating with an error?Beta Was this translation helpful? Give feedback.
All reactions