From 316bad428e3dec617c69564f5c64fc07cf4f174a Mon Sep 17 00:00:00 2001 From: Jay White Date: Mon, 12 Aug 2024 18:28:14 -0400 Subject: [PATCH] refactor: rename `pre_result` to `pcs_proof` (#105) --- .../src/sql/proof/proof_builder.rs | 22 ++++++------ .../src/sql/proof/proof_builder_test.rs | 8 ++--- .../proof-of-sql/src/sql/proof/query_proof.rs | 32 ++++++++--------- .../src/sql/proof/sumcheck_mle_evaluations.rs | 8 ++--- .../proof/sumcheck_mle_evaluations_test.rs | 8 ++--- .../verifiable_query_result_test_utility.rs | 4 +-- .../src/sql/proof/verification_builder.rs | 34 +++++++++---------- .../sql/proof/verification_builder_test.rs | 16 ++++----- 8 files changed, 64 insertions(+), 68 deletions(-) diff --git a/crates/proof-of-sql/src/sql/proof/proof_builder.rs b/crates/proof-of-sql/src/sql/proof/proof_builder.rs index b523900d5..9d925ccd4 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_builder.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_builder.rs @@ -16,7 +16,7 @@ pub struct ProofBuilder<'a, S: Scalar> { num_sumcheck_variables: usize, bit_distributions: Vec, commitment_descriptor: Vec>, - pre_result_mles: Vec + 'a>>, + pcs_proof_mles: Vec + 'a>>, sumcheck_subpolynomials: Vec>, /// The challenges used in creation of the constraints in the proof. /// Specifically, these are the challenges that the verifier sends to @@ -39,7 +39,7 @@ impl<'a, S: Scalar> ProofBuilder<'a, S> { num_sumcheck_variables, bit_distributions: Vec::new(), commitment_descriptor: Vec::new(), - pre_result_mles: Vec::new(), + pcs_proof_mles: Vec::new(), sumcheck_subpolynomials: Vec::new(), post_result_challenges, } @@ -67,7 +67,7 @@ impl<'a, S: Scalar> ProofBuilder<'a, S> { /// /// An anchored MLE is an MLE where the verifier has access to the commitment. pub fn produce_anchored_mle(&mut self, data: impl MultilinearExtension + 'a) { - self.pre_result_mles.push(Box::new(data)); + self.pcs_proof_mles.push(Box::new(data)); } /// Produce an MLE for a intermediate computed column that we can reference in sumcheck. @@ -139,13 +139,13 @@ impl<'a, S: Scalar> ProofBuilder<'a, S> { /// Given the evaluation vector, compute evaluations of all the MLEs used in sumcheck except /// for those that correspond to result columns sent to the verifier. #[tracing::instrument( - name = "ProofBuilder::evaluate_pre_result_mles", + name = "ProofBuilder::evaluate_pcs_proof_mles", level = "debug", skip_all )] - pub fn evaluate_pre_result_mles(&self, evaluation_vec: &[S]) -> Vec { - let mut res = Vec::with_capacity(self.pre_result_mles.len()); - for evaluator in self.pre_result_mles.iter() { + pub fn evaluate_pcs_proof_mles(&self, evaluation_vec: &[S]) -> Vec { + let mut res = Vec::with_capacity(self.pcs_proof_mles.len()); + for evaluator in self.pcs_proof_mles.iter() { res.push(evaluator.inner_product(evaluation_vec)); } res @@ -153,11 +153,11 @@ impl<'a, S: Scalar> ProofBuilder<'a, S> { /// Given random multipliers, multiply and add together all of the MLEs used in sumcheck except /// for those that correspond to result columns sent to the verifier. - #[tracing::instrument(name = "ProofBuilder::fold_pre_result_mles", level = "debug", skip_all)] - pub fn fold_pre_result_mles(&self, multipliers: &[S]) -> Vec { - assert_eq!(multipliers.len(), self.pre_result_mles.len()); + #[tracing::instrument(name = "ProofBuilder::fold_pcs_proof_mles", level = "debug", skip_all)] + pub fn fold_pcs_proof_mles(&self, multipliers: &[S]) -> Vec { + assert_eq!(multipliers.len(), self.pcs_proof_mles.len()); let mut res = vec![Zero::zero(); self.table_length]; - for (multiplier, evaluator) in multipliers.iter().zip(self.pre_result_mles.iter()) { + for (multiplier, evaluator) in multipliers.iter().zip(self.pcs_proof_mles.iter()) { evaluator.mul_add(&mut res, multiplier); } res diff --git a/crates/proof-of-sql/src/sql/proof/proof_builder_test.rs b/crates/proof-of-sql/src/sql/proof/proof_builder_test.rs index f97aabfa2..4d283b8d0 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_builder_test.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_builder_test.rs @@ -47,7 +47,7 @@ fn we_can_compute_commitments_for_intermediate_mles_using_a_non_zero_offset() { } #[test] -fn we_can_evaluate_pre_result_mles() { +fn we_can_evaluate_pcs_proof_mles() { let mle1 = [1, 2]; let mle2 = [10i64, 20]; let mut builder = ProofBuilder::new(2, 1, Vec::new()); @@ -57,7 +57,7 @@ fn we_can_evaluate_pre_result_mles() { Curve25519Scalar::from(100u64), Curve25519Scalar::from(10u64), ]; - let evals = builder.evaluate_pre_result_mles(&evaluation_vec); + let evals = builder.evaluate_pcs_proof_mles(&evaluation_vec); let expected_evals = [ Curve25519Scalar::from(120u64), Curve25519Scalar::from(1200u64), @@ -159,14 +159,14 @@ fn we_can_form_the_provable_query_result() { } #[test] -fn we_can_fold_pre_result_mles() { +fn we_can_fold_pcs_proof_mles() { let mle1 = [1, 2]; let mle2 = [10i64, 20]; let mut builder = ProofBuilder::new(2, 1, Vec::new()); builder.produce_anchored_mle(&mle1); builder.produce_intermediate_mle(&mle2[..]); let multipliers = [Curve25519Scalar::from(100u64), Curve25519Scalar::from(2u64)]; - let z = builder.fold_pre_result_mles(&multipliers); + let z = builder.fold_pcs_proof_mles(&multipliers); let expected_z = [ Curve25519Scalar::from(120u64), Curve25519Scalar::from(240u64), diff --git a/crates/proof-of-sql/src/sql/proof/query_proof.rs b/crates/proof-of-sql/src/sql/proof/query_proof.rs index 8b6d3148d..908122f4f 100644 --- a/crates/proof-of-sql/src/sql/proof/query_proof.rs +++ b/crates/proof-of-sql/src/sql/proof/query_proof.rs @@ -34,7 +34,7 @@ pub struct QueryProof { /// Sumcheck Proof pub sumcheck_proof: SumcheckProof, /// MLEs used in sumcheck except for the result columns - pub pre_result_mle_evaluations: Vec, + pub pcs_proof_evaluations: Vec, /// Inner product proof of the MLEs' evaluations pub evaluation_proof: CP, } @@ -103,22 +103,20 @@ impl QueryProof { // evaluate the MLEs used in sumcheck except for the result columns let mut evaluation_vec = vec![Zero::zero(); table_length]; compute_evaluation_vector(&mut evaluation_vec, &evaluation_point); - let pre_result_mle_evaluations = builder.evaluate_pre_result_mles(&evaluation_vec); + let pcs_proof_evaluations = builder.evaluate_pcs_proof_mles(&evaluation_vec); // commit to the MLE evaluations - transcript.append_canonical_serialize( - MessageLabel::QueryMleEvaluations, - &pre_result_mle_evaluations, - ); + transcript + .append_canonical_serialize(MessageLabel::QueryMleEvaluations, &pcs_proof_evaluations); // fold together the pre result MLEs -- this will form the input to an inner product proof // of their evaluations (fold in this context means create a random linear combination) - let mut random_scalars = vec![Zero::zero(); pre_result_mle_evaluations.len()]; + let mut random_scalars = vec![Zero::zero(); pcs_proof_evaluations.len()]; transcript.challenge_scalars( &mut random_scalars, MessageLabel::QueryMleEvaluationsChallenge, ); - let folded_mle = builder.fold_pre_result_mles(&random_scalars); + let folded_mle = builder.fold_pcs_proof_mles(&random_scalars); // finally, form the inner product proof of the MLEs' evaluations let evaluation_proof = CP::new( @@ -133,7 +131,7 @@ impl QueryProof { bit_distributions: builder.bit_distributions().to_vec(), commitments, sumcheck_proof, - pre_result_mle_evaluations, + pcs_proof_evaluations, evaluation_proof, }; (proof, provable_result) @@ -212,13 +210,12 @@ impl QueryProof { // commit to mle evaluations transcript.append_canonical_serialize( MessageLabel::QueryMleEvaluations, - &self.pre_result_mle_evaluations, + &self.pcs_proof_evaluations, ); // draw the random scalars for the evaluation proof - // (i.e. the folding/random linear combination of the pre_result_mles) - let mut evaluation_random_scalars = - vec![Zero::zero(); self.pre_result_mle_evaluations.len()]; + // (i.e. the folding/random linear combination of the pcs_proof_mles) + let mut evaluation_random_scalars = vec![Zero::zero(); self.pcs_proof_evaluations.len()]; transcript.challenge_scalars( &mut evaluation_random_scalars, MessageLabel::QueryMleEvaluationsChallenge, @@ -238,7 +235,7 @@ impl QueryProof { table_length, &subclaim.evaluation_point, &sumcheck_random_scalars, - &self.pre_result_mle_evaluations, + &self.pcs_proof_evaluations, &result_evaluations, result.indexes(), ); @@ -262,11 +259,11 @@ impl QueryProof { } // finally, check the MLE evaluations with the inner product proof - let product = builder.folded_pre_result_evaluation(); + let product = builder.folded_pcs_proof_evaluation(); self.evaluation_proof .verify_batched_proof( &mut transcript, - builder.pre_result_commitments(), + builder.pcs_proof_commitments(), builder.inner_product_multipliers(), &product, &subclaim.evaluation_point, @@ -292,8 +289,7 @@ impl QueryProof { fn validate_sizes(&self, counts: &ProofCounts, result: &ProvableQueryResult) -> bool { result.num_columns() == counts.result_columns && self.commitments.len() == counts.intermediate_mles - && self.pre_result_mle_evaluations.len() - == counts.intermediate_mles + counts.anchored_mles + && self.pcs_proof_evaluations.len() == counts.intermediate_mles + counts.anchored_mles } } diff --git a/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations.rs b/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations.rs index 40800abb4..d7e133a98 100644 --- a/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations.rs +++ b/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations.rs @@ -28,7 +28,7 @@ pub struct SumcheckMleEvaluations<'a, S: Scalar> { /// is zero across all entries. pub random_evaluation: S, /// The evaluations (at the random point generated by sumcheck) of the mles that are evaluated by the inner product argument. These are batched together and checked by a single IPA. - pub pre_result_evaluations: &'a [S], + pub pcs_proof_evaluations: &'a [S], /// The evaluations (at the random point generated by sumcheck) of the final result table columns. pub result_evaluations: &'a [S], } @@ -39,14 +39,14 @@ impl<'a, S: Scalar> SumcheckMleEvaluations<'a, S> { /// # Inputs /// - `evaluation_point` - the point, outputted by sumcheck, at which to evaluate the MLEs /// - `sumcheck_random_scalars` - the random scalars used to batch the evaluations that are proven via IPA - /// - `pre_result_evaluations` - the evaluations of the MLEs that are proven via IPA + /// - `pcs_proof_evaluations` - the evaluations of the MLEs that are proven via IPA /// - `result_evaluations` - the evaluations of the final result table columns /// - `result_indexes` - the indexes of the entries in the result columns. This can be sparse or dense pub fn new( table_length: usize, evaluation_point: &[S], sumcheck_random_scalars: &SumcheckRandomScalars, - pre_result_evaluations: &'a [S], + pcs_proof_evaluations: &'a [S], result_evaluations: &'a [S], result_indexes: &Indexes, ) -> Self { @@ -69,7 +69,7 @@ impl<'a, S: Scalar> SumcheckMleEvaluations<'a, S> { num_sumcheck_variables: evaluation_point.len(), one_evaluation, random_evaluation, - pre_result_evaluations, + pcs_proof_evaluations, result_evaluations, result_indexes_evaluation, } diff --git a/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations_test.rs b/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations_test.rs index 9b8505823..aec1b7d1d 100644 --- a/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations_test.rs +++ b/crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations_test.rs @@ -12,13 +12,13 @@ fn we_can_track_the_evaluation_of_mles_used_within_sumcheck() { let sumcheck_random_scalars = SumcheckRandomScalars::new(&random_scalars, 3, 2); - let pre_result_evaluations = [Curve25519Scalar::from(42u64)]; + let pcs_proof_evaluations = [Curve25519Scalar::from(42u64)]; let result_evaluations = [Curve25519Scalar::from(51u64)]; let evals = SumcheckMleEvaluations::new( 3, &evaluation_point, &sumcheck_random_scalars, - &pre_result_evaluations, + &pcs_proof_evaluations, &result_evaluations, &Indexes::Sparse(vec![]), ); @@ -54,13 +54,13 @@ fn we_can_track_the_evaluation_of_dense_indexes() { let sumcheck_random_scalars = SumcheckRandomScalars::new(&random_scalars, 3, 2); - let pre_result_evaluations = [Curve25519Scalar::from(42u64)]; + let pcs_proof_evaluations = [Curve25519Scalar::from(42u64)]; let result_evaluations = [Curve25519Scalar::from(51u64)]; let evals = SumcheckMleEvaluations::new( 3, &evaluation_point, &sumcheck_random_scalars, - &pre_result_evaluations, + &pcs_proof_evaluations, &result_evaluations, &Indexes::Dense(0..3), ); diff --git a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs index 4a17994c3..19e349016 100644 --- a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs +++ b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs @@ -35,9 +35,9 @@ pub fn exercise_verification( let proof = res.proof.as_ref().unwrap(); // try changing MLE evaluations - for i in 0..proof.pre_result_mle_evaluations.len() { + for i in 0..proof.pcs_proof_evaluations.len() { let mut res_p = res.clone(); - res_p.proof.as_mut().unwrap().pre_result_mle_evaluations[i] += Curve25519Scalar::one(); + res_p.proof.as_mut().unwrap().pcs_proof_evaluations[i] += Curve25519Scalar::one(); assert!(res_p.verify(expr, accessor, &()).is_err()); } diff --git a/crates/proof-of-sql/src/sql/proof/verification_builder.rs b/crates/proof-of-sql/src/sql/proof/verification_builder.rs index b34e79fd0..1ee6a2e6a 100644 --- a/crates/proof-of-sql/src/sql/proof/verification_builder.rs +++ b/crates/proof-of-sql/src/sql/proof/verification_builder.rs @@ -11,10 +11,10 @@ pub struct VerificationBuilder<'a, C: Commitment> { inner_product_multipliers: &'a [C::Scalar], sumcheck_evaluation: C::Scalar, bit_distributions: &'a [BitDistribution], - pre_result_commitments: Vec, - folded_pre_result_evaluation: C::Scalar, + pcs_proof_commitments: Vec, + folded_pcs_proof_evaluation: C::Scalar, consumed_result_mles: usize, - consumed_pre_result_mles: usize, + consumed_pcs_proof_mles: usize, consumed_intermediate_mles: usize, produced_subpolynomials: usize, /// The challenges used in creation of the constraints in the proof. @@ -39,7 +39,7 @@ impl<'a, C: Commitment> VerificationBuilder<'a, C> { ) -> Self { assert_eq!( inner_product_multipliers.len(), - mle_evaluations.pre_result_evaluations.len() + mle_evaluations.pcs_proof_evaluations.len() ); Self { mle_evaluations, @@ -49,10 +49,10 @@ impl<'a, C: Commitment> VerificationBuilder<'a, C> { subpolynomial_multipliers, inner_product_multipliers, sumcheck_evaluation: C::Scalar::zero(), - pre_result_commitments: Vec::with_capacity(inner_product_multipliers.len()), - folded_pre_result_evaluation: C::Scalar::zero(), + pcs_proof_commitments: Vec::with_capacity(inner_product_multipliers.len()), + folded_pcs_proof_evaluation: C::Scalar::zero(), consumed_result_mles: 0, - consumed_pre_result_mles: 0, + consumed_pcs_proof_mles: 0, consumed_intermediate_mles: 0, produced_subpolynomials: 0, post_result_challenges, @@ -71,12 +71,12 @@ impl<'a, C: Commitment> VerificationBuilder<'a, C> { /// /// An anchored MLE is an MLE where the verifier has access to the commitment pub fn consume_anchored_mle(&mut self, commitment: C) -> C::Scalar { - let index = self.consumed_pre_result_mles; + let index = self.consumed_pcs_proof_mles; let multiplier = self.inner_product_multipliers[index]; - self.pre_result_commitments.push(commitment); - self.consumed_pre_result_mles += 1; - let res = self.mle_evaluations.pre_result_evaluations[index]; - self.folded_pre_result_evaluation += multiplier * res; + self.pcs_proof_commitments.push(commitment); + self.consumed_pcs_proof_mles += 1; + let res = self.mle_evaluations.pcs_proof_evaluations[index]; + self.folded_pcs_proof_evaluation += multiplier * res; res } @@ -119,9 +119,9 @@ impl<'a, C: Commitment> VerificationBuilder<'a, C> { /// Get the commitments of pre-result MLE vectors used in a verifiable query's /// bulletproof - pub fn pre_result_commitments(&self) -> &[C] { + pub fn pcs_proof_commitments(&self) -> &[C] { assert!(self.completed()); - &self.pre_result_commitments + &self.pcs_proof_commitments } /// Get folding factors for the pre-result commitments pub fn inner_product_multipliers(&self) -> &[C::Scalar] { @@ -131,9 +131,9 @@ impl<'a, C: Commitment> VerificationBuilder<'a, C> { /// Get the evaluation of the folded pre-result MLE vectors used in a verifiable query's /// bulletproof - pub fn folded_pre_result_evaluation(&self) -> C::Scalar { + pub fn folded_pcs_proof_evaluation(&self) -> C::Scalar { assert!(self.completed()); - self.folded_pre_result_evaluation + self.folded_pcs_proof_evaluation } /// Check that the verification builder is completely built up @@ -141,7 +141,7 @@ impl<'a, C: Commitment> VerificationBuilder<'a, C> { self.bit_distributions.is_empty() && self.produced_subpolynomials == self.subpolynomial_multipliers.len() && self.consumed_intermediate_mles == self.intermediate_commitments.len() - && self.consumed_pre_result_mles == self.mle_evaluations.pre_result_evaluations.len() + && self.consumed_pcs_proof_mles == self.mle_evaluations.pcs_proof_evaluations.len() && self.consumed_result_mles == self.mle_evaluations.result_evaluations.len() && self.post_result_challenges.is_empty() } diff --git a/crates/proof-of-sql/src/sql/proof/verification_builder_test.rs b/crates/proof-of-sql/src/sql/proof/verification_builder_test.rs index a2ff7d19c..5c69c76c0 100644 --- a/crates/proof-of-sql/src/sql/proof/verification_builder_test.rs +++ b/crates/proof-of-sql/src/sql/proof/verification_builder_test.rs @@ -21,7 +21,7 @@ fn an_empty_sumcheck_polynomial_evaluates_to_zero() { Vec::new(), ); assert_eq!(builder.sumcheck_evaluation(), Curve25519Scalar::zero()); - assert_eq!(builder.pre_result_commitments(), &[]); + assert_eq!(builder.pcs_proof_commitments(), &[]); assert_eq!(builder.inner_product_multipliers(), &[]); } @@ -53,15 +53,15 @@ fn we_build_up_a_sumcheck_polynomial_evaluation_from_subpolynomial_evaluations() } #[test] -fn we_build_up_the_folded_pre_result_commitment() { - let pre_result_evaluations = [ +fn we_build_up_the_folded_pcs_proof_commitment() { + let pcs_proof_evaluations = [ Curve25519Scalar::from(123u64), Curve25519Scalar::from(456u64), ]; let mle_evaluations = SumcheckMleEvaluations { table_length: 1, num_sumcheck_variables: 1, - pre_result_evaluations: &pre_result_evaluations, + pcs_proof_evaluations: &pcs_proof_evaluations, ..Default::default() }; let mut rng = OsRng; @@ -85,17 +85,17 @@ fn we_build_up_the_folded_pre_result_commitment() { assert_eq!(eval, Curve25519Scalar::from(123u64)); let eval = builder.consume_intermediate_mle(); assert_eq!(eval, Curve25519Scalar::from(456u64)); - assert_eq!(builder.pre_result_commitments(), &[commit1, commit2]); + assert_eq!(builder.pcs_proof_commitments(), &[commit1, commit2]); assert_eq!( builder.inner_product_multipliers(), &[inner_product_multipliers[0], inner_product_multipliers[1]] ); - let expected_folded_pre_result_eval = inner_product_multipliers[0] + let expected_folded_pcs_proof_evaluation = inner_product_multipliers[0] * Curve25519Scalar::from(123u64) + inner_product_multipliers[1] * Curve25519Scalar::from(456u64); assert_eq!( - builder.folded_pre_result_evaluation(), - expected_folded_pre_result_eval + builder.folded_pcs_proof_evaluation(), + expected_folded_pcs_proof_evaluation ); }