From d418ff51c5c1318882022f60fcd5139ef1017736 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Thu, 19 Dec 2024 14:24:12 +0100 Subject: [PATCH] mvpoly/tests: check the output size of ct_scaled Checking that the specification is correctly followed. --- mvpoly/tests/monomials.rs | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mvpoly/tests/monomials.rs b/mvpoly/tests/monomials.rs index b81ad623fd..676122062b 100644 --- a/mvpoly/tests/monomials.rs +++ b/mvpoly/tests/monomials.rs @@ -864,3 +864,43 @@ fn test_cross_terms_aggregated_polynomial() { aggregated_poly.compute_cross_terms(&random_eval1_prime, &random_eval2_prime, u1, u2); assert_eq!(res, cross_terms_aggregated); } + +#[test] +fn test_cross_terms_scaled_invariant_output_size() { + let mut rng = o1_utils::tests::make_test_rng(None); + + let random_eval1: [Fp; 4] = std::array::from_fn(|_| Fp::rand(&mut rng)); + let random_eval2: [Fp; 4] = std::array::from_fn(|_| Fp::rand(&mut rng)); + let u1 = Fp::rand(&mut rng); + let u2 = Fp::rand(&mut rng); + let scalar1 = Fp::rand(&mut rng); + let scalar2 = Fp::rand(&mut rng); + + { + let p1 = unsafe { Sparse::::random(&mut rng, None) }; + let cross_terms = + p1.compute_cross_terms_scaled(&random_eval1, &random_eval2, u1, u2, scalar1, scalar2); + assert_eq!(cross_terms.len(), 4); + } + + { + let p1 = Sparse::::zero(); + let cross_terms = + p1.compute_cross_terms_scaled(&random_eval1, &random_eval2, u1, u2, scalar1, scalar2); + assert_eq!(cross_terms.len(), 4); + } + + { + let p1 = Sparse::::one(); + let cross_terms = + p1.compute_cross_terms_scaled(&random_eval1, &random_eval2, u1, u2, scalar1, scalar2); + assert_eq!(cross_terms.len(), 7); + } + + { + let p1 = Sparse::::from(Fp::from(42)); + let cross_terms = + p1.compute_cross_terms_scaled(&random_eval1, &random_eval2, u1, u2, scalar1, scalar2); + assert_eq!(cross_terms.len(), 12); + } +}