From d42ed39ed9dc4f5d38764f869814273d77da2c9a Mon Sep 17 00:00:00 2001 From: zhenfei Date: Mon, 10 Jun 2024 10:29:28 -0400 Subject: [PATCH] has error --- bi-kzg/src/bi_kzg.rs | 27 +++++++++++++++++++++++---- bi-kzg/src/poly.rs | 4 +--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bi-kzg/src/bi_kzg.rs b/bi-kzg/src/bi_kzg.rs index d7d6cc6c..81fd6f9c 100644 --- a/bi-kzg/src/bi_kzg.rs +++ b/bi-kzg/src/bi_kzg.rs @@ -144,15 +144,34 @@ where point: &Self::Point, ) -> (Self::Proof, Self::Evaluation) { // fixme - let eval = polynomial.evaluate(&point.0, &point.1); - let q_0 = polynomial.evaluate(&prover_param.borrow().tau_0, &point.1); - let q_1 = polynomial.evaluate(&point.0, &prover_param.borrow().tau_1); + let tau_0 = prover_param.borrow().tau_0; + let tau_1 = prover_param.borrow().tau_1; + let a = point.0; + let b = point.1; + + let u = polynomial.evaluate(&a, &b); + let u_prime = polynomial.evaluate(&tau_0, &b); + + let f_tau0_b = polynomial.evaluate(&tau_0, &b); + let f_a_tau1 = polynomial.evaluate(&a, &tau_1); + + let q_0 = (f_tau0_b - u) * ((tau_0 - a).invert().unwrap()); + let q_1 = (f_a_tau1 - u_prime) * ((tau_1 - b).invert().unwrap()); + let proof = BiKZGProof { pi0: (prover_param.borrow().powers_of_g[0] * q_0).into(), pi1: (prover_param.borrow().powers_of_g[0] * q_1).into(), }; - (proof, eval) + let c = polynomial.evaluate(&tau_0, &tau_1); + + let t0 = q_0 * (tau_0 - a); + let t1 = q_1 * (tau_1 - b); + let right = c - u; + + assert_eq!(t0 + t1, right, "t0 + t1 != right"); + + (proof, u) } fn verify( diff --git a/bi-kzg/src/poly.rs b/bi-kzg/src/poly.rs index 944e1789..f8c86d22 100644 --- a/bi-kzg/src/poly.rs +++ b/bi-kzg/src/poly.rs @@ -14,7 +14,7 @@ impl BivaraitePolynomial { degree_1, } } - + pub fn random(mut rng: impl RngCore, degree_0: usize, degree_1: usize) -> Self { let coefficients = (0..degree_0 * degree_1) .map(|_| F::random(&mut rng)) @@ -37,8 +37,6 @@ impl BivaraitePolynomial { * y_i }) } - - } #[cfg(test)]