diff --git a/src/provider/non_hiding_zeromorph.rs b/src/provider/non_hiding_zeromorph.rs index 7d6a46680..d7a313eab 100644 --- a/src/provider/non_hiding_zeromorph.rs +++ b/src/provider/non_hiding_zeromorph.rs @@ -189,7 +189,7 @@ where } debug_assert_eq!(Self::commit(pp, poly).unwrap().0, comm.0); - debug_assert_eq!(poly.evaluate_BE(point), eval.0); + debug_assert_eq!(poly.evaluate(point), eval.0); let (quotients, remainder) = quotients(poly, point); debug_assert_eq!(remainder, eval.0); @@ -329,7 +329,7 @@ fn quotients(poly: &MultilinearPolynomial, point: &[F]) -> (Ve let mut remainder = poly.Z.to_vec(); let mut quotients = point - .iter() + .iter().rev() // assume polynomial variables come in LE form .enumerate() .rev() .map(|(num_var, x_i)| { @@ -361,8 +361,8 @@ fn quotients(poly: &MultilinearPolynomial, point: &[F]) -> (Ve } // TODO : move this somewhere else -fn eval_and_quotient_scalars(y: F, x: F, z: F, u: &[F]) -> (F, Vec) { - let num_vars = u.len(); +fn eval_and_quotient_scalars(y: F, x: F, z: F, point: &[F]) -> (F, Vec) { + let num_vars = point.len(); let squares_of_x = iter::successors(Some(x), |&x| Some(x.square())) .take(num_vars + 1) @@ -397,7 +397,7 @@ fn eval_and_quotient_scalars(y: F, x: F, z: F, u: &[F]) -> (F, Vec) .zip(squares_of_x) .zip(&vs) .zip(&vs[1..]) - .zip(u) + .zip(point.iter().rev()) // assume variables come in LE form .map( |(((((power_of_y, offset_of_x), square_of_x), v_i), v_j), u_i)| { -(power_of_y * offset_of_x + z * (square_of_x * v_j - *u_i * v_i)) @@ -437,18 +437,8 @@ where // TODO: the following two lines will need to change base let polynomial = MultilinearPolynomial::new(poly.to_vec()); - // Nova evaluates in lower endian, the implementation assumes big endian - let rev_point = point.iter().rev().cloned().collect::>(); - let evaluation = ZMEvaluation(*eval); - ZMPCS::open( - pk, - &commitment, - &polynomial, - &rev_point, - &evaluation, - transcript, - ) + ZMPCS::open(pk, &commitment, &polynomial, point, &evaluation, transcript) } fn verify( @@ -462,18 +452,8 @@ where let commitment = ZMCommitment::from(UVKZGCommitment::from(*comm)); let evaluation = ZMEvaluation(*eval); - // Nova evaluates in lower endian, the implementation assumes big endian - let rev_point = point.iter().rev().cloned().collect::>(); - // TODO: this clone is unsightly! - ZMPCS::verify( - vk, - transcript, - &commitment, - &rev_point, - &evaluation, - arg.clone(), - )?; + ZMPCS::verify(vk, transcript, &commitment, point, &evaluation, arg.clone())?; Ok(()) } } @@ -527,7 +507,7 @@ mod test { let point = iter::from_fn(|| transcript.squeeze(b"pt").ok()) .take(num_vars) .collect::>(); - let eval = ZMEvaluation(poly.evaluate_BE(&point)); + let eval = ZMEvaluation(poly.evaluate(&point)); let mut transcript_prover = Keccak256Transcript::::new(b"test"); let proof = ZMPCS::open(&pp, &comm, &poly, &point, &eval, &mut transcript_prover).unwrap(); @@ -577,11 +557,11 @@ mod test { } let (_quotients, remainder) = quotients(&poly, &point); assert_eq!( - poly.evaluate_BE(&point), + poly.evaluate(&point), remainder, "point: {:?}, \n eval: {:?}, remainder:{:?}", point, - poly.evaluate_BE(&point), + poly.evaluate(&point), remainder ); } diff --git a/src/spartan/polys/multilinear.rs b/src/spartan/polys/multilinear.rs index a1d365ee4..4ce48918d 100644 --- a/src/spartan/polys/multilinear.rs +++ b/src/spartan/polys/multilinear.rs @@ -130,32 +130,6 @@ impl MultilinearPolynomial { } new_poly } - - /// Evaluate the dense MLE at the given point. The MLE is assumed to be in - /// monomial basis. - /// - /// # Example - /// ``` - /// use pasta_curves::pallas::Scalar as Fr; - /// use nova_snark::spartan::polys::multilinear::MultilinearPolynomial; - /// - /// // The two-variate polynomial x_1 + 3 * x_0 * x_1 + 2 evaluates to [2, 3, 2, 6] - /// // in the lagrange basis: 2*(1 - x_0)(1 - x_1) + 3*(1-x_0)(x_1) + 2*(x_0)(1-x_1) + 6*(x_0)(x_1) - /// let mle = MultilinearPolynomial::new( - /// vec![2, 3, 2, 6].iter().map(|x| Fr::from(*x as u64)).collect() - /// ); - /// - /// // By the uniqueness of MLEs, `mle` is precisely the above polynomial, which - /// // takes the value 54 at the point (x_1 = 1, x_0 = 17) - /// let eval = mle.evaluate_BE(&[Fr::one(), Fr::from(17)]); - /// assert_eq!(eval, Fr::from(54)); - /// ``` - pub fn evaluate_BE(&self, point: &[Scalar]) -> Scalar { - assert_eq!(self.num_vars, point.len()); - // evaluate requires "lower endian" - let revp = point.iter().cloned().rev().collect::>(); - self.evaluate(&revp) - } } impl Index for MultilinearPolynomial {