Skip to content

Commit f83879b

Browse files
committed
fix: remove endianness shenanigans
1 parent 06bdefa commit f83879b

File tree

2 files changed

+10
-42
lines changed

2 files changed

+10
-42
lines changed

src/provider/non_hiding_zeromorph.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ where
189189
}
190190

191191
debug_assert_eq!(Self::commit(pp, poly).unwrap().0, comm.0);
192-
debug_assert_eq!(poly.evaluate_BE(point), eval.0);
192+
debug_assert_eq!(poly.evaluate(point), eval.0);
193193

194194
let (quotients, remainder) = quotients(poly, point);
195195
debug_assert_eq!(remainder, eval.0);
@@ -329,7 +329,7 @@ fn quotients<F: PrimeField>(poly: &MultilinearPolynomial<F>, point: &[F]) -> (Ve
329329

330330
let mut remainder = poly.Z.to_vec();
331331
let mut quotients = point
332-
.iter()
332+
.iter().rev() // assume polynomial variables come in LE form
333333
.enumerate()
334334
.rev()
335335
.map(|(num_var, x_i)| {
@@ -361,8 +361,8 @@ fn quotients<F: PrimeField>(poly: &MultilinearPolynomial<F>, point: &[F]) -> (Ve
361361
}
362362

363363
// TODO : move this somewhere else
364-
fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, u: &[F]) -> (F, Vec<F>) {
365-
let num_vars = u.len();
364+
fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, point: &[F]) -> (F, Vec<F>) {
365+
let num_vars = point.len();
366366

367367
let squares_of_x = iter::successors(Some(x), |&x| Some(x.square()))
368368
.take(num_vars + 1)
@@ -397,7 +397,7 @@ fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, u: &[F]) -> (F, Vec<F>)
397397
.zip(squares_of_x)
398398
.zip(&vs)
399399
.zip(&vs[1..])
400-
.zip(u)
400+
.zip(point.iter().rev()) // assume variables come in LE form
401401
.map(
402402
|(((((power_of_y, offset_of_x), square_of_x), v_i), v_j), u_i)| {
403403
-(power_of_y * offset_of_x + z * (square_of_x * v_j - *u_i * v_i))
@@ -437,15 +437,12 @@ where
437437
// TODO: the following two lines will need to change base
438438
let polynomial = MultilinearPolynomial::new(poly.to_vec());
439439

440-
// Nova evaluates in lower endian, the implementation assumes big endian
441-
let rev_point = point.iter().rev().cloned().collect::<Vec<_>>();
442-
443440
let evaluation = ZMEvaluation(*eval);
444441
ZMPCS::open(
445442
pk,
446443
&commitment,
447444
&polynomial,
448-
&rev_point,
445+
point,
449446
&evaluation,
450447
transcript,
451448
)
@@ -462,15 +459,12 @@ where
462459
let commitment = ZMCommitment::from(UVKZGCommitment::from(*comm));
463460
let evaluation = ZMEvaluation(*eval);
464461

465-
// Nova evaluates in lower endian, the implementation assumes big endian
466-
let rev_point = point.iter().rev().cloned().collect::<Vec<_>>();
467-
468462
// TODO: this clone is unsightly!
469463
ZMPCS::verify(
470464
vk,
471465
transcript,
472466
&commitment,
473-
&rev_point,
467+
point,
474468
&evaluation,
475469
arg.clone(),
476470
)?;
@@ -527,7 +521,7 @@ mod test {
527521
let point = iter::from_fn(|| transcript.squeeze(b"pt").ok())
528522
.take(num_vars)
529523
.collect::<Vec<_>>();
530-
let eval = ZMEvaluation(poly.evaluate_BE(&point));
524+
let eval = ZMEvaluation(poly.evaluate(&point));
531525

532526
let mut transcript_prover = Keccak256Transcript::<E::G1>::new(b"test");
533527
let proof = ZMPCS::open(&pp, &comm, &poly, &point, &eval, &mut transcript_prover).unwrap();
@@ -577,11 +571,11 @@ mod test {
577571
}
578572
let (_quotients, remainder) = quotients(&poly, &point);
579573
assert_eq!(
580-
poly.evaluate_BE(&point),
574+
poly.evaluate(&point),
581575
remainder,
582576
"point: {:?}, \n eval: {:?}, remainder:{:?}",
583577
point,
584-
poly.evaluate_BE(&point),
578+
poly.evaluate(&point),
585579
remainder
586580
);
587581
}

src/spartan/polys/multilinear.rs

-26
Original file line numberDiff line numberDiff line change
@@ -130,32 +130,6 @@ impl<Scalar: PrimeField> MultilinearPolynomial<Scalar> {
130130
}
131131
new_poly
132132
}
133-
134-
/// Evaluate the dense MLE at the given point. The MLE is assumed to be in
135-
/// monomial basis.
136-
///
137-
/// # Example
138-
/// ```
139-
/// use pasta_curves::pallas::Scalar as Fr;
140-
/// use nova_snark::spartan::polys::multilinear::MultilinearPolynomial;
141-
///
142-
/// // The two-variate polynomial x_1 + 3 * x_0 * x_1 + 2 evaluates to [2, 3, 2, 6]
143-
/// // 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)
144-
/// let mle = MultilinearPolynomial::new(
145-
/// vec![2, 3, 2, 6].iter().map(|x| Fr::from(*x as u64)).collect()
146-
/// );
147-
///
148-
/// // By the uniqueness of MLEs, `mle` is precisely the above polynomial, which
149-
/// // takes the value 54 at the point (x_1 = 1, x_0 = 17)
150-
/// let eval = mle.evaluate_BE(&[Fr::one(), Fr::from(17)]);
151-
/// assert_eq!(eval, Fr::from(54));
152-
/// ```
153-
pub fn evaluate_BE(&self, point: &[Scalar]) -> Scalar {
154-
assert_eq!(self.num_vars, point.len());
155-
// evaluate requires "lower endian"
156-
let revp = point.iter().cloned().rev().collect::<Vec<_>>();
157-
self.evaluate(&revp)
158-
}
159133
}
160134

161135
impl<Scalar: PrimeField> Index<usize> for MultilinearPolynomial<Scalar> {

0 commit comments

Comments
 (0)