The gnark-bn254-verifier
crate is used for verifying Groth16 and PlonK proofs on the Bn254
curve, ensuring compatibility with proofs generated by the gnark
library. One can save proofs and verification keys from gnark
and subsequently load them to this library for verifying the proofs with ease.
To save the proof and verification key from gnark
, one can use the following code snippet:
// Write the verifier key.
vkFile, err := os.Create("vk.bin")
if err != nil {
panic(err)
}
defer vkFile.Close()
_, err = vk.WriteTo(vkFile)
if err != nil {
panic(err)
}
// Write the proof.
proofFile, err := os.Create("proof.bin")
if err != nil {
panic(err)
}
defer proofFile.Close()
_, err = proof.WriteTo(proofFile)
if err != nil {
panic(err)
}
To use this library, add it as a dependency in your Cargo.toml
:
[dependencies]
gnark-bn254-verifier = "1.0.2"
Then, you can verify a proof by calling the verify
function:
use gnark_bn254_verifier::{verify, ProvingSystem, Fr};
fn main() {
let proof = std::fs::read("proof.bin").unwrap();
let vk = std::fs::read("vk.bin").unwrap();
if verify(&proof, &vk, &[Fr::from(1u8), Fr::from(7u8)], ProvingSystem::Plonk) {
println!("Proof is valid");
} else {
println!("Proof is invalid");
}
}
- Verification of Groth16 and PlonK proofs generated using
gnark
. - Easy integration into Rust projects.