3 stable releases
1.0.2 | Aug 14, 2024 |
---|
#425 in Cryptography
53 downloads per month
48KB
1K
SLoC
gnark BN254 Verifier
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.
How to save proofs and verification keys from gnark
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 proving key.
proofFile, err := os.Create("proof.bin")
if err != nil {
panic(err)
}
defer proofFile.Close()
_, err = proof.WriteTo(proofFile)
if err != nil {
panic(err)
}
Usage
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");
}
}
Features
- Verification of Groth16 and PlonK proofs generated using
gnark
. - Easy integration into Rust projects.
Dependencies
~6.5MB
~120K SLoC