Skip to content

brevis-network/gnark-bn-verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gnark-bn-verifier

Groth16 zero-knowledge proof verifier, implemented in Rust.

Verifies BN128 curve Groth16 proofs generated by the gnark compiler.

Dependencies

  • bn: BN128 curve pairing operations
  • anyhow: Error handling

Installation

[dependencies]
gnark-bn-verifier = "0.1.0"

Quick Start

Verifying a Groth16 Proof

use gnark_bn_verifier::{proof::Groth16Proof, vk::Groth16VKey};
use bn::Fr;

// Deserialize verification key and proof from bytes
let vk = Groth16VKey::try_from(vk_bytes)?;
let proof = Groth16Proof::try_from(proof_bytes)?;

// Public inputs from the circuit
let public_inputs: Vec<Fr> = vec![
    Fr::from(123),
    Fr::from(456),
];

// Verify
proof.verify(&vk, &public_inputs)?;
println!("Proof verified successfully!");

Format Specification

Verification Key

Byte sequence generated by gnark:

Offset Length Content
0 32 α (G1, compressed)
32 32 (unused)
64 64 β (G2, compressed)
128 64 γ (G2, compressed)
224 64 δ (G2, compressed)
288 4 num_k (big-endian u32)
292 num_k × 32 K[i] (G1, compressed)
  • num_k = number of public inputs + 1

Proof

Byte sequence generated by gnark:

Offset Length Content
0 64 A (G1, uncompressed)
64 128 B (G2, uncompressed)
192 64 C (G1, uncompressed)

Public Inputs

Public inputs are scalar values of type Fr, corresponding to public parameters in the circuit.

API Reference

Groth16VKey

Verification key struct.

// Deserialize from bytes
let vk = Groth16VKey::try_from(bytes)?;

// Get number of public inputs
let num_inputs = vk.num_public_inputs();

Groth16Proof

Proof struct.

// Deserialize from bytes
let proof = Groth16Proof::try_from(bytes)?;

// Verify the proof
proof.verify(&vk, &public_inputs)?;

Testing

cargo test

Generating Real Test Vectors

To verify real proofs, you need to compile a circuit with gnark and generate proofs:

  1. Install gnark: go get github.com/ConsenSys/gnark
  2. Write circuit code
  3. Run prover to generate vk/proof/public_inputs
  4. Verify using this library

Example Circuit (Go)

package main

import (
    "github.com/consensys/gnark/std/hash/mimc"
    "github.com/consensys/gnark/benchmark"
)

func main() {
    // Define circuit
    circuit := MyCircuit{}

    // Generate test vectors
    _ = circuit
}

Security Notes

  • This library only implements the verification algorithm, not proof generation
  • Verification key must be from a trusted source
  • Pairing operations are performed on the BN128 curve

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages