#kzg #bls12-381

已删除 a0kzg

ZKG 多项式承诺游乐场

2 个发布

0.1.1 2021 年 8 月 17 日
0.1.0 2021 年 8 月 17 日

#8 in #kzg

MIT/Apache

22KB
356 代码行

学习-kate

Kate-Zaverucha-Goldberg 多项式承诺在 Rust 游乐场

这是一个仅用于学习的项目,因此请不要在生产环境中使用 Rust 中的 KZG 承诺,其想法是使用其他函数扩展它,如 plonk 或 verkle 树。

它使用了出色的 bls12_381 crate

KZG 示例

use a0kzg::{Scalar, Kzg};
// Create a trustd setup that allows maximum 4 points (degree+1)
let kzg = Kzg::trusted_setup(5);

// define the set of points (the "population"), and create a polinomial
// for them, as well its polinomial commitment, see the polinomial commitment
// like the "hash" of the polinomial
let set = vec![
  (Scalar::from(1), Scalar::from(2)),
  (Scalar::from(2), Scalar::from(3)),
  (Scalar::from(3), Scalar::from(4)),
  (Scalar::from(4), Scalar::from(57)),
];
let (p, c) = kzg.poly_commitment_from_set(&set);

// generate a proof that (1,2) and (2,3) are in the set
let proof01 = kzg.prove(&p, &vec![set[0].clone(), set[1].clone()]);

// prove that (1,2) and (2,3) are in the set
assert!(kzg.verify(&c, &vec![set[0].clone(), set[1].clone()], &proof01));
// other proofs will fail since the proof only works for exactly (1,2) AND (2,3)
assert!(!kzg.verify(&c, &vec![set[0].clone()], &proof01));
assert!(!kzg.verify(&c, &vec![set[0].clone(), set[2].clone()], &proof01));

// prove and verify that the whole set exists in the whole set
let proof0123 = kzg.prove(&p, &set);
assert!(kzg.verify(&c, &set, &proof0123));

依赖项

~1.5MB
~27K SLoC