Crates.io | spawn-zk-snarks |
lib.rs | spawn-zk-snarks |
version | 0.1.5 |
source | src |
created_at | 2024-09-09 07:35:25.855105 |
updated_at | 2024-12-07 21:54:45.397393 |
description | Zero-knowledge proof library with EVM compatibility |
homepage | |
repository | https://github.com/nzengi/spawn-zk-snarks |
max_upload_size | |
id | 1368934 |
size | 32,273 |
spawn-zk-snarks
is a Rust library that provides a robust implementation of Zero-Knowledge Proofs (ZKPs) using the Groth16 proving system. Built on top of the arkworks ecosystem, it offers both high performance and EVM compatibility.
Groth16 Proving System
Circuit Implementation
EVM Compatibility
Performance
Add this to your Cargo.toml
:
[dependencies]
spawn-zk-snarks = "0.1.4"
use spawn_zk_snarks::{Groth16Setup, ArithmeticCircuit};
use ark_bn254::Fr;
use ark_ff::One;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup phase
let setup = Groth16Setup::new(3, 2)?;
// Generate proof
let inputs = vec![Fr::one()];
let witness = vec![Fr::one(), Fr::one()];
let proof = setup.prove(&inputs, &witness)?;
// Verify proof
let is_valid = setup.verify(&proof, &inputs)?;
assert!(is_valid);
// Generate Solidity verifier
let contract = generate_verifier_contract(&setup.verifying_key)?;
Ok(())
}
Performance on M1 MacBook Pro:
proof generation time: [1.3244 ms 1.3519 ms 1.3931 ms]
proof verification time: [760.30 µs 762.93 µs 765.25 µs]
evm conversion time: [289.96 ns 291.12 ns 292.43 ns]
// Generate Solidity verifier contract
let contract = generate_verifier_contract(&setup.verifying_key)?;
// Convert proof to EVM format
let proof_bytes = Groth16Setup::proof_to_evm_format(&proof)?;
// Estimate gas cost
let gas = Groth16Setup::estimate_verification_gas(
proof_bytes.len(),
inputs.len()
);
Run unit tests:
cargo test
Run benchmarks:
cargo bench
MIT License. See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
This library is provided as is, without any security guarantees. Please perform your own security audit before using in production.