diff --git a/crates/proof-of-sql/src/base/polynomial/multilinear_extension.rs b/crates/proof-of-sql/src/base/polynomial/multilinear_extension.rs index 99720707c..a5fe4481c 100644 --- a/crates/proof-of-sql/src/base/polynomial/multilinear_extension.rs +++ b/crates/proof-of-sql/src/base/polynomial/multilinear_extension.rs @@ -1,12 +1,12 @@ use crate::base::{database::Column, if_rayon, scalar::Scalar, slice_ops}; use alloc::{rc::Rc, vec::Vec}; -use core::ffi::c_void; +use core::{ffi::c_void, fmt::Debug}; use num_traits::Zero; #[cfg(feature = "rayon")] use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; /// Interface for operating on multilinear extension's in-place -pub trait MultilinearExtension { +pub trait MultilinearExtension: Debug { /// Given an evaluation vector, compute the evaluation of the multilinear /// extension fn inner_product(&self, evaluation_vec: &[S]) -> S; @@ -18,7 +18,7 @@ pub trait MultilinearExtension { fn to_sumcheck_term(&self, num_vars: usize) -> Rc>; /// pointer to identify the slice forming the MLE - fn id(&self) -> *const c_void; + fn id(&self) -> (*const c_void, usize); #[cfg(test)] /// Given an evaluation point, compute the evaluation of the multilinear @@ -30,7 +30,7 @@ pub trait MultilinearExtension { } } -impl<'a, T: Sync, S: Scalar> MultilinearExtension for &'a [T] +impl<'a, T: Sync + Debug, S: Scalar> MultilinearExtension for &'a [T] where &'a T: Into, { @@ -56,8 +56,8 @@ where Rc::new(scalars) } - fn id(&self) -> *const c_void { - self.as_ptr().cast::() + fn id(&self) -> (*const c_void, usize) { + (self.as_ptr().cast::(), self.len()) } } @@ -76,20 +76,20 @@ macro_rules! slice_like_mle_impl { (&self[..]).to_sumcheck_term(num_vars) } - fn id(&self) -> *const c_void { + fn id(&self) -> (*const c_void, usize) { (&self[..]).id() } }; } -impl<'a, T: Sync, S: Scalar> MultilinearExtension for &'a Vec +impl<'a, T: Sync + Debug, S: Scalar> MultilinearExtension for &'a Vec where &'a T: Into, { slice_like_mle_impl!(); } -impl<'a, T: Sync, const N: usize, S: Scalar> MultilinearExtension for &'a [T; N] +impl<'a, T: Sync + Debug, const N: usize, S: Scalar> MultilinearExtension for &'a [T; N] where &'a T: Into, { @@ -139,7 +139,7 @@ impl MultilinearExtension for &Column<'_, S> { } } - fn id(&self) -> *const c_void { + fn id(&self) -> (*const c_void, usize) { match self { Column::Boolean(c) => MultilinearExtension::::id(c), Column::Scalar(c) | Column::VarChar((_, c)) | Column::Decimal75(_, _, c) => { @@ -167,7 +167,7 @@ impl MultilinearExtension for Column<'_, S> { (&self).to_sumcheck_term(num_vars) } - fn id(&self) -> *const c_void { + fn id(&self) -> (*const c_void, usize) { (&self).id() } } diff --git a/crates/proof-of-sql/src/base/polynomial/multilinear_extension_test.rs b/crates/proof-of-sql/src/base/polynomial/multilinear_extension_test.rs index 1d72361db..083592486 100644 --- a/crates/proof-of-sql/src/base/polynomial/multilinear_extension_test.rs +++ b/crates/proof-of-sql/src/base/polynomial/multilinear_extension_test.rs @@ -1,5 +1,17 @@ use super::MultilinearExtension; use crate::base::{database::Column, scalar::test_scalar::TestScalar}; +use bumpalo::Bump; + +#[test] +fn allocated_slices_must_have_different_ids_even_when_one_is_empty() { + let alloc = Bump::new(); + let foo = alloc.alloc_slice_fill_default(5) as &[TestScalar]; + let bar = alloc.alloc_slice_fill_default(0) as &[TestScalar]; + assert_ne!( + MultilinearExtension::::id(&foo), + MultilinearExtension::::id(&bar) + ); +} #[test] fn we_can_use_multilinear_extension_methods_for_i64_slice() { diff --git a/crates/proof-of-sql/src/proof_primitive/sumcheck/prover_state.rs b/crates/proof-of-sql/src/proof_primitive/sumcheck/prover_state.rs index af3544c39..371ab8242 100644 --- a/crates/proof-of-sql/src/proof_primitive/sumcheck/prover_state.rs +++ b/crates/proof-of-sql/src/proof_primitive/sumcheck/prover_state.rs @@ -7,6 +7,7 @@ use crate::base::polynomial::CompositePolynomial; use crate::base::scalar::Scalar; use alloc::vec::Vec; +#[derive(Debug)] pub struct ProverState { /// Stores the list of products that is meant to be added together. Each multiplicand is represented by /// the index in `flattened_ml_extensions` diff --git a/crates/proof-of-sql/src/sql/proof/composite_polynomial_builder.rs b/crates/proof-of-sql/src/sql/proof/composite_polynomial_builder.rs index c5e6878df..62346bb1e 100644 --- a/crates/proof-of-sql/src/sql/proof/composite_polynomial_builder.rs +++ b/crates/proof-of-sql/src/sql/proof/composite_polynomial_builder.rs @@ -17,7 +17,7 @@ pub struct CompositePolynomialBuilder { fr_multiplicands_rest: Vec<(S, Vec>>)>, zerosum_multiplicands: Vec<(S, Vec>>)>, fr: Rc>, - mles: IndexMap<*const c_void, Rc>>, + mles: IndexMap<(*const c_void, usize), Rc>>, } impl CompositePolynomialBuilder { diff --git a/crates/proof-of-sql/src/sql/proof/sumcheck_subpolynomial.rs b/crates/proof-of-sql/src/sql/proof/sumcheck_subpolynomial.rs index 1a9437fa3..8c0279182 100644 --- a/crates/proof-of-sql/src/sql/proof/sumcheck_subpolynomial.rs +++ b/crates/proof-of-sql/src/sql/proof/sumcheck_subpolynomial.rs @@ -23,6 +23,7 @@ pub type SumcheckSubpolynomialTerm<'a, S> = (S, Vec { terms: Vec>, subpolynomial_type: SumcheckSubpolynomialType,