| Crates.io | kzg-mini |
| lib.rs | kzg-mini |
| version | 0.1.1 |
| created_at | 2025-05-20 18:34:54.518544+00 |
| updated_at | 2025-05-20 18:34:54.518544+00 |
| description | A small implementation of the KZG polynomial commitment scheme over the arkworks ecosystem. |
| homepage | |
| repository | https://github.com/sidx04/kzg-mini |
| max_upload_size | |
| id | 1681942 |
| size | 38,082 |
A minimal implementation of the KZG commitment scheme. Built on top of the arkworks ecosystem.
ark_ec::Pairing).⚠️ Experimental: This crate is designed for educational purposes. Not intended for production use.
Add to your Cargo.toml:
[dependencies]
kzg-mini = "0.1"
ark-ff = "0.4"
ark-ec = "0.4"
ark-std = "0.4"
ark-bls12-381 = "0.4" # Or any curve from arkworks
The following examples demonstrate how to create a polynomial commitment and open a KZG proof using the kzg_mini crate on the BLS12-381 curve. See examples for the full code.
This example constructs a polynomial f(x) = 3x² + 2x + 1, commits to it, and verifies a KZG proof:
fn main() {
let mut rng = test_rng();
let poly = Polynomial::new(vec![Fr::from(1u64), Fr::from(2u64), Fr::from(3u64)]);
let tau = Fr::rand(&mut rng);
let g1 = G1Projective::generator();
let g2 = G2Projective::generator();
let setup = KZGCeremony::<Bls12_381>::setup(2, tau, g1, g2);
let commitment = setup.commit(&poly);
let point = Fr::from(42u64);
let proof = setup.open(&poly, point);
let ok = setup.verify(commitment, &proof);
println!("Reference Polynomial: {:#?}", poly);
println!("Commitment: {}", commitment);
println!("Proof: {:#?}", proof);
println!("KZG proof verified: {}", ok);
}
This example shows how to generate a polynomial from a string, commit to it, and verify the corresponding proof:
fn main() {
let mut rng = test_rng();
let poly = Polynomial::from_str("hell0, world!")?;
let tau = Fr::rand(&mut rng);
let g1 = G1Projective::generator();
let g2 = G2Projective::generator();
let setup = KZGCeremony::<Bls12_381>::setup(poly.coeffs.len(), tau, g1, g2);
let commitment = setup.commit(&poly);
let point = Fr::from(42u64);
let proof = setup.open(&poly, point);
let ok = setup.verify(commitment, &proof);
println!("Reference Polynomial: {:#?}", poly);
println!("Commitment: {}", commitment);
println!("Proof: {:#?}", proof);
println!("KZG proof verified: {}", ok);
}
Polynomial<F>: A simple polynomial type over any ark_ff::Field, with arithmetic operations and evaluation.KZGCeremony<E>: Holds the trusted setup parameters for a KZG commitment over a pairing engine E.KZGCommitment, KZGProof: Types representing the output of commitment and opening.MIT or Apache-2.0
Built using arkworks libraries.