Skip to content

Commit

Permalink
ProverCommitmentScheme::commit_on_evals()
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Jul 14, 2024
1 parent 3f50cef commit 7112eba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
20 changes: 18 additions & 2 deletions crates/prover/src/core/pcs/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,27 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentSchemeProver<B> {
channel: &mut ProofChannel,
twiddles: &TwiddleTree<B>,
) {
let _span = span!(Level::INFO, "Commitment").entered();
let tree =
CommitmentTreeProver::new(polynomials, self.log_blowup_factor, channel, twiddles);
self.trees.push(tree);
}

pub fn commit_on_evals(
&mut self,
evals: ColumnVec<CircleEvaluation<B, BaseField, BitReversedOrder>>,
channel: &mut ProofChannel,
twiddles: &TwiddleTree<B>,
) {
let span = span!(Level::INFO, "Interpolation for commitment").entered();
let polys = evals
.into_iter()
.map(|eval| eval.interpolate_with_twiddles(twiddles))
.collect();
span.exit();
self.commit(polys, channel, twiddles);
}

pub fn roots(&self) -> TreeVec<Blake2sHash> {
self.trees.as_ref().map(|tree| tree.commitment.root())
}
Expand Down Expand Up @@ -157,7 +173,7 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentTreeProver<B> {
channel: &mut ProofChannel,
twiddles: &TwiddleTree<B>,
) -> Self {
let span = span!(Level::INFO, "Commitment evaluation").entered();
let span = span!(Level::INFO, "Extension").entered();
let evaluations = polynomials
.iter()
.map(|poly| {
Expand All @@ -170,7 +186,7 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentTreeProver<B> {

span.exit();

let _span = span!(Level::INFO, "Commitment merkle").entered();
let _span = span!(Level::INFO, "Merkle").entered();
let tree = MerkleProver::commit(evaluations.iter().map(|eval| &eval.values).collect());
channel.mix_digest(tree.root());

Expand Down
30 changes: 9 additions & 21 deletions crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,19 @@ pub fn evaluate_and_commit_on_trace<B: Backend + MerkleOps<MerkleHasher>>(
twiddles: &TwiddleTree<B>,
trace: ColumnVec<CircleEvaluation<B, BaseField, BitReversedOrder>>,
) -> Result<(CommitmentSchemeProver<B>, InteractionElements), ProvingError> {
let span = span!(Level::INFO, "Trace interpolation").entered();
// TODO(AlonH): Clone only the columns needed for interaction.
let trace_polys = trace
.clone()
.into_iter()
.map(|eval| eval.interpolate_with_twiddles(twiddles))
.collect();
span.exit();

let mut commitment_scheme = CommitmentSchemeProver::new(LOG_BLOWUP_FACTOR);
let span = span!(Level::INFO, "Trace commitment").entered();
commitment_scheme.commit(trace_polys, channel, twiddles);
// TODO(spapini): Remove clone.
let span = span!(Level::INFO, "Trace").entered();
commitment_scheme.commit_on_evals(trace.clone(), channel, twiddles);
span.exit();

let interaction_elements = air.interaction_elements(channel);
let interaction_trace = air.interact(&trace, &interaction_elements);
// TODO(spapini): Make this symmetric with verify, once the TraceGenerator traits support
// retrieveing the column log sizes.
if !interaction_trace.is_empty() {
let span = span!(Level::INFO, "Interaction trace interpolation").entered();
let interaction_trace_polys = interaction_trace
.into_iter()
.map(|eval| eval.interpolate_with_twiddles(twiddles))
.collect();
span.exit();
commitment_scheme.commit(interaction_trace_polys, channel, twiddles);
let _span = span!(Level::INFO, "Interaction").entered();
commitment_scheme.commit_on_evals(interaction_trace, channel, twiddles);
}

Ok((commitment_scheme, interaction_elements))
Expand All @@ -103,16 +90,17 @@ pub fn prove<B: Backend + MerkleOps<MerkleHasher>>(

// Evaluate and commit on composition polynomial.
let random_coeff = channel.draw_felt();
let span = span!(Level::INFO, "Composition generation").entered();

let span = span!(Level::INFO, "Composition").entered();
let span1 = span!(Level::INFO, "Generation").entered();
let composition_polynomial_poly = air.compute_composition_polynomial(
random_coeff,
&component_traces,
interaction_elements,
&lookup_values,
);
span.exit();
span1.exit();

let span = span!(Level::INFO, "Composition commitment").entered();
commitment_scheme.commit(composition_polynomial_poly.to_vec(), channel, twiddles);
span.exit();

Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl ComponentProver<SimdBackend> for PoseidonComponent {
let eval_domain = CanonicCoset::new(self.log_column_size() + LOG_EXPAND).circle_domain();

// Create a new evaluation.
let span = span!(Level::INFO, "Deg8 eval").entered();
let span = span!(Level::INFO, "Deg4 eval").entered();
let twiddles = SimdBackend::precompute_twiddles(
CanonicCoset::new(self.max_constraint_log_degree_bound())
.circle_domain()
Expand Down

0 comments on commit 7112eba

Please sign in to comment.