Skip to content

Commit

Permalink
refactor: rename pre_result to pcs_proof (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayWhite2357 authored Aug 12, 2024
1 parent dbb5ef5 commit 316bad4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 68 deletions.
22 changes: 11 additions & 11 deletions crates/proof-of-sql/src/sql/proof/proof_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ProofBuilder<'a, S: Scalar> {
num_sumcheck_variables: usize,
bit_distributions: Vec<BitDistribution>,
commitment_descriptor: Vec<CommittableColumn<'a>>,
pre_result_mles: Vec<Box<dyn MultilinearExtension<S> + 'a>>,
pcs_proof_mles: Vec<Box<dyn MultilinearExtension<S> + 'a>>,
sumcheck_subpolynomials: Vec<SumcheckSubpolynomial<'a, S>>,
/// The challenges used in creation of the constraints in the proof.
/// Specifically, these are the challenges that the verifier sends to
Expand All @@ -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,
}
Expand Down Expand Up @@ -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<S> + '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.
Expand Down Expand Up @@ -139,25 +139,25 @@ 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<S> {
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<S> {
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
}

/// 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<S> {
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<S> {
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
Expand Down
8 changes: 4 additions & 4 deletions crates/proof-of-sql/src/sql/proof/proof_builder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
32 changes: 14 additions & 18 deletions crates/proof-of-sql/src/sql/proof/query_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct QueryProof<CP: CommitmentEvaluationProof> {
/// Sumcheck Proof
pub sumcheck_proof: SumcheckProof<CP::Scalar>,
/// MLEs used in sumcheck except for the result columns
pub pre_result_mle_evaluations: Vec<CP::Scalar>,
pub pcs_proof_evaluations: Vec<CP::Scalar>,
/// Inner product proof of the MLEs' evaluations
pub evaluation_proof: CP,
}
Expand Down Expand Up @@ -103,22 +103,20 @@ impl<CP: CommitmentEvaluationProof> QueryProof<CP> {
// 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(
Expand All @@ -133,7 +131,7 @@ impl<CP: CommitmentEvaluationProof> QueryProof<CP> {
bit_distributions: builder.bit_distributions().to_vec(),
commitments,
sumcheck_proof,
pre_result_mle_evaluations,
pcs_proof_evaluations,
evaluation_proof,
};
(proof, provable_result)
Expand Down Expand Up @@ -212,13 +210,12 @@ impl<CP: CommitmentEvaluationProof> QueryProof<CP> {
// 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,
Expand All @@ -238,7 +235,7 @@ impl<CP: CommitmentEvaluationProof> QueryProof<CP> {
table_length,
&subclaim.evaluation_point,
&sumcheck_random_scalars,
&self.pre_result_mle_evaluations,
&self.pcs_proof_evaluations,
&result_evaluations,
result.indexes(),
);
Expand All @@ -262,11 +259,11 @@ impl<CP: CommitmentEvaluationProof> QueryProof<CP> {
}

// 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,
Expand All @@ -292,8 +289,7 @@ impl<CP: CommitmentEvaluationProof> QueryProof<CP> {
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
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/proof-of-sql/src/sql/proof/sumcheck_mle_evaluations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
Expand All @@ -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<S>,
pre_result_evaluations: &'a [S],
pcs_proof_evaluations: &'a [S],
result_evaluations: &'a [S],
result_indexes: &Indexes,
) -> Self {
Expand All @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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![]),
);
Expand Down Expand Up @@ -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),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
34 changes: 17 additions & 17 deletions crates/proof-of-sql/src/sql/proof/verification_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C>,
folded_pre_result_evaluation: C::Scalar,
pcs_proof_commitments: Vec<C>,
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.
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
}

Expand Down Expand Up @@ -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] {
Expand All @@ -131,17 +131,17 @@ 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
fn completed(&self) -> bool {
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()
}
Expand Down
Loading

0 comments on commit 316bad4

Please sign in to comment.