zkcg-verifier 0.2.2

ZKCG proof verifier supporting Halo2 circuits and zkVM execution receipts
Documentation

zkcg-verifier

Rust verifier for proofs generated by the ZKCG system.

Verification is lightweight and can be integrated into applications that need to validate off-chain computations.

Installation

cargo add zkcg-verifier

Example

use zkcg_verifier::{Proof, ProofSystem, Verifier};
use zkcg_verifier::engine::PublicInputs;

let proof = Proof::new(ProofSystem::Halo2, proof_bytes);
let public_inputs = PublicInputs {
    threshold: 40,
    old_state_root: [0u8; 32],
    nonce: 1,
};

Verifier::verify(&proof, &public_inputs)?;

Batch verification uses the same universal model:

use zkcg_verifier::{Proof, ProofSystem, VerificationRequest, Verifier};
use zkcg_verifier::engine::PublicInputs;

let batch = vec![
    VerificationRequest::new(
        Proof::new(ProofSystem::Halo2, halo2_bytes),
        PublicInputs {
            threshold: 40,
            old_state_root: [0u8; 32],
            nonce: 1,
        },
    ),
    VerificationRequest::new(
        Proof::new(ProofSystem::ZkVm, zkvm_bytes),
        PublicInputs {
            threshold: 40,
            old_state_root: [0u8; 32],
            nonce: 1,
        },
    ),
];

Verifier::verify_batch(&batch)?;

For independent proofs, the same batch can be verified in parallel:

Verifier::verify_batch_parallel(&batch)?;

If you need per-proof outcomes instead of a single pass/fail result:

let results = Verifier::verify_batch_parallel_results(&batch);

for result in results {
    match result {
        Ok(()) => println!("proof verified"),
        Err(err) => println!("proof failed: {err}"),
    }
}

You can also build a custom registry for additional proof systems while keeping the default API:

use zkcg_common::errors::ProtocolError;
use zkcg_verifier::{
    Proof, ProofSystem, ProofVerifier, Verifier, VerifierRegistry,
};
use zkcg_verifier::engine::PublicInputs;

struct MockVerifier;

impl ProofVerifier for MockVerifier {
    fn verify(&self, _proof: &[u8], _public_inputs: &PublicInputs) -> Result<(), ProtocolError> {
        Ok(())
    }
}

let mut registry = VerifierRegistry::new();
registry.register(ProofSystem::custom("groth16-demo"), MockVerifier);

let proof = Proof::new(ProofSystem::custom("groth16-demo"), proof_bytes);
Verifier::verify_with_registry(&registry, &proof, &public_inputs)?;

Features

Halo2 proof verification

zkVM verification support

example integrations

Repository

https://github.com/MRSKYWAY/ZKCG